-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
68 lines (60 loc) · 1.71 KB
/
app.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
const p1Display = document.querySelector('#p1-display');
const p2Display = document.querySelector('#p2-display');
const p1ButtonMin = document.querySelector('#p1-button-min');
const p2ButtonMin = document.querySelector('#p2-button-min');
const p1ButtonMax = document.querySelector('#p1-button-max');
const p2ButtonMax = document.querySelector('#p2-button-max');
const resetButoon = document.querySelector('#reset');
const selectWinPoint = document.querySelector('#winpoint');
let p1Score = 0;
let p2Score = 0;
let winPont = 21;
let isGameOver = false;
function reset() {
isGameOver = false;
p1Score = 0;
p2Score = 0;
p1Display.textContent = 0;
p2Display.textContent = 0;
}
p1ButtonMin.addEventListener('click', function () {
if (!isGameOver) {
p1Score -= 1;
if (p1Score === winPont) {
isGameOver = true;
}
p1Display.textContent = p1Score;
}
});
p2ButtonMin.addEventListener('click', function () {
if (!isGameOver) {
p2Score -= 1;
if (p2Score === winPont) {
isGameOver = true;
}
p2Display.textContent = p2Score;
}
});
p1ButtonMax.addEventListener('click', function () {
if (!isGameOver) {
p1Score += 1;
if (p1Score === winPont) {
isGameOver = true;
}
p1Display.textContent = p1Score;
}
});
p2ButtonMax.addEventListener('click', function () {
if (!isGameOver) {
p2Score += 1;
if (p2Score === winPont) {
isGameOver = true;
}
p2Display.textContent = p2Score;
}
});
resetButoon.addEventListener('click', reset);
selectWinPoint.addEventListener('change', function(){
winPont=parseInt(this.value);
reset();
});