As usual, the first thing we have to do is defining and setting up the game field.
The idea: Just like Minesweeper game, the best solution is a two-dimensional array representing the six rows and seven columns. The first index determines the row, and the second index determines the column.
Then, any element can have these values:
0: an empty cell.
1: a cell occupied by player one.
2: a cell occupied by player two.
Look at this picture with a typical Connect Four situation:
On the left, array indexes for each cell. On the right, array values to represent board's situation.
When the game starts, all cells are empty, so the entire array must be filled with zeros.
The development: Create a new file (File | New) then from New Document window select Actionscript 3.0. Set its properties as width to 640
px, height to 480
px, background color to #FFFFFF
(white), and frame rate to 30
. Also define the Document Class as Main
and save the file as connect4.fla
.