Spaces:
Running
Running
File size: 2,017 Bytes
a6b6ac5 | 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 | let balance = 100;
let multiplier = 1.0;
let isFlying = false;
let crashPoint = 0;
const balanceDisplay = document.getElementById("balance");
const multiplierDisplay = document.getElementById("multiplier");
const startGameButton = document.getElementById("start-game");
const cashOutButton = document.getElementById("cash-out");
const plane = document.getElementById("plane");
// Update balance display
function updateBalance() {
balanceDisplay.textContent = balance.toFixed(2);
}
// Reset plane position
function resetPlane() {
plane.style.left = "0";
}
// Move the plane
function movePlane(multiplier) {
const maxWidth = document.getElementById("game-area").offsetWidth - plane.offsetWidth;
const newLeft = Math.min(maxWidth, (multiplier / 5) * maxWidth); // Adjust scaling factor
plane.style.left = `${newLeft}px`;
}
// Start the game
startGameButton.addEventListener("click", () => {
if (isFlying) return;
crashPoint = (Math.random() * 5 + 1).toFixed(2); // Random crash point
isFlying = true;
multiplier = 1.0;
startGameButton.disabled = true;
cashOutButton.disabled = false;
resetPlane();
// Multiplier increase loop
const flightInterval = setInterval(() => {
if (multiplier >= crashPoint) {
clearInterval(flightInterval);
isFlying = false;
alert("Crashed! You lost your stake.");
resetGame();
} else {
multiplier += 0.1;
multiplierDisplay.textContent = multiplier.toFixed(2) + "x";
movePlane(multiplier);
}
}, 100);
});
// Cash out
cashOutButton.addEventListener("click", () => {
if (!isFlying) return;
isFlying = false;
balance += (multiplier - 1) * 10; // Example: stake of 10
updateBalance();
alert(`You cashed out at ${multiplier.toFixed(2)}x!`);
resetGame();
});
// Reset game
function resetGame() {
startGameButton.disabled = false;
cashOutButton.disabled = true;
multiplier = 1.0;
multiplierDisplay.textContent = "1.00x";
resetPlane();
}
// Initialize balance display
updateBalance(); |