-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sparring_Score.html
112 lines (105 loc) · 4.14 KB
/
Sparring_Score.html
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
<!DOCTYPE html>
<html>
<head>
<title> Score keeper </title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<meta name="viewport" content="width=device-width - 10%, initial-scale=1">
<style>
body {
background-color: silver;
}
h1 {
color: white;
text-align: center;
}
p {
font-family: verdana;
font-size: 20px;
}
</style>
</head>
<body>
<h1>
<center> Taekwon-Do score keeper </center>
</h1>
<center> <button id="counter" style="width:150px" class="btn btn-info" type="submit">1:00</button> </center>
<hr/>
<hr/> <br/> <br/>
<center>
<button style="width:30%" id="b1" class="btn btn-success" type="submit" height="100px"> +1 </button>
<button style="width:30%" id="b2" class="btn btn-success" type="submit" height="100px"> +1 </button> <br/> <br/> <br/>
<button style="width:30%" id="b3" class="btn btn-success" type="submit" height="100px"> +2 </button>
<button style="width:30%" id="b4" class="btn btn-success" type="submit" height="100px"> +2 </button> <br/> <br/> <br/>
<button style="width:30%" id="b5" class="btn btn-success" type="submit" height="100px"> +3 </button>
<button style="width:30%" id="b6" class="btn btn-success" type="submit" height="100px"> +3 </button> <br/> <br/>
<button id="b7" class="btn btn-warning" type="submit" style="width:30%" margin="15%"> Click to pause and see results </button>
<button id="reset" class="btn btn-danger" type="submit"> Allow resetting </button>
</center>
<script>
var score_player1 = 0,
score_player2 = 0;
var b1 = document.getElementById('b1');
var b2 = document.getElementById('b2');
var b3 = document.getElementById('b3');
var b4 = document.getElementById('b4');
var b5 = document.getElementById('b5');
var b6 = document.getElementById('b6');
var b7 = document.getElementById('b7');
var reset = document.getElementById('reset');
var counter = document.getElementById('counter');
var timer_state = 0; // if 1 -> it was clicked
b1.onclick = function() {
score_player1 += 1;
}
b2.onclick = function() {
score_player2 += 1;
}
b3.onclick = function() {
score_player1 += 2;
}
b4.onclick = function() {
score_player2 += 2;
}
b5.onclick = function() {
score_player1 += 3;
}
b6.onclick = function() {
score_player2 += 3;
}
b7.onclick = function() {
window.alert("Player 1: " + score_player1 + " vs Player2: " + score_player2);
}
reset.onclick = function() {
seconds = 60;
timer_state = 0;
reset.innerHTML = "You can reset now";
}
reset.innerHTML = "Allow Reseting";
counter.onclick = function countdown() {
var seconds = 60;
reset.innerHTML = "Allow Reseting";
if (timer_state == 0) {
function tick() {
var counter = document.getElementById("counter");
seconds--;
counter.innerHTML = "0:" + (seconds < 10 ? "0" : "") + String(seconds);
if (seconds > 0) {
setTimeout(tick, 1000);
}
}
tick();
if (score_player1 > score_player2) {
alert("The winner is Player 1! Click ok to restart the timer and start a new round.");
seconds = 60;
}
if (score_player2 > score_player1) {
alert("The winner is Player 2! Click ok to restart the timer and start a new round.");
seconds = 60;
}
timer_state = 1;
}
}
// countdown();
</script>
</body>
</html>