-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.js
More file actions
88 lines (80 loc) · 2.64 KB
/
Copy pathinit.js
File metadata and controls
88 lines (80 loc) · 2.64 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
'use strict';
var newLevel = null;
var isGameStarted = false;
function reset () {
isGameStarted = false;
newLevel.clearIntervals();
newLevel.backSound.pause();
if(newLevel.victorySound !== null){
newLevel.victorySound.pause();
}
init();
}
function drawLandingPage() {
document.body.innerHTML =
`<div class='wrapper-landing'>
<header>
<h1 class='title'>TREASURE HUNTER</h1>
</header>
<main class='central-container'>
<div class='img-container'>
<img class='img-splash' id='img-diver' src='images/owd-diver-min.png' alt='scuba-diver'>
</div>
<div class='img-container'>
<img class='img-splash' src='images/great-white-shark-min.png' alt='shark'>
</div>
</main>
<footer class='splash-footer'>
<button class='btn btn-play'>
<i class='fa fa-caret-square-o-right' aria-hidden='true'></i> Play
</button>
</footer>
</div>`;
}
function mute(){
var muteBtn = document.getElementById("btn-mute");
if(newLevel.isBackSound){
newLevel.backSound.pause();
newLevel.isBackSound = false;
muteBtn.innerHTML = "Unmute";
}
else{
newLevel.backSound.play();
newLevel.isBackSound = true;
muteBtn.innerHTML = "Mute";
}
}
function drawGamingPage() {
if(isGameStarted === false){
isGameStarted = true;
setTimeout(function () {
document.body.innerHTML =
`<div class="wrapper-game">
<header class="stats-btns">
<div class="stats-btns">
<button id="btn-mute">Mute</button>
Lives:
<div id="lives">3</div>
<div><button id="btn-reset">Main Screen</button></div>
</div>
</header>
<main id="game">
<img id='win-game-over' alt='shark'>
</main>
</div>`;
var grid = document.getElementById("game");
newLevel = new Level(grid);
newLevel.startGame();
var resetBtn = document.getElementById("btn-reset");
var muteBtn = document.getElementById("btn-mute");
resetBtn.addEventListener("click", reset);
muteBtn.addEventListener("click", mute);
}, 1000);
}
}
function init() {
drawLandingPage();
var button = document.getElementsByClassName("btn-play");
button[0].addEventListener("click", drawGamingPage);
}
document.addEventListener("DOMContentLoaded", init);