Hi all,
I have created a snakes and ladders board game which uses an array to produce the board (10x10) and to randomly assign ‘snakes’ and ‘ladders’. These details are numerical for example the trace for a typical game is as follows:
Square 34 goes to 25.
Square 61 goes to 59.
Square 62 goes to 68.
What I want to happen is to somehow show the snakes and ladders visually on the array grid. I’ve created the grid and that displays a 10x10 board with each square numbered. If the number is greater than the first then its a ladder if its less it’s a snake. I’m lost as to how to visually show the snakes and ladders on the board.
//Create the game board
for (t=0; t<100; t++) { //Create 100 tiles
if (random(100)<90) { //Generate number of special tiles
gameBoard.push(t);
} else {
gameBoard.push(Math.max((Math.min((t+random(25)-14), 99)), 0)); //Generate random lengths of snakes and ladders
}
}
var sqX:Number = 290; //Position of board
var sqY:Number = 320;
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(gameBoard[sqNum-1]);
_root["square"+j+i].sqNum.text = sqNum;
_root["square"+j+i]._x = sqX;
if ((int(j/2)*2) == j) {
if (i != 10) {
sqX -= 30;
}
} else {
if (i != 10) {
sqX += 30;
}
}
_root["square"+j+t]._y = sqY;
sqNum++;
}
sqY -= 30;
}
//Display random special tiles
for (t=0; t<gameBoard.length; t++) {
trace("Square "+(t+1)+" goes to "+(gameBoard[t]+1)+".");
if (gameBoard[t] != t) {
}
}
Any help would be great, thanks.