Game Dev - Counters and Spreading Cards Evenly


I came up with a card game idea the other day on the train about countering and attacking (like sword fighting). It's a fixed deck of cards where players play cards to attack or counter. It's like rock-paper-scissors, but you don't lose until you choose to or have to pass.

The piece of code I was working at lunch was actually not game specific, but was a cosmetic issue figuring out an equation to run to spread cards out evenly when displaying a hand. If there are fewer cards than the "maximum display width", those offsets are a percentage of the width of the cards and things are spread out evenly. As the number of cards increases and when placed side-by-side would equal more than the "maximum display width", the offset has to be reset accordingly. From there you have to do a base offset to where the cards actually start to draw since the straight center of the display hand will have them populate from the center to the right, instead of the center to both sides evenly.

Here's the little piece of code:
		offsetX = Math.round(tempCard.width * offsetPercentage);
		if ( ((tempCard.width * player1Hand.length) + ((offsetX-tempCard.width) * (player1Hand.length-1))) < handWidth)
		{			
			baseX = (handWidth/2) - (( (tempCard.width * player1Hand.length)
									 + ((offsetX-tempCard.width) * (player1Hand.length - 1)) )/2);
		} else {
			offsetX = Math.round(handWidth / player1Hand.length);
			baseX = 0;
		}
		
		tempCard.x = baseX + (offsetX * i);

Now I just want them to tween to their right places.