Coding Problem [F8]

• Born
• Posts: 2

3+ Months Ago

Hi,

I have a porblem with my code, I am creating a snakes and ladders game, I have so far created the board, using a for statement, which looks like this;

Code: [ Select ]
var sqX:Number = 100;
var sqY:Number = 600;
var sqNum:Number = 1;
for (j=1; j<=10; j++) {
for (i=1; i<=10; i++) {
duplicateMovieClip("square", "square"+j+i, 100+sqNum);
_root["square"+j+i].gotoAndStop(boardArray[sqNum-1]);
_root["square"+j+i].sqNum.text = sqNum;
_root["square"+j+i]._x = sqX;
_root["square"+j+i]._y = sqY;
if ((int(j/2)*2) == j) {
if (i != 10) {
sqX -= 60;
}
} else {
if (i != 10) {
sqX += 60;
}
}
sqNum++;
}
sqY -= 60;
}
1. var sqX:Number = 100;
2. var sqY:Number = 600;
3. var sqNum:Number = 1;
4. for (j=1; j<=10; j++) {
5.     for (i=1; i<=10; i++) {
6.         duplicateMovieClip("square", "square"+j+i, 100+sqNum);
7.         _root["square"+j+i].gotoAndStop(boardArray[sqNum-1]);
8.         _root["square"+j+i].sqNum.text = sqNum;
9.         _root["square"+j+i]._x = sqX;
10.         _root["square"+j+i]._y = sqY;
11.         if ((int(j/2)*2) == j) {
12.             if (i != 10) {
13.                 sqX -= 60;
14.             }
15.         } else {
16.             if (i != 10) {
17.                 sqX += 60;
18.             }
19.         }
20.         sqNum++;
21.     }
22.     sqY -= 60;
23. }

Now the porblem that I am having is that I cannot think how to make it so that, when I roll a dice it will move the player along the board the number that was generated from the dice. I have created a dice function that generates a random number, but as I said I cannot think how to make it move a character piece that many squares along the board. Any help would be much appreciated.

oh and here is the code for my dice funciton;
Code: [ Select ]
function randomNum() {
diceNum = Math.round(Math.random()*5)+1;
_root.dice.gotoAndStop(diceNum);
}
rollBtn.onRelease = randomNum;
1. function randomNum() {
2.     diceNum = Math.round(Math.random()*5)+1;
3.     _root.dice.gotoAndStop(diceNum);
4. }
5. rollBtn.onRelease = randomNum;

I can put up the fla if needed.

thanks
• Posts: 122
• Loc: St. Louis MO. USA

3+ Months Ago

Here is a shot in the dark. What about taking the results of the dice roll and call a function sending that variable to the function that makes the object move across the board using the x,y corridants.

Post Information

• Total Posts in this topic: 2 posts
• Users browsing this forum: No registered users and 6 guests
• You cannot post new topics in this forum
• You cannot reply to topics in this forum
• You cannot edit your posts in this forum
• You cannot delete your posts in this forum
• You cannot post attachments in this forum