-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
64 lines (57 loc) · 2.03 KB
/
index.html
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<html>
<head>
<script type="text/javascript" src="src/GameOfLife.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
var grid = [];
var timer =0;
for(row_counter=0;row_counter<50; row_counter++){
grid.push([]);
for(column_counter=0;column_counter<50; column_counter++){
grid[row_counter].push({"row":row_counter, "column": column_counter, "alive":false});
}
}
// create a glider
grid[2][1].alive = true;
grid[2][2].alive = true;
grid[2][3].alive = true;
grid[1][3].alive = true;
grid[0][2].alive = true;
$(document).ready(function() {
var width = 50;
for (var i = 0; i < width; i++) {
var tr = $("#game").append($("<tr />"));
for (var c = 0; c < width; c++) {
tr.children('tr:last').append($("<td class='cell dead' id='"+i+"-"+c+"'></td>"));
};
};
$("td").click(function() {
$(this).toggleClass("dead");
var id = $(this).attr("id");
id = id.split("-");
grid[id[0]][id[1]].alive = !grid[id[0]][id[1]].alive;
});
$("#go").click(function() {
if (timer == 0)
timer = setInterval(function(){grid = run(grid)},310);
});
$("#stop").click(function() {
clearInterval(timer);
timer = 0;
});
grid = run(grid);
});
</script>
<style type="text/css">
table {
border-spacing:1px;
}
.cell { width:10px; height:10px;}
.dead {background-color: gray}
</style>
</head>
<body>
<table colspacing="1" ><tbody id="game"></tbody></table>
<button id="go">Go</button> <button id="stop">Stop</button>
</body>
</html>