Checking for possible columns

Before we can determine how long a disc will fall down a column, we have to know in which columns we can make a move.

In your Main.as file, add this function:

public function possibleColumns():Array {
var moves_array = new Array();
for (var i:uint=0; i<7; i++) {
if (gameField[0][i]==0) {
moves_array.push(i);
}
}
return moves_array;
}

possibleColumns returns an array with all the columns a player can place the disc in.

Also I want you to notice that this is the first function different to the one with the same name of the class that is declared as public. That's because the program will need to access this function from within disc_movieclip class.

var moves_array = new Array();

Constructing a new array called moves_array ...

Get Flash Game Development by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.