-
Notifications
You must be signed in to change notification settings - Fork 0
/
play.html
238 lines (227 loc) · 9 KB
/
play.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
<!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()" id="close">×</div><div id="popup" style="width:2px;height:2px;"></div></div>
<div id="guessBox"><div class="guessCont"><img onclick="sendChoice(this)" class="guessImg" src="assets/bedbath.jpg" style="width:40%"><br>Ensuite Bathroom</div><div class="guessCont"><img onclick="sendChoice(this)" class="guessImg" src="assets/bed2.jpg"><br>Master Bedroom</div><div class="guessCont"><img onclick="sendChoice(this)" class="guessImg" src="assets/bath.jpg"><br>Bathroom</div><div class="guessCont"><img onclick="sendChoice(this)" class="guessImg" src="assets/bed1.jpg"><br>Second Bedroom</div><div class="guessCont"><img onclick="sendChoice(this)" class="guessImg" src="assets/kitchen.jpg"><br>Kitchen</div><div class="guessCont"><img onclick="sendChoice(this)" class="guessImg" src="assets/living.jpg"><br>Living Room</div><div class="guessCont"><img onclick="sendChoice(this)" class="guessImg" src="assets/family.jpg"><br>Family Room</div></div>
</body>
<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 } 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()
const dbRef = ref(db)
function actionCheck() {
console.log("ac")
get(child(ref(getDatabase()), "gameid/" + gameid)).then((snapshot) => {
if (snapshot.exists()) {
var data = snapshot.val()
var act = data.action
if (act) {
if (act == "<h1>Vote for the room you think the nest is.</h1>") {
setTimeout(function() {
changeBF(function() {sendVote(this)})
popout()
},2000)
}
popout(act)
clearInterval(acint)
acint = setInterval(removeACheck,500)
}
} else {
clearInterval(acint)
clearInterval(turnint)
popout("<h1>Game Ended</h1>")
}
})
}
function removeACheck() {
console.log("rac")
get(child(ref(getDatabase()), "gameid/" + gameid)).then((snapshot) => {
if (snapshot.exists()) {
var data = snapshot.val()
if (!data.action) {
popout()
clearInterval(acint)
acint = setInterval(actionCheck,500)
}
} else {
clearInterval(acint)
clearInterval(turnint)
popout("<h1>Game Ended</h1>")
}
})
}
var startint;
function sync() {
get(child(ref(getDatabase()), "gameid/" + gameid)).then((snapshot) => {
if (snapshot.exists()) {
var data = snapshot.val()
sourceR = data.source
var toadd = {}
toadd["/gameid/" + gameid + "/players/" + playerID] = uid;
update(dbRef,toadd)
acint = setInterval(actionCheck,500)
startint = setInterval(startCheck,100)
popout("<h1>Waiting for the game to start...</h1>")
} else {
popout("<div style='text-align:center'><h1>Game ID Inactive</h1><a href='/'><button>Go Back</button></a></div>")
}
})
}
function startCheck() {
get(child(ref(getDatabase()), "gameid/" + gameid)).then((snapshot) => {
if (snapshot.exists()) {
var data = snapshot.val()
if (data.started == true) {
clearInterval(startint)
popout()
setTimeout(function() {
popout(" ")
},500)
turnint = setInterval(turnCheck,1000)
}
}
})
}
var acint;
if (sessionStorage.getItem("gameid") && localStorage.getItem("username")) {
window.gameid = sessionStorage.getItem("gameid")
var playerID = btoa(Math.random())
window.uid = localStorage.getItem("username")
sync()
} else {
popout("<div style='text-align:center'><h1>Something went wrong!</h1><a href='join'><button>Go Back</button></a></div>")
}
function changeBF(func) {
var choices = guessBox.querySelectorAll(".guessImg")
Object.keys(choices).forEach(function(k) {
choices[k].onclick = func
})
}
function sendVote(elem) {
var choice = elem.src.split("assets/")[1].replace(".jpg","")
get(child(dbRef, "/gameid/" + gameid + "/votes")).then((snapshot) => {
var toadd = {};
if (snapshot.exists()) {
var gdata = snapshot.val();
if (gdata[choice]) {
toadd[choice] = gdata[choice] + 1;
} else {
toadd[choice] = 1;
}
} else {
toadd[choice] = 1;
};
update(ref(db,"/gameid/" + gameid + "/votes"),toadd)
popout("<div style='text-align:center'><h1>Vote Cast</h1>The result will appear on the main screen.</div>")
});
}
function die() {
var options = ["assets/spider1.png","assets/spider2.png"]
interact(options[Math.floor(Math.random() * options.length)],"Spider Attack!")
get(child(dbRef, "/gameid/" + gameid)).then((snapshot) => {
var data = snapshot.val();
var dtext = uid + " was bitten in the " + rooms[data.currentAttackRoom].freindly + "<br>"
if (data.clues) {
var toadd = {
"clues": data.clues + dtext
}
} else {
var toadd = {
"clues": dtext
}
}
update(ref(db,"/gameid/" + gameid),toadd)
})
leave()
}
function sendChoice(elem) {
var choice = elem.src.split("assets/")[1].replace(".jpg","");
get(child(dbRef, "/gameid/" + gameid)).then((snapshot) => {
var data = snapshot.val();
var num1 = data.guessesComplete + 1;
update(ref(db,"/gameid/" + gameid),{"guessesComplete":num1})
if (data.currentAttackRoom == choice) {
die()
} else {
if (choice == rooms[sourceR].room1 || choice == rooms[sourceR].room2 || choice == sourceR) {
popout("<h1>You see a spider scuttle across the room.</h1>")
var dtext = uid + " saw a spider in the " + rooms[choice].freindly + "<br>"
if (data.clues) {
var toadd = {
"clues": data.clues + dtext
}
} else {
var toadd = {
"clues": dtext
}
}
update(ref(db,"/gameid/" + gameid),toadd)
} else {
popout("<h1>You don't see anything in this room.</h1>")
}
}
})
}
function leave() {
clearInterval(acint)
var toadd = {}
toadd["/gameid/" + gameid + "/players/" + playerID] = null;
update(dbRef,toadd)
}
var turnint;
function turnCheck() {
get(child(dbRef, "/gameid/" + gameid)).then((snapshot) => {
var data = snapshot.val();
if (data.currentGuessers) {
if (data.currentGuessers.includes(uid)) {
popout("<h1>Get Ready to Guess!</h1>")
setTimeout(function() {
popout()
},3000)
clearInterval(turnint)
turnint = setInterval(turnBlock,1000)
}
}
})
}
function turnBlock() {
get(child(dbRef, "/gameid/" + gameid)).then((snapshot) => {
var data = snapshot.val();
if (!data.currentGuessers) {
popout()
setTimeout(function() {
popout(" ")
},500)
clearInterval(turnint)
turnint = setInterval(turnCheck,1000)
}
})
}
window.sendChoice = sendChoice
window.sendVote = sendVote
window.turnCheck = turnCheck
window.onbeforeunload = leave
</script>
<script src="script.js"></script>
</html>