-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlightsout.html
More file actions
324 lines (280 loc) · 7.54 KB
/
lightsout.html
File metadata and controls
324 lines (280 loc) · 7.54 KB
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<!DOCTYPE html>
<!-- Game: lights OUT! Code written by Meghan Nelson. All cats reserved. October, 2013.
The formatted time function based on code from here: http://knowpapa.com/js-stopwatch/ -->
<html>
<head>
<link href='http://fonts.googleapis.com/css?family=Raleway' rel='stylesheet' type='text/css'>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
var runningstate = 1; // 1 means the timecounter is running 0 means counter stopped
var refresh = setInterval('increment()', 10);
var numofclicks = 0;
var lapcounter = 1;
var time = 0;
function start() {
refresh = setInterval('increment()', 10);
}
function stopTimer() {
clearInterval(refresh);
}
function startandstop() {
if(runningstate == 0){
runningstate = 1;
start();
}
if (runningstate == 1) {
runningstate = 0;
stopTimer(); //turns the timer off
}
}
function formattedtime(unformattedtime)
{
var decisec = Math.floor(unformattedtime/100) + '';
var second = Math.floor(unformattedtime/1000);
var minute = Math.floor(unformattedtime/60000);
decisec = decisec.charAt(decisec.length - 1);
second = second - 60 * minute + '';
return minute + ':' + second + ':' + decisec;
}
function increment() {
time+=10;
document.getElementById('stopwatch').value = formattedtime(time);
}
function newGame() {
$("table td").each(function() {
$(this).removeClass("on");
var randomNum = Math.round(Math.random());
if(randomNum == 1) {
$(this).addClass("on");
}
});
numofclicks=0;
$('#clicks').text('Clicks: ' + numofclicks);
time = 0;
}
function restartGame() {
document.getElementById('lapdetails').value += (lapcounter++) + '. '+ formattedtime(time) + ' Clicks: ' + numofclicks + '\n';
}
function checkGameEnding(){
var allOff = true; /* checks each one to see if it has the "on" class or not. Assumes all are off, since it's easier that way */
$("table td").each(function() {
if( $(this).hasClass("on")){
allOff = false;
}
});
if(allOff) {
alert('Lights are OUT!!!');
restartGame();
newGame();
}
}
function checkClicks(){
numofclicks = numofclicks+1;
$('#clicks').text('Clicks: ' + numofclicks);
}
$(document).ready(function() {
$("#instruction_set").hide();
$('#clicks').text('Clicks: ' + numofclicks);
newGame();
$("#instructions").click(function() {
$("#instruction_set").slideToggle("slow");
});
$("td#1").click(function() { /*Corner buttons */
$("td#1").toggleClass("on");
$("td#2").toggleClass("on");
$("td#4").toggleClass("on");
$("td#5").toggleClass("on");
checkClicks();
checkGameEnding();
});
$( "td#3").click(function() { /*Corner buttons */
$("td#3").toggleClass("on");
$("td#2").toggleClass("on");
$("td#5").toggleClass("on");
$("td#6").toggleClass("on");
checkClicks();
checkGameEnding();
});
$( "td#7").click(function() { /*Corner buttons */
$("td#4").toggleClass("on");
$("td#5").toggleClass("on");
$("td#7").toggleClass("on");
$("td#8").toggleClass("on");
checkClicks();
checkGameEnding();
});
$( "td#9").click(function() { /*Corner buttons */
$("td#9").toggleClass("on");
$("td#5").toggleClass("on");
$("td#6").toggleClass("on");
$("td#8").toggleClass("on");
checkClicks();
checkGameEnding();
});
$( "td#2" ).click(function() { /*Edge buttons */
$("td#1").toggleClass("on");
$("td#2").toggleClass("on");
$("td#3").toggleClass("on");
checkClicks();
checkGameEnding();
});
$( "td#6" ).click(function() { /*Edge buttons */
$("td#3").toggleClass("on");
$("td#6").toggleClass("on");
$("td#9").toggleClass("on");
checkClicks();
checkGameEnding();
});
$( "td#8" ).click(function() { /*Edge buttons */
$("td#7").toggleClass("on");
$("td#8").toggleClass("on");
$("td#9").toggleClass("on");
checkClicks();
checkGameEnding();
});
$( "td#4" ).click(function() { /*Edge buttons */
$("td#1").toggleClass("on");
$("td#4").toggleClass("on");
$("td#7").toggleClass("on");
checkClicks();
checkGameEnding();
});
$( "td#5" ).click(function() { /*Center buttons */
$("td#5").toggleClass("on");
$("td#2").toggleClass("on");
$("td#6").toggleClass("on");
$("td#8").toggleClass("on");
$("td#4").toggleClass("on");
checkClicks();
checkGameEnding();
});
});
</script>
<style type="text/css" media=screen>
h1 {
margin-left: 110px;
}
h6{margin-left: 140px; text-decoration: underline;}
.button, .button:visited {
margin: 30px 0 0 140px;
background: #222 url(overlay.png) repeat-x;
display: inline-block;
padding: 5px 10px 6px;
color: #fff;
text-decoration: none;
text-shadow: 0 -1px 1px rgba(0,0,0,0.25);
border-bottom: 1px solid rgba(0,0,0,0.25);
border-radius: 10px;
}
.blue.button, .blue.button:visited { background-color: #2981e4; }
.blue.button:hover { background-color: #2575cf; }
html {
margin-left: 30px;
padding-left:20px;
font-family: 'Raleway', serif;
}
table {
margin: 5px;
padding: 0px;
cursor: pointer;
position: relative;
float: left;
}
td{
border-radius: 5px;
box-shadow: 2px 4px 5px black;
background-color: #52524E;
color: #000;
}
td:hover {
background-color: #2B2B29;
}
td.on{
background-color: #F5F249;
color: #000;
}
td.on:hover{
background-color: #FFFEAD;
}
#stop {
position: relative;
display: inline-block;
margin-top: 40px;
margin-left: 30px;
border-style: dashed;
border-width: 2px;
border-radius: 30px;
}
#clicks{
position: relative;
display:inline-block;
width: 70px;
height: 20px;
border: black;
border-radius: 2px;
margin-left: 150px;
}
#instructions {
margin: 0 0 0 130px;
padding: 0px;
}
#instruction_set {
margin: 0px;
margin-left: 10px;
padding: 5px 0 10px 10px;
width: 350px;
font-size: 12px;
}
.stopwatch { padding: 5px; border:none; width: 160px; margin:15px 5px 5px 10px; border-radius: 2px; background-color: lightgrey;}
.lap { color: black; padding: 1px; border:black; height:75%; width: 175px; margin:15px 5px; border-radius: 2px; background-color: lightgrey;}
.button2 {margin-left: 20px; margin-top: 0px;}
.red.button2, .red.button2:visited { background-color: #FF8080; }
.red.button2:hover { background-color: #990000; }
#footer {
position: absolute;
bottom: 0px;
left: 10px;
font-size: 7px;
margin-left: 10px;
}
</style>
</head>
<body>
<h1> Lights Out!</h1>
<h6 id="instructions"> Gameplay instructions</h6>
<div id="instruction_set">
<p>The goal is to turn all the lights <em>OUT!</em></p>
<p>You can do so by pressing the buttons.</p>
<p>There are three types of buttons: corner, edge, and center</p>
<p>Corner buttons toggle the four lights in the corner on and off.
Edge buttons toggle the two neighboring lights on and off. The center button toggles itself and the four lights surrounding it on and off. Use these to turn the lights out!</p>
</p>
</div>
<input type="button" id="newgame" name="newgame" value="New Game" class="blue button" onclick="newGame();">
<div id="clicks"></div>
<p></p>
<table cellpadding="45%" cellspacing="20px" >
<tr>
<td id="1" class=""></td>
<td id="2" class=""></td>
<td id="3" class=""></td>
</tr>
<tr>
<td id="4" class=""></td>
<td id="5" class=""></td>
<td id="6" class=""></td>
</tr>
<tr>
<td id="7" class=""></td>
<td id="8" class=""></td>
<td id="9" class=""></td>
</tr>
</table>
<div id="stop">
<input class="stopwatch" id="stopwatch" value="0:0:0" type="text"><br>
<input class="button button2 red" id="startandstopbutton" value="Stop" onclick="startandstop();" type="button"><br>
<textarea class="lap" id="lapdetails" rows="6" cols="70"></textarea>
</div>
<p id="footer">Written by Meghan Nelson. Contact at meghan@meghan.net. All cats reserved</p>
</body>
</html>