Hi,
I’m currently in the early stage of making a small game of the type “if you align 3 identical beads vertically or horizontally they disapear and get replaced by new ones”.
I’m at the pont of filling my 2D Array, to me, my code makes sense and should work, but for some reason the output is really odd.
The main porblem is that my in my 2D array gameBoard*[j] for some reason the adresses past 1 in the i column do not get defined even tho I’m pretty sure I’m defining them correctly.
If you’re wondering about the ifs and the continues, when I fill my board, I dont want any identical pieces 3 times in a row so a valid combination is not already on the board when the user first starts the game.
Anyways look at the trace of this code, its really odd.
var boardSize:Number = 8;
var gameBoard:Array = new Array(new Array(boardSize), new Array(boardSize));
//
//
//Fills the board using the number of different types of beads
fillBoard = function (types:Number) {
for (var i = 0; i<boardSize; i++) {
for (var j = 0; j<boardSize; j++) {
//Make sure the initial filling wont put combinations on the initial layout
while (true) {
var randomType = Math.floor(Math.random()*types)+1;
if (i>=2 && (gameBoard[i-2][j] == gameBoard[i-1][j] == randomType)) {
continue;
}
if (i>=1 && i<=(boardSize-2) && (gameBoard[i-1][j] == randomType == gameBoard[i+1][j])) {
continue;
}
if (i<=boardSize-3 && (randomType == gameBoard[i+1][j] == gameBoard[i+2][j])) {
continue;
}
if (j>=2 && (gameBoard*[j-2] == gameBoard*[j-1] == randomType)) {
continue;
}
if (j>=1 && j<=(boardSize-2) && (gameBoard*[j-1] == randomType == gameBoard*[j+1])) {
continue;
}
if (j<=boardSize-3 && (randomType == gameBoard*[j+1] == gameBoard*[j+2])) {
continue;
} else {
gameBoard*[j] = randomType;
trace("i-> "+i+" , j-> "+j+" ==== "+gameBoard*[j]+" and the random number that was assigned is: "+randomType);
break;
}
}
//End of while
}
}
trace(gameBoard[0][0]+" "+gameBoard[0][1]+" "+gameBoard[0][2]+" "+gameBoard[0][3]+" "+gameBoard[0][4]+" "+gameBoard[0][5]+" "+gameBoard[0][6]+" "+gameBoard[0][7]);
trace(gameBoard[1][0]+" "+gameBoard[1][1]+" "+gameBoard[1][2]+" "+gameBoard[1][3]+" "+gameBoard[1][4]+" "+gameBoard[1][5]+" "+gameBoard[1][6]+" "+gameBoard[1][7]);
trace(gameBoard[2][0]+" "+gameBoard[2][1]+" "+gameBoard[2][2]+" "+gameBoard[2][3]+" "+gameBoard[2][4]+" "+gameBoard[2][5]+" "+gameBoard[2][6]+" "+gameBoard[2][7]);
trace(gameBoard[3][0]+" "+gameBoard[3][1]+" "+gameBoard[3][2]+" "+gameBoard[3][3]+" "+gameBoard[3][4]+" "+gameBoard[3][5]+" "+gameBoard[3][6]+" "+gameBoard[3][7]);
trace(gameBoard[4][0]+" "+gameBoard[4][1]+" "+gameBoard[4][2]+" "+gameBoard[4][3]+" "+gameBoard[4][4]+" "+gameBoard[4][5]+" "+gameBoard[4][6]+" "+gameBoard[4][7]);
trace(gameBoard[5][0]+" "+gameBoard[5][1]+" "+gameBoard[5][2]+" "+gameBoard[5][3]+" "+gameBoard[5][4]+" "+gameBoard[5][5]+" "+gameBoard[5][6]+" "+gameBoard[5][7]);
trace(gameBoard[6][0]+" "+gameBoard[6][1]+" "+gameBoard[6][2]+" "+gameBoard[6][3]+" "+gameBoard[6][4]+" "+gameBoard[6][5]+" "+gameBoard[6][6]+" "+gameBoard[6][7]);
trace(gameBoard[7][0]+" "+gameBoard[7][1]+" "+gameBoard[7][2]+" "+gameBoard[7][3]+" "+gameBoard[7][4]+" "+gameBoard[7][5]+" "+gameBoard[7][6]+" "+gameBoard[7][7]);
};
//executes the board filling
fillBoard(6);
the big trace at the end is onl so I can have a clear representation of the board in my output to verify if my code is working properly Ie :
2 3 4 6 3 6
1 2 1 5 5 4
4 4 3 2 1 3
1 2 1 2 5 4
5 4 3 5 1 3
(just thought I could do this huge trace with a forloop, but I dont feel like rewrting it right now)
If you see anything please share some advice
Thanks !