-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
95 lines (78 loc) · 2.23 KB
/
Copy pathscript.js
File metadata and controls
95 lines (78 loc) · 2.23 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
/****************/
/* MODEL (data) */
/****************/
// Elementen
const healthBar = document.getElementById("healthProgress");
const healthSpan = document.getElementById("healthSpan");
const healthP = document.getElementById("healthP");
const healthImage = document.getElementById("healthImg");
const drumImage = document.getElementById("tama-drum");
const btnMetal = document.getElementById("play_metal");
const btnJazz = document.getElementById("play_jazz");
const btnClean = document.getElementById("clean_drum_kit");
const buttons = document.querySelectorAll("button");
const startKnop = document.getElementById("startKnop");
console.log("Dit zijn de buttons: ", buttons);
buttons.forEach((button) => {});
// Game data
let health = 10;
/********************/
/* CONTROL (logica) */
/********************/
// Laat health aflopen
function reduceHealth() {
health = health - 1;
}
function increaseHealth(amount) {
health = health + amount;
// ???
if (health > 100) {
health = 100;
}
}
// Interval die health automatisch laat aflopen
let decreaseHealthInterval = setInterval(reduceHealth, 1000);
// Interval die health updatet
let updateHealthBar = setInterval(() => {
updateHealth();
}, 1000);
// Interval die health check op game over
let checkHealthInterval = setInterval(() => {
if (!health) {
console.log("Game over");
clearInterval(decreaseHealthInterval);
clearInterval(checkHealthInterval);
healthP.textContent = "Game over! :(";
}
}, 1000);
// Event listeners
buttons.forEach((button) => {
button.addEventListener("click", handleAction);
});
// Event handlers (functies)
// PLAY METAL
function handleAction(event) {
console.log(event);
drumImage.src = "images/tama-" + event.target.dataset.action + ".png";
increaseHealth(event.target.dataset.reward);
drumImage.style.visibility = "visible";
}
/***************************/
/* naar VIEW (presentatie) */
/***************************/
// DOM UPDATE
function updateHealth() {
healthSpan.textContent = health;
healthBar.value = health;
}
// document.querySelector("playMetal");
// // while loop
// let tel = 10;
// while (tel > 0){
// console.log(tel)
// tel--
// }
// // for
// for (let teller = 10; teller > 0; teller--) {
// console.log(teller);
// }