-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
255 lines (215 loc) · 7.76 KB
/
script.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
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
253
254
255
let gameActive = false;
let countdownActive = false;
let multiplier = 1.0;
let crashMultiplier = 0;
let playerData = [];
let gameHistory = [];
let interval;
let countdownInterval;
const multiplierDisplay = document.getElementById("multiplier-display");
const rocket = document.getElementById("rocket");
const smokeContainer = document.getElementById("smoke-container");
const gameStatus = document.getElementById("game-status");
const playerTable = document.getElementById("player-table");
const betInput = document.getElementById("bet-amount");
const autoCashoutInput = document.getElementById("auto-cashout");
const placeBetButton = document.getElementById("place-bet");
const cashoutButton = document.getElementById("cashout");
const historyBar = document.getElementById("history-bar");
const rocketSound = document.getElementById("rocket-sound");
const explosionSound = document.getElementById("explosion-sound");
// Generate smoke
function generateSmoke() {
const smoke = document.createElement("div");
smoke.classList.add("smoke");
smokeContainer.appendChild(smoke);
setTimeout(() => smoke.remove(), 2000); // Remove smoke puff after 2 seconds
}
// Calculate crash point
function calculateCrashMultiplier() {
const roll = Math.random() * 100;
if (roll <= 60) return (Math.random() * 4 + 1).toFixed(2); // 60% chance for 1x to 5x
if (roll <= 70) return (Math.random() * 15 + 5).toFixed(2); // 10% chance for 5x to 20x
if (roll <= 75) return (Math.random() * 80 + 20).toFixed(2); // 5% chance for 20x to 100x
if (roll <= 77) return (Math.random() * 900 + 100).toFixed(2); // 2% chance for 100x to 1000x
return 1.01; // Default fallback
}
// Update crash history
function updateCrashHistory(crashPoint) {
if (gameHistory.length >= 10) {
gameHistory.shift(); // Remove the oldest entry to maintain only 10 results
}
gameHistory.push(parseFloat(crashPoint));
// Clear the history bar
historyBar.innerHTML = "";
// Create history items dynamically
gameHistory.forEach(point => {
const historyItem = document.createElement("div");
historyItem.classList.add("history-item");
// Determine the color based on the crash point
if (point < 2) {
historyItem.classList.add("red");
} else if (point < 10) {
historyItem.classList.add("green");
} else if (point < 20) {
historyItem.classList.add("light-blue");
} else {
historyItem.classList.add("yellow");
}
historyItem.textContent = `${point.toFixed(2)}x`;
historyBar.appendChild(historyItem);
});
}
// Start game
function startGame() {
gameActive = true;
countdownActive = false; // Disable countdown
multiplier = 1.0;
crashMultiplier = calculateCrashMultiplier();
gameStatus.textContent = "Game is active!";
multiplierDisplay.textContent = "1.00x";
rocket.style.bottom = "0px";
rocket.style.transition = "bottom 0.1s linear";
cashoutButton.disabled = false;
placeBetButton.disabled = true; // Disable placing new bets when the game starts
// Play rocket launch sound in a loop
rocketSound.volume = 0.2; // Set volume to 20%
rocketSound.loop = true; // Enable looping
rocketSound.currentTime = 0; // Reset audio
rocketSound.play();
interval = setInterval(() => {
if (multiplier >= crashMultiplier) {
crashGame();
return;
}
// Update multiplier and rocket position
multiplier += multiplier < 10 ? 0.01 : 0.05; // Faster multiplier after 10x
multiplierDisplay.textContent = `${multiplier.toFixed(2)}x`;
// Keep the rocket within the game area, slowing movement after 10x
if (multiplier < 10) {
rocket.style.bottom = `${(multiplier - 1) * 20}px`;
} else {
rocket.style.bottom = `${200 + (multiplier - 10) * 10}px`; // Slower upward movement
}
generateSmoke();
playerData.forEach(player => {
if (player.status === "active" && multiplier >= player.autoCashout) {
cashOut(player, "auto");
}
});
}, 100);
}
// Crash game
function crashGame() {
clearInterval(interval);
gameActive = false;
gameStatus.textContent = `Crashed at ${crashMultiplier}x`;
smokeContainer.innerHTML = ""; // Clear all smoke
// Stop rocket sound immediately
rocketSound.pause();
rocketSound.currentTime = 0; // Reset rocket sound
// Play explosion sound
explosionSound.volume = 0.3; // Set volume to 30%
explosionSound.currentTime = 0; // Reset explosion audio
explosionSound.play();
// Stop explosion sound after 2 seconds
setTimeout(() => {
explosionSound.pause();
explosionSound.currentTime = 0; // Reset explosion sound
}, 2000);
// Update crash history
updateCrashHistory(crashMultiplier);
// Mark all players as lost
playerData.forEach(player => {
if (player.status === "active") {
player.status = "lost";
player.profit = -player.betAmount;
}
});
updatePlayerTable();
// Clear player bets for the next game
playerData = [];
setTimeout(() => {
startCountdown();
}, 1000); // Delay before the countdown starts
}
// Start countdown for the next game
function startCountdown() {
let countdown = 10;
gameStatus.textContent = `Next game starts in ${countdown} seconds`;
countdownActive = true;
// Enable placing new bets during countdown
placeBetButton.disabled = false;
countdownInterval = setInterval(() => {
countdown -= 1;
gameStatus.textContent = `Next game starts in ${countdown} seconds`;
if (countdown <= 0) {
clearInterval(countdownInterval);
placeBetButton.disabled = true; // Lock bets before starting the game
resetGame(); // Reset game state and start the next game
}
}, 1000);
}
// Reset game
function resetGame() {
updatePlayerTable(); // Clear player table for the new game
multiplier = 1.0;
crashMultiplier = 0;
rocket.style.bottom = "0px";
cashoutButton.disabled = true; // Disable cashout button
gameActive = false;
countdownActive = false;
// Start the game automatically, even if no bets exist
startGame();
}
// Place Bet
placeBetButton.addEventListener("click", () => {
if (gameActive) {
gameStatus.textContent = "❌ Bets are locked. Wait for the next game.";
return;
}
const betAmount = parseFloat(betInput.value);
const autoCashout = parseFloat(autoCashoutInput.value);
if (isNaN(betAmount) || isNaN(autoCashout)) {
gameStatus.textContent = "❌ Invalid input!";
return;
}
playerData.push({
betAmount,
autoCashout,
profit: 0,
status: "active",
});
updatePlayerTable();
gameStatus.textContent = `✅ Bet placed: $${betAmount} (Auto Cashout: ${autoCashout}x)`;
if (!countdownActive && !gameActive) {
// Start the countdown if this is the first bet
startCountdown();
}
});
// Cash Out
cashoutButton.addEventListener("click", () => {
if (!gameActive) return;
const player = playerData.find(p => p.status === "active");
if (!player) return;
cashOut(player, "manual");
});
function cashOut(player, type) {
player.status = "cashed_out";
player.profit = (player.betAmount * multiplier).toFixed(2);
gameStatus.textContent = `✅ Cashed out at ${multiplier.toFixed(2)}x! Won $${player.profit}`;
updatePlayerTable();
}
// Update Player Table
function updatePlayerTable() {
playerTable.innerHTML = "";
playerData.forEach(player => {
const row = document.createElement("tr");
row.innerHTML = `
<td>$${player.betAmount.toFixed(2)}</td>
<td>${player.status === "active" ? "-" : `${multiplier.toFixed(2)}x`}</td>
<td style="color: ${player.profit < 0 ? "red" : "limegreen"};">$${player.profit}</td>
`;
playerTable.appendChild(row);
});
}