-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
200 lines (170 loc) · 4.72 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>jQuery Minesweeper</title>
<script src="jquery.js" type="text/javascript" charset="utf-8"></script>
<script src="minesweeper.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function () {
var ms, MAX_DIMENSIONS = 30, DEFAULT_DIMENSION = 10, BOMB_INC = 5;
$('#rows,#cols')
.each(function () {
var option;
for (var i = 1; i <= 30; i++) {
option = $('<option>' + i + '</option>');
if (i == DEFAULT_DIMENSION) {
option.attr('selected', true);
}
$(this).append(option);
}
})
.change(function () {
$('#bombs').empty();
var max = parseInt($('#rows').val()) * parseInt($('#cols').val());
for (var i = BOMB_INC; i <= max; i += BOMB_INC) {
$('#bombs').append('<option>' + i + '</option>');
}
})
.change();
$('#minesweeper_form')
.bind('submit', function (e) { e.preventDefault (); })
.bind('click', function (e) {
e.preventDefault();
var target = $(e.target);
if (target.is('#generate')) {
if (ms) { $('#minesweeper_board').empty(); delete ms }
var o = {
rows: parseInt($('#rows').val()),
cols: parseInt($('#cols').val()),
bombs: parseInt($('#bombs').val())
};
ms = $('#minesweeper_board').minesweeper(o, true);
} else if (target.is('#reset')) {
ms.reset().play();
}
});
var updateStatus = function () {
if (ms.isPlaying ()) {
$('#status span').text(ms.bombsRemaining());
}
};
$('#minesweeper_board').bind('gameinput', updateStatus);
})
</script>
<style type="text/css" media="screen">
body {
font-family: 'Helvetica Neue';
color: #555;
}
body h1 {
font-weight: normal;
}
body h1 span {
color: #333;
}
body h1 span.version {
font-size: 0.6em;
color: #999;
}
#minesweeper_board {
float: left;
margin-left: 2em;
}
#minesweeper_board .board {
border: 1px solid #888;
overflow: auto;
}
#minesweeper_board div.cell {
width: 20px;
padding-top: 20px;
height: 0;
overflow: hidden;
background-color: #ddd;
border-left: 1px solid #fff;
border-top: 1px solid #fff;
border-right: 1px solid #bbb;
border-bottom: 1px solid #bbb;
text-align: center;
line-height: 20px;
font-size: 14px;
float: left;
}
#minesweeper_board div.cell.visible {
height: 20px;
padding-top: 0;
background-color: #eee;
border-left: 1px solid #eee;
border-top: 1px solid #eee;
border-right: 1px solid #ddd;
border-bottom: 1px solid #ddd;
}
#minesweeper_board .playing div.cell:hover {
cursor: pointer;
background-color: #eee;
}
#minesweeper_board .playing div.cell:active {
background-color: #ddd;
border-left: 1px solid #bbb;
border-top: 1px solid #bbb;
border-right: 1px solid #fff;
border-bottom: 1px solid #fff;
}
#minesweeper_board div.cell.visible.bomb {
background: url(bomb.png) no-repeat center #F66;
border: 1px solid #800000;
}
#minesweeper_board div.cell.flag {
background-image: url(flag.png);
background-repeat: no-repeat;
background-position: center;
}
#minesweeper_board div.cell.one { color: #00f; }
#minesweeper_board div.cell.two { color: #008000; }
#minesweeper_board div.cell.three { color: #f00; }
#minesweeper_board div.cell.four { color: #800040; }
#minesweeper_board div.cell.five { color: #FF8000; }
#minesweeper_board div.cell.six { color: #008080; }
#minesweeper_board div.cell.seven { color: #FF0080; }
#minesweeper_board div.cell.eight { color: #004080; }
select {
float: left;
width: 4em;
}
label {
float: left;
clear: left;
width: 5em;
margin-bottom: 1em;
line-height: 1.4em;
}
form {
float: left;
}
.buttons {
clear: left;
margin-bottom: 1em;
}
</style>
</head>
<body>
<h1>jQuery <span>Minesweeper</span> <span class="version">0.1</span></h1>
<div id="status">
Bombs Left: <span>-</span>
</div>
<form id="minesweeper_form" method="get" action="">
<label for="rows">Rows</label>
<select name="rows" id="rows"></select>
<label for="cols">Columns</label>
<select name="cols" id="cols"></select>
<label for="bombs">Bombs</label>
<select name="bombs" id="bombs"></select>
<div class="buttons">
<button id="generate">Generate</button>
<button id="reset">Reset</button>
</div>
</form>
<div id="minesweeper_board"></div>
</body>
</html>