File size: 2,954 Bytes
84031f1
 
 
 
 
 
 
 
 
 
2ce3b01
84031f1
 
 
 
 
2ce3b01
 
84031f1
 
 
2ce3b01
 
84031f1
 
 
 
 
 
2ce3b01
 
84031f1
 
 
 
 
 
 
48ea0fb
 
 
 
 
 
 
 
 
2ce3b01
48ea0fb
 
 
2ce3b01
48ea0fb
 
 
 
 
 
 
 
2ce3b01
48ea0fb
84031f1
2ce3b01
84031f1
 
 
48ea0fb
84031f1
 
48ea0fb
 
 
 
 
2ce3b01
48ea0fb
84031f1
 
2ce3b01
84031f1
 
 
 
 
 
 
 
 
 
 
2ce3b01
84031f1
 
48ea0fb
 
2ce3b01
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
document.addEventListener("DOMContentLoaded", () => {
  const balanceDisplay = document.getElementById("balance");
  const stakeAmountInput = document.getElementById("stake-amount");
  const stakeBtn = document.getElementById("stake-btn");
  const cashoutBtn = document.getElementById("cashout-btn");
  const backBtn = document.getElementById("back-btn");
  const plane = document.getElementById("plane");
  const multiplierDisplay = document.getElementById("multiplier");
  const audio = new Audio("sound.mp3"); // Replace with your sound file path

  let balance = 10000; // Default balance
  let gameInterval;
  let multiplier = 1.0;
  let crashPoint = 0;
  let stakeAmount = 0;

  // Play sound
  const playSound = () => {
    if (audio) audio.play();
  };

  // Stop sound
  const stopSound = () => {
    if (audio) {
      audio.pause();
      audio.currentTime = 0; // Reset sound to the beginning
    }
  };

  // Start the game
  const startGame = () => {
    stakeAmount = parseFloat(stakeAmountInput.value);

    if (isNaN(stakeAmount) || stakeAmount <= 0 || stakeAmount > balance) {
      alert("Invalid stake amount.");
      return;
    }

    crashPoint = Math.random() * 5 + 1; // Random crash point for simulation
    multiplier = 1.0;

    balance -= stakeAmount;
    balanceDisplay.textContent = balance.toFixed(2);

    cashoutBtn.disabled = false;
    stakeBtn.disabled = true;

    playSound(); // Play sound when the game starts

    // Start multiplier animation and plane movement
    gameInterval = setInterval(() => {
      multiplier += 0.05; // Slower multiplier increment
      multiplierDisplay.textContent = multiplier.toFixed(2) + "x";

      // Move the plane across the screen
      plane.style.transform = `translateX(${multiplier * 10}px)`;

      if (multiplier >= crashPoint) {
        clearInterval(gameInterval);
        alert("Plane crashed! You lost your stake.");
        stopSound(); // Stop sound on crash
        resetGame();
      }
    }, 200); // Slower interval for smoother animation
  };

  // Cash out before crash
  const cashout = () => {
    clearInterval(gameInterval);

    const winnings = stakeAmount * multiplier;
    balance += winnings;
    balanceDisplay.textContent = balance.toFixed(2);

    alert(`You cashed out at ${multiplier.toFixed(2)}x. Winnings: ${winnings.toFixed(2)}`);
    stopSound(); // Stop sound on cash out
    resetGame();
  };

  // Reset the game state
  const resetGame = () => {
    multiplierDisplay.textContent = "1.0x";
    plane.style.transform = "translateX(0px)";
    cashoutBtn.disabled = true;
    stakeBtn.disabled = false;
  };

  // Event listeners
  stakeBtn.addEventListener("click", startGame);
  cashoutBtn.addEventListener("click", cashout);
  backBtn.addEventListener("click", () => {
    window.location.href = "home"; // Replace with your actual back button URL
  });

  // Initialize balance
  balanceDisplay.textContent = balance.toFixed(2);
});