Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Token Animation Jumping grids on a board game

Status
Not open for further replies.

matthewking

Programmer
Jul 15, 2002
75
ES
Hi,

I've written this for a simple board game applet, its supposed to role the dice, which it does correctly, then move the players token along each grid piece, one at a time until it reaches its destination, its usually fine the first time around the board, then it irregularly jumps, for example grid 3 to 5, missing 4 etc. Any ideas?

public void run()
{
while (true)
{
/**
* Handles Animating the dice
*/
if (rolling)
{
int i = 0;

// animates dices moving
while (i < 20)
{
i++;

Dice1 =(int) (Math.random()*5)+1;
Dice2 =(int) (Math.random()*5)+1;

try { task.sleep(100); }
catch (Exception e) { }

repaint();
}

rolling = false;

/**
* Procedure for Moving players Token
* This is the problem part.
*/

// set curPos to the players current grid ref
int curPos = player[1].getPlayerPosition();

// total grid refs to move
int Move = Dice1 + Dice2 + 1;

while (Move != 0)
{
// correct game position if going off board
if (curPos == 40) { curPos = 0; }

// set new position
player[1].setPlayerPosition(curPos);
curPos++;

// when the moves run out, we stop.
Move--;

// pause thread try { task.sleep(250); }
catch (Exception e) { }

repaint();
}
} // roll dice
}
} // run


Anyone have any ideas?

Thanks in advance,

Matt.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top