-
Notifications
You must be signed in to change notification settings - Fork 0
/
site.js
141 lines (118 loc) · 3.26 KB
/
site.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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
var myAudio = new Audio("alert.mp3");
//
//
//
function Timer(Element, Time, Name) {
var element = Element;
var time = Time;
var originalTime = Time;
var name = Name;
var interval = setInterval(timeCallBack, 1000);
var isPaused = false;
element.addEventListener("click", onClick);
setName(name);
timeCallBack();
onClick();
function getTimeElement() {
return element.getElementsByClassName("time")[0];
}
function getNameElement() {
return element.getElementsByClassName("name")[0];
}
function setName(name) {
getNameElement().textContent = name;
}
function timeCallBack() {
if (time <= 0) {
onEnd(getNameElement());
}
var minutes = Math.floor(time / 60);
var seconds = time % 60;
if (seconds < 10) {
seconds = "0" + seconds;
}
getTimeElement().textContent = minutes + ":" + seconds;
time -= 1;
}
function onClick(event) {
if (isPaused) {
interval = setInterval(timeCallBack, 1000);
} else {
clearInterval(interval);
}
isPaused = !isPaused;
}
//
//
//
function onEnd(name) {
myAudio.play();
//document.body.style.backgroundColor = "red";
clearInterval(interval);
isPaused = true;
time = 0; //originalTime;
let msgs = ["<h2>🤠 Almost Mate! Don't give up...</h2>", "<h2>😉 Get them next time!</h2>", "<h2>😎 It's all about having fun</h2>",
"<h2>😜 You will win on the next game!</h2>"];
let curMsg = msgs[Math.floor(Math.random() * msgs.length)];
$("#status").append(curMsg + "<h3>"+ name.innerText + " is out of the game!</h3>");
$("#status").show();
// setTimeout(function() {
// $("#status").hide();
// }, 3000)
}
}
//
//
//
function Timers(Element) {
var timers = [];
var element = Element;
this.addTimer = function () {
if (timers.length >= 4) {
return;
}
else if (timers.length == 3) {
$(".add-timer").hide();
}
var name = prompt("Player Name");
var time = prompt("The length of your timer in seconds (e.g. 15min * 60sec = 900)");
name = name || "Timer " + (timers.length + 1);
if (isNaN(parseFloat(time))) {
time = 10 * 60;
}
time = Math.floor(time) || 10 * 60;
var timerElement = document.createElement("div");
timerElement.classList.add("timer");
var nameElement = document.createElement("div");
nameElement.classList.add("name");
timerElement.appendChild(nameElement);
var timeElement = document.createElement("div");
timeElement.classList.add("time");
timerElement.appendChild(timeElement);
element.appendChild(timerElement);
timers.push(new Timer(timerElement, time, name));
}
element.getElementsByClassName("add-timer")[0].addEventListener("click", this.addTimer);
}
//
var timers = new Timers(document.getElementsByClassName("timer-container")[0]);
//
//
//
$(document).ready(function() {
console.log("-- starting the party --");
$("#status").hide();
$("#help-area").hide();
// Button to let users restart everything
$("#start-game-but").click(function() {
location.reload();
});
// The 'help' dialog
$(".help-icon").click(function () {
$("#help-area").show();
});
$(".close-but").click(function() {
$("#help-area").hide();
$("#status").hide();
});
});