-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid-game.html
86 lines (56 loc) · 1.4 KB
/
grid-game.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
<style>
#board, .square {
margin: 0;
padding: 0;
}
#board {
width: 900px;
height:700px;
background-color: #cc1;
}
.square {
display: inline-block;
width: 50px;
height: 50px;
background-color: white;
margin: 1px;
}
.square.spike {
background-image: url("https://s3.amazonaws.com/uploads.hipchat.com/75912/859501/Pi06QdSLOm2Or0E/imgres-1.jpg");
}
.square.orange {
background-color: orange;
}
</style>
</head>
<body>
<div id="board">
</div>
<script>
var $board = $('#board');
for (var w = 0; w<150; w++) {
var num = Math.floor(Math.random() * 10) + 1
if(num == 9){
var sq = $('<div class="square spike"> </div>');
$board.append(sq);
}
else{
var sq = $('<div class="square"> </div>');
$board.append(sq);
}
}
$('div.square').on('click', function() {
if(!$(this ).hasClass( "square spike" )){
$("div.square").removeClass( "orange" );
$(this).addClass('orange');
}
});
</script>
</body>
</html>