-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhighScore.js
65 lines (59 loc) · 1.94 KB
/
highScore.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
highScoreBtn = document.querySelector(".trophy");
menuScaffold = document.querySelector(".menuScaffold");
historyScaffold = document.querySelector(".history");
historyBackBtn = document.querySelector(".historyBackBtn");
highScoreBtn.addEventListener("click", () => {
menuScaffold.style.display = "none";
historyScaffold.style.display = "flex";
});
historyBackBtn.addEventListener("click", () => {
menuScaffold.style.display = "block";
historyScaffold.style.display = "none";
});
fetchHistory = async () => {
fetchHistoryData = await fetch(
"https://v-1-multiplayer-b436a-default-rtdb.asia-southeast1.firebasedatabase.app/history.json"
);
historyDataJson = await fetchHistoryData.json();
historyInnerHtml = Object.values(historyDataJson)
.map(
(ele) => `<div class="historyListElement">
<div class="playerInfoHistory winningInfo">
<img src="assets/menu/p${ele.winnerSprite}.JPG" />
<div>
<p>Win</p>
<p>${ele.winnerName}</p>
</div>
</div>
<span class="vs">VS</span>
<div class="playerInfoHistory loosingInfo">
<div>
<p>Loose</p>
<p>${ele.looserName}</p>
</div>
<img src="assets/menu/p${ele.looserSprite}.JPG" />
</div>
</div>`
)
.join("");
document.querySelector(".historyList").innerHTML = historyInnerHtml;
};
fetchHistory();
historyFlag = false;
createHistory = async (winnerName, winnerSprite, looserName, looserSprite) => {
if (!historyFlag) {
historyResponse = await fetch(
"https://v-1-multiplayer-b436a-default-rtdb.asia-southeast1.firebasedatabase.app/history.json",
{
method: "POST",
body: JSON.stringify({
winnerName,
winnerSprite,
looserName,
looserSprite,
}),
}
);
fetchHistory();
}
};