-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
144 lines (122 loc) · 3.4 KB
/
main.js
File metadata and controls
144 lines (122 loc) · 3.4 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
var playing = false;
var currentCallback;
//windows
function replaceWindow(evt, param_div) {
if (evt != "game"){
pauseMusic();
}
stopInterval();
clearCellsValue();
clearWindow();
document.getElementById(param_div).style.display = "block";
evt.currentTarget.className += " active";
}
function clearWindow() {
element = document.getElementsByClassName("tab");
for (i = 0; i < element.length; i++) {
element[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
}
function clearCanvas() {
element = document.getElementById('canvas');
for (i = 0; i < element.length; i++) {
element[i].style.display = "none";
}
}
function showCanvas() {
document.getElementById("startgame").className.replace("active", "");
startGame();
document.getElementById('canvas').style.display = "block";
document.getElementById('reset').style.display = "block";
}
function reset() {
setSettings();
startGame();
playMusic();
}
function clearCellsValue() {
document.getElementById("lblScore").value = "";
document.getElementById("lblTime").value = "";
document.getElementById("lblLifes").value = "";
}
function resize_canvas() {
canvas = document.getElementById("canvas");
if (canvas.width < window.innerWidth) {
canvas.width = window.innerWidth;
}
if (canvas.height < window.innerHeight) {
canvas.height = window.innerHeight;
}
}
//music
function playPause() {
const song = document.getElementById("music");
if (playing) {
pauseMusic();
} else {
playMusic();
}
}
function pauseMusic(){
const song = document.getElementById("music");
song.pause();
playing = false;
}
function playMusic() {
const song = document.getElementById("music");
song.play(); //play the audio track
playing = true;
}
function playDieSound() {
document.getElementById("diemusic").play();
}
function playWinSound() {
document.getElementById("winmusic").play();
}
function playGhostSound() {
if (playing) {
document.getElementById("ghostmusic").play();
}
}
function pauseGame() {
const song = document.getElementById("music");
const pauseGame = document.getElementById("pause");
if(pause){
//var temp = tempTime - start_time;
//start_time = temp;
pause = false;
pauseGame.textContent = "Pause";
playMusic();
}
else{
//tempTime = new Date();
pauseGame.textContent = "Resume";
pause = true;
pauseMusic();
}
}
// override default browser alert
window.alert = function(msg, callback){
$('.message').text(msg);
// $('.customAlert').css('animation', 'fadeIn 0.3s linear');
$('.customAlert').css('display', 'inline');
setTimeout(function(){
$('.customAlert').css('animation', 'none');
}, 300);
currentCallback = callback;
}
$(function(){
// add listener for when our confirmation button is clicked
$('.confirmButton').click(function(){
$('.customAlert').css('animation', 'fadeOut 0.3s linear');
setTimeout(function(){
$('.customAlert').css('animation', 'none');
$('.customAlert').css('display', 'none');
}, 300);
currentCallback();
})
});