-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (60 loc) · 1.95 KB
/
index.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
// initilizing the values
// score of player 1
// let player1Score = parseInt(
// document.getElementById("player1Score").innerText
// );
// score of player 2
// let player2Score = parseInt(
// document.getElementById("player2Score").innerText
// );
// inilitazing the value to make fire power between 0 - 5;
let firePower = 0;
// getting the fire buttons
let fire1 = document.getElementById("fire1");
let fire2 = document.getElementById("fire2");
// adding eventlistenr on fire 1
fire1.addEventListener("click", function () {
if (
parseInt(document.getElementById("player1TournamentScore").innerText) >= 2
) {
alert("PLAYER 1 WON THE TOURNAMENT !");
newTournament();
}
if (player2Score.innerText <= 0) {
alert("Player 1 won the match");
document.getElementById("player1TournamentScore").innerText =
parseInt(document.getElementById("player1TournamentScore").innerText) + 1;
newGame();
} else {
firePower = Math.floor(Math.random() * 5) + 1;
player2Score.innerText = parseInt(player2Score.innerText - firePower);
}
});
// adding eventlistener on fire 2
fire2.addEventListener("click", function () {
if (
parseInt(document.getElementById("player2TournamentScore").innerText) >= 2
) {
alert("PLAYER 2 WON THE TOURNAMENT !");
newTournament();
}
if (player1Score.innerText <= 0) {
alert("Player 2 won the match");
document.getElementById("player2TournamentScore").innerText =
parseInt(document.getElementById("player2TournamentScore").innerText) + 1;
newGame();
} else {
firePower = Math.floor(Math.random() * 5) + 1;
player1Score.innerText = parseInt(player1Score.innerText - firePower);
}
});
// new game function
function newGame() {
player2Score.innerText = 100;
player1Score.innerText = 100;
}
function newTournament() {
document.getElementById("player1TournamentScore").innerText = 0;
document.getElementById("player2TournamentScore").innerText = 0;
newGame();
}