/
BackToTheFuture.html
136 lines (97 loc) · 3.13 KB
/
BackToTheFuture.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
<html>
<head>
<title>Back to the Future</title>
<link rel="stylesheet" href="whack.css">
<script src="jquery211.js"></script>
<link href="bootstrap.css" rel="stylesheet">
</head>
<body>
<div class="table">
<div class="row">
<div class="cell"><img id="cell1" src="img/bolt.gif"></div>
<div class="cell"><img id="cell2" src="img/bolt.gif"></div>
<div class="cell"><img id="cell3" src="img/bolt.gif"></div>
</div>
<div class="row">
<div class="cell"><img id="cell4" src="img/bolt.gif"></div>
<div class="cell"><img id="cell5" src="img/bolt.gif"></div>
<div class="cell"><img id="cell6" src="img/bolt.gif"></div>
</div>
<div class="row">
<div class="cell"><img id="cell7" src="img/bolt.gif"></div>
<div class="cell"><img id="cell8" src="img/bolt.gif"></div>
<div class="cell"><img id="cell9" src="img/bolt.gif"></div>
</div>
</div>
<div>
<div id='speed-box'>
<div id="speed">0</div>
<div id='speedText'>SPEED</div>
</div>
<div id='gw-box'>
<div id='gw'>1210000000</div>
<div id='gwText'>GigaWatts Needed</div>
</div>
<div class="progress progress-striped active">
<div id="progress" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 10%">
<span class="sr-only">45% Complete</span>
</div>
</div>
</div>
<div><button id='start'>Start game</button></div>
<script type="text/javascript">
//GAME STARTS HERE
//starts counter
var counter = 0;//set this to what ever you want the start # to be
var timer;
var intervalId;
var audio = new Audio('tesla.wav');
//button starts game
$('#start').click(function(){
countUP ();//call the function once
// LOOP STARTS HERE
intervalId = setInterval(function(){
var cellToshow = getRandomInt(1,9);
audio.play();
$("#cell" + cellToshow).fadeIn(200).delay( 500 ).fadeOut(200);
}, 2000);
});
// Returns a random integer between min and max
// Using Math.round() will give you a non-uniform distribution!
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function countUP () {
counter++;//increment the counter by 1
$('#speed').html(counter); //refresh indicator
if (counter < 88) {
timer = setTimeout ("countUP()", 350 ); //runs itsself
// ends game
if (score == 0) {
alert(" You Win !");
clearInterval(timer);
}
} else {
clearInterval(timer);
clearInterval(intervalId);
if (score > 0) {
alert("You failed");
};
}
}
//---------------------------
//adds score
var score = 1210000000;
percent = 0;
$('.cell>img').click(function() {
$(this).hide();
score = (score - 121000000);
percent += 10;
$('#gw').html(score);
var progress = $('#progress');
progress.css('width', percent + '%');
console.log(percent);
});
// console.log(progress);
</script>
</html>