-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameoflife.js
49 lines (38 loc) · 833 Bytes
/
gameoflife.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// gameoflife.js
//console game of life conway's simulator.
// how to build the grid... array of objects? 2d objects? example grid[5][7]...
let gridsize = 4;
let grid = [];
function randombool() {
if (Math.random() <= 0.5) {
return true
} else {
return false
}
};
let Cell = function(x, y) {
this.x = x;
this.y = y;
this.alive = true;
}
//generate grid
for (let i = 0; i < gridsize; i++) {
for (let j = 0; j < gridsize; j++) {
let cell = new Cell
cell.x = j;
cell.y = i;
cell.alive = randombool();
grid.push(cell);
}
}
function buildRow(col) {
let row = "";
for (let i = 0; i < gridsize; i++) {
// if (grid[i].x == )
}
}
console.log(grid)
let test = grid.find(function () {
return this.x ==
});
console.log(test)