-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.js
97 lines (80 loc) · 2.01 KB
/
main.js
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
// main JavaScript file
var GameOver = "False"
var loc = 300;
var miss = 5;
var hits = 0;
var score = 0;
var ss1 = document.getElementById('ss1');
var ss2 = document.getElementById('ss2');
var ss3 = document.getElementById('ss3');
var ss4 = document.getElementById('ss4');
var ss5 = document.getElementById('ss5');
var canon = document.getElementById('canon');
var missedQuestions = document.getElementById('missed');
var nofHits = document.getElementById('hits');
var leveltimer = document.getElementById('leveltimer');
var ss1y = 0;
var ss2y = 0;
var ss3y = 0;
var ss4y = 0;
var ss5y = 0;
var canx = 450;
var ss1sum;
var ss2sum;
var ss3sum;
var ss4sum;
var ss5sum;
var ss1content;
var ss2content;
var ss3content;
var ss4content;
var ss5content;
var canoncontent;
canon.style.left = canx + 'px';
function mainGameLoop() {
var id = setInterval(frame, GameSpeed);
var t = setInterval(timeUpdate, 1000);
function timeUpdate(){
if(GameOver == "False"){
leveltimer.innerHTML = "Time Left: " + TimeInSeconds--;
}
}
function frame() {
if(ss1y == loc || ss2y == loc || ss3y == loc || ss4y == loc || ss5y == loc || miss<1 ){
GameOver = "True";
clearInterval(id);
storeReportVar("Failed!");
newpage('report.html');
}
if (TimeInSeconds<1) {
clearInterval(id);
storeReportVar("Congrats!");
newpage("report.html");
}
else {
missedQuestions.innerHTML = "Miss: " + miss;
nofHits.innerHTML = "<p>HITS: " + hits + "</p><p>Score: " + hits*10 + "</p>";
ss1y++;
ss1.style.top = ss1y + 'px';
ss2y++;
ss2.style.top = ss2y + 'px';
ss3y++;
ss3.style.top = ss3y + 'px';
ss4y++;
ss4.style.top = ss4y + 'px';
ss5y++;
ss5.style.top = ss5y + 'px';
}
}
}
function newpage(pageurl) {
window.location.assign(pageurl);
}
//Start the game
setss1content();
setss2content();
setss3content();
setss4content();
setss5content();
setcanoncontent()
mainGameLoop();