Spaces:
Sleeping
Sleeping
Update static/script.js
Browse files- static/script.js +20 -4
static/script.js
CHANGED
@@ -54,9 +54,10 @@ function buyCoin(index) {
|
|
54 |
.then((data) => {
|
55 |
if (data.success) {
|
56 |
balance = data.balance;
|
57 |
-
currentCoin =
|
58 |
-
document.getElementById("coin").style.backgroundColor = coins[
|
59 |
updateInfo();
|
|
|
60 |
} else {
|
61 |
alert("Not enough money to buy this coin or you already own it!");
|
62 |
}
|
@@ -82,6 +83,8 @@ function generateCoin() {
|
|
82 |
updateInfo();
|
83 |
} else {
|
84 |
alert("Failed to generate new coin: " + data.error);
|
|
|
|
|
85 |
}
|
86 |
})
|
87 |
.finally(() => {
|
@@ -116,8 +119,8 @@ function createShopItem(coin, index) {
|
|
116 |
<strong>${coin.name}</strong><br>
|
117 |
Cost: $${coin.price.toFixed(2)}<br>
|
118 |
Value: $${coin.value.toFixed(2)}<br>
|
119 |
-
Win rate: ${coin.winrate.toFixed(2)}
|
120 |
-
|
121 |
`;
|
122 |
|
123 |
shopCoin.appendChild(coinPrice);
|
@@ -130,6 +133,17 @@ function createShopItem(coin, index) {
|
|
130 |
return shopItem;
|
131 |
}
|
132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
function showGameOver() {
|
134 |
const modal = document.getElementById("game-over");
|
135 |
const finalScore = document.getElementById("final-score");
|
@@ -171,6 +185,7 @@ function resetGame() {
|
|
171 |
updateInfo();
|
172 |
document.getElementById("coin").style.backgroundColor = coins[0].color;
|
173 |
document.getElementById("game-over").style.display = "none";
|
|
|
174 |
}
|
175 |
});
|
176 |
}
|
@@ -182,4 +197,5 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
182 |
document.getElementById("submit-score").onclick = submitScore;
|
183 |
document.getElementById("play-again").onclick = resetGame;
|
184 |
document.getElementById("coin").style.backgroundColor = coins[0].color;
|
|
|
185 |
});
|
|
|
54 |
.then((data) => {
|
55 |
if (data.success) {
|
56 |
balance = data.balance;
|
57 |
+
currentCoin = data.current_coin;
|
58 |
+
document.getElementById("coin").style.backgroundColor = coins[currentCoin].color;
|
59 |
updateInfo();
|
60 |
+
updateSelectedCoin();
|
61 |
} else {
|
62 |
alert("Not enough money to buy this coin or you already own it!");
|
63 |
}
|
|
|
83 |
updateInfo();
|
84 |
} else {
|
85 |
alert("Failed to generate new coin: " + data.error);
|
86 |
+
balance = data.balance;
|
87 |
+
updateInfo();
|
88 |
}
|
89 |
})
|
90 |
.finally(() => {
|
|
|
119 |
<strong>${coin.name}</strong><br>
|
120 |
Cost: $${coin.price.toFixed(2)}<br>
|
121 |
Value: $${coin.value.toFixed(2)}<br>
|
122 |
+
Win rate: ${(coin.winrate * 100).toFixed(2)}%<br>
|
123 |
+
Bonus: $${coin.bonus.toFixed(2)}
|
124 |
`;
|
125 |
|
126 |
shopCoin.appendChild(coinPrice);
|
|
|
133 |
return shopItem;
|
134 |
}
|
135 |
|
136 |
+
function updateSelectedCoin() {
|
137 |
+
const shopItems = document.querySelectorAll('.shop-item');
|
138 |
+
shopItems.forEach((item, index) => {
|
139 |
+
if (index === currentCoin) {
|
140 |
+
item.classList.add('selected');
|
141 |
+
} else {
|
142 |
+
item.classList.remove('selected');
|
143 |
+
}
|
144 |
+
});
|
145 |
+
}
|
146 |
+
|
147 |
function showGameOver() {
|
148 |
const modal = document.getElementById("game-over");
|
149 |
const finalScore = document.getElementById("final-score");
|
|
|
185 |
updateInfo();
|
186 |
document.getElementById("coin").style.backgroundColor = coins[0].color;
|
187 |
document.getElementById("game-over").style.display = "none";
|
188 |
+
updateSelectedCoin();
|
189 |
}
|
190 |
});
|
191 |
}
|
|
|
197 |
document.getElementById("submit-score").onclick = submitScore;
|
198 |
document.getElementById("play-again").onclick = resetGame;
|
199 |
document.getElementById("coin").style.backgroundColor = coins[0].color;
|
200 |
+
updateSelectedCoin();
|
201 |
});
|