-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhost.html
252 lines (244 loc) · 10.2 KB
/
host.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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<!DOCTYPE HTML>
<html>
<head>
<title>Better Call the Exterminator!</title>
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src='https://exactalytics.pages.dev/import.js'></script>
<script>analyticsInit('Better Call The Exterminator','3moxYInXFN6fp')</script>
</head>
<body>
<div class="modal" id="popupBack"><div style="font-size: 50px;cursor:pointer;user-select:none;display:none" onclick="menu();setTimeout(function() {popout(`<div style='text-align:center'><div id='qr'></div><h1 style='font-size:70px' id='pin'>Loading PIN...</h1><div id='namesD'></div><p><button onclick='startG()' id='sbtn' style='display:none;margin:auto'>Start</button></p></div>`);setTimeout(createGame,400)},500)" id="close">×</div><div id="popup" style="width:2px;height:2px;"></div></div>
<div class="corkCont"><img src='assets/corkboard.png' height='100%'><div id="hostTime">3:00</div><div id="hostInfo"><h1>What we know</h1>Nothing yet</div></div>
</body>
<script src="script.js"></script>
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.10.0/firebase-app.js";
import { get, update, getDatabase, ref, child, set } from "https://www.gstatic.com/firebasejs/10.10.0/firebase-database.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyBWBFJ9yYYDXTgTQieDFfJ5O4uVJ2GMEos",
authDomain: "better-call-the-exterminator.firebaseapp.com",
projectId: "better-call-the-exterminator",
storageBucket: "better-call-the-exterminator.appspot.com",
messagingSenderId: "786054842141",
appId: "1:786054842141:web:eaafc978769f9e423b03f4"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const db = getDatabase();
var acint;
function createGame() {
window.newid = Math.ceil(Math.random() * (20000000 - 10000000) + 10000000)
get(child(ref(getDatabase()), "gameid/" + newid)).then((snapshot) => {
if (snapshot.exists()) {createGame()} else {
update(ref(getDatabase(), 'gameid/' + newid), {
"source": sourceR
});
get(child(ref(getDatabase()), "gameid/" + newid)).then((snapshot) => {
if (snapshot.exists()) {
pinShow()
nameint = setInterval(getNames,500)
}
})
}})
setInterval(getInfo,1000)
}
function actionCheck() {
get(child(ref(getDatabase()), "gameid/" + newid)).then((snapshot) => {
if (snapshot.exists()) {
var data = snapshot.val()
var act = data.action
if (act) {
popout(act)
clearInterval(acint)
acint = setInterval(removeACheck,500)
}
}
})
}
function removeACheck() {
get(child(ref(getDatabase()), "gameid/" + newid)).then((snapshot) => {
if (snapshot.exists()) {
var data = snapshot.val()
if (!data.action) {
popout()
clearInterval(acint)
acint = setInterval(actionCheck,500)
}
}})
}
function pinShow() {
pin.innerHTML = newid + "<br><span style='font-size:30px'>Scan or enter code at https://calltheexterminator.pages.dev/join</span>"
qr.innerHTML = "<img src='https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=https://calltheexterminator.pages.dev/join?id=" + newid + "'>"
namesD.innerHTML = "Waiting for players..."
}
var countint;
function startG() {
popout()
clearInterval(nameint)
nameint = setInterval(getNames2,1000)
countint = setInterval(count,1000)
update(ref(getDatabase(), 'gameid/' + newid), {"started":true});
acint = setInterval(actionCheck,500);
roundint = setInterval(roundCheck,1000)
newround()
update(ref(getDatabase(), 'gameid/' + newid), {
"guessesComplete": 0
});
}
function getNames() {
get(child(ref(getDatabase()), "gameid/" + newid + "/players")).then((snapshot) => {
if (snapshot.exists()) {
var data = snapshot.val()
var stringdata = "";
Object.keys(data).forEach(function(k) {
stringdata = stringdata + "<div class='name'>" + data[k] + "</div>"
})
namesD.innerHTML = stringdata
window.names = [];
var num = -1
Object.keys(data).forEach(function(k) {
num = num + 1
names[num] = data[k]
})
if (Object.keys(data).length > 1) {
sbtn.style.display = "block";
}
}})
}
function getNames2() {
get(child(ref(getDatabase()), "gameid/" + newid + "/players")).then((snapshot) => {
if (snapshot.exists()) {
var data = snapshot.val()
var tempnames = [];
var num = -1
Object.keys(data).forEach(function(k) {
num = num + 1
tempnames[num] = data[k]
})
window.names = tempnames
if (names.length == 1) {voteS()}
} else {
interact("assets/grave.png","<div>Game Lost!<h5>Everyone was bitten by a spider before the exterminator arrived</h5></div>")
setTimeout(endGame,5000)
}
})
}
var roundint;
var guesserAmnt;
function newround() {
var src = rooms[sourceR]
var options = [sourceR,src.room1,src.room2]
var currentRoom = options[Math.floor(Math.random() * options.length)]
var name1 = names[Math.floor(Math.random() * names.length)]
guesserAmnt = 1
update(ref(getDatabase(), 'gameid/' + newid), {
"currentGuessers": name1,
"currentAttackRoom": currentRoom
});
}
function roundCheck() {
get(child(ref(getDatabase()), "gameid/" + newid)).then((snapshot) => {
var data = snapshot.val()
if (data.guessesComplete == guesserAmnt) {
update(ref(getDatabase(), 'gameid/' + newid), {
"currentGuessers": null,
"guessesComplete": 0
});
setTimeout(newround,2000)
}
})
}
function getInfo() {
get(child(ref(getDatabase()), "gameid/" + newid)).then((snapshot) => {
if (snapshot.exists()) {
var data = snapshot.val()
if (data.clues) {
hostInfo.innerHTML = "<h1>What we know</h1>" + data.clues
}
}})
}
var trMin = 60
var trHour = 2
function count() {
trMin = trMin - 1
if (trMin == -1) {
trMin = 59
trHour = trHour - 1
}
if (trMin.toString().length == 1) {
var minTXT = "0" + trMin
} else {
var minTXT = trMin
}
if (trHour == 0 && trMin == 0) {
voteS()
} else {
hostTime.innerHTML = trHour + ":" + minTXT
}
}
function endGame(curl) {
set(ref(getDatabase(), 'gameid/' + newid), {});
if (curl) {location.replace(curl)} else {location.replace("/")}
}
var nameint;
var voteint;
function voteCheck() {
get(child(ref(getDatabase()), "gameid/" + newid + "/votes")).then((snapshot) => {
if (snapshot.exists()) {
var data = snapshot.val()
var sortedJSON = Object.entries(data).sort((a, b) => b[1] - a[1]).reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});
var sortedArray = Object.keys(sortedJSON)
var num = 0;
sortedArray.forEach(function(k) {
num = num + sortedJSON[k]
})
if (num == names.length) {
clearInterval(voteint)
var winner = sortedArray[0]
console.log(winner)
console.log(sortedArray)
console.log(sortedJSON)
popout("<div style='text-align:center'><h1>We have a winner:</h1><br><h2 class='moi'>" + rooms[winner].freindly + "</h2></div>")
setTimeout(function() {
popout()
setTimeout(function() {guess(winner)},1000)
},5000)
}
}
})
}
menu(`
<div style="text-align:center">
<h1>How to Play</h1>
<p>There's a spider infestation in your house! You quickly call an exterminator, but you realize that you don't know where the nest is! Players will be selected to go into different rooms to find out where the nest is, but be careful! The spiders are poisonous and will try bite you if you get too close. These spiders also only travel to rooms that are close to the nest, so you can use the blueprints to find it's location.</p>
</div>
`)
function voteS() {
update(ref(getDatabase(),'gameid/' + newid),{"action":"<img width='270' src='assets/exterminator.png'><h1>Alright, where are the bugs?</h1>"})
setTimeout(function() {
update(ref(getDatabase(),'gameid/' + newid),{"action":null})
update(ref(getDatabase(),'gameid/' + newid),{"currentGuessers":null})
setTimeout(function() {
update(ref(getDatabase(),'gameid/' + newid),{"action":"<h1>Vote for the room you think the nest is.</h1>"})
voteint = setInterval(voteCheck,1000)
hostTime.innerHTML = "VOTE"
setTimeout(function() {popout()},2000)
},1000)
},5000)
clearInterval(countint)
clearInterval(nameint)
}
window.voteCheck = voteCheck
window.count = count
window.endGame = endGame
window.createGame = createGame
window.startG = startG
window.newround = newround
window.onbeforeunload = function() {set(ref(getDatabase(), 'gameid/' + newid), {})}
</script>
</html>