previous

page 12

next
the glider

I'm sure that you tried the glider to make sure all is as it should be but wouldn't it be neat to have a button that draws the glider for the player?

To do this we'll need to specify the cells to be filled in like this perhaps:

var arr=[[1,2],[2,3],[3,1],[3,2],[3,3]];

Each pair specifies the row and column values of a cell that is "live".

Now we'll need a set(arr) function that does the work for us.

function set(arr) {
for (var i=0;i<arr.length;i++) {
var rc=arr[i];
var row=rc[0];
var col=rc[1];
var id=rc2id(row,col);
g_squares[id]=1;
var el=document.getElementById(id);
el.style.backgroundColor='red';
}
}
the glider function
function glider() {
var arr=[[1,2],[2,3],[3,1],[3,2],[3,3]];
set(arr);
}

So now you can add a glider button to your game.

previous
next