Dasda
Dasda
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gashapon Machine Game</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="game-container">
<div class="machine">
<img src="https://i.postimg.cc/1gNjxFTF/gashpon-machine.png" alt="Gashapon
Machine" class="gashapon-image">
</div>
<div class="controls">
<h1 style="color: #ffcc00;">Gashapon Game</h1>
<div class="balance-display">Balance: $<span id="balance">1000.00</span></div>
<div>
<label style="color: #cc0000;">Red Balls:</label>
<input type="number" id="redCount" min="1" max="13" value="5">
</div>
<div>
<label style="color: #3366cc;">Blue Balls:</label>
<input type="number" id="blueCount" min="1" max="13" value="5">
</div>
<div>
<label style="color: #ffcc00;">Yellow Balls:</label>
<input type="number" id="yellowCount" min="1" max="13" value="5">
</div>
<div class="betting">
<p>Choose Your Bet:</p>
<input type="number" id="betAmount" value="100" step="10">
<select id="betColor">
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="yellow">Yellow</option>
</select>
</div>
<div class="info">
<p>Current Multiplier: <span id="multiplier">1.00</span>x</p>
<p>Potential Earnings: $<span id="potentialEarnings">0.00</span></p>
<p id="message"></p>
<p id="ballColor" style="font-size: 14px;"></p> <!-- Added ball color display
-->
</div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
css
* {
box-sizing: border-box;
font-family: 'Arial', sans-serif;
}
body {
background-color: #3a3a3a; /* Matte grey background */
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
color: #fff;
}
.game-container {
display: flex;
gap: 30px;
}
.machine {
width: 300px;
height: 500px;
display: flex;
justify-content: center;
align-items: center;
}
.gashapon-image {
width: 100%;
height: auto;
}
.controls {
width: 300px;
padding: 20px;
background: rgba(0, 0, 0, 0.3);
border-radius: 10px;
}
button {
width: 100%;
padding: 10px;
margin: 10px 0;
border: none;
border-radius: 5px;
background-color: #28a745;
color: #fff;
font-size: 16px;
cursor: pointer;
}
button:disabled {
background-color: #6c757d;
cursor: not-allowed;
}
.info {
margin-top: 10px;
}
.balance-display {
font-size: 18px;
margin-bottom: 15px;
}
js
let balance = 1000;
let multiplier = 1;
let betAmount = 0;
let betColor = "";
let redCount = 5;
let blueCount = 5;
let yellowCount = 5;
let totalBalls = 15;
let remainingBalls = totalBalls;
let baseMultiplier = 1.5; // Base multiplier to adjust probabilities
function startGame() {
betAmount = parseFloat(document.getElementById("betAmount").value);
betColor = document.getElementById("betColor").value;
redCount = parseInt(document.getElementById("redCount").value);
blueCount = parseInt(document.getElementById("blueCount").value);
yellowCount = parseInt(document.getElementById("yellowCount").value);
// Check if the total number of balls is 15
if (redCount + blueCount + yellowCount !== totalBalls) {
messageDisplay.innerText = "Total number of balls must be 15!";
return;
}
// Calculate the multiplier based on the number of selected balls and probability
calculateMultiplier();
function continueGame() {
let ball = getRandomBall();
function cashOut() {
messageDisplay.innerText = `You cashed out. You earned $${(betAmount *
multiplier).toFixed(2)}!`;
balance += betAmount * multiplier;
updateUI();
resetGameControls(); // Reset controls after cashing out
}
function getRandomBall() {
// Generate a random ball from the available balls
const balls = Array(redCount).fill("red")
.concat(Array(blueCount).fill("blue"))
.concat(Array(yellowCount).fill("yellow"));
function calculateMultiplier() {
// Calculate multiplier based on the probability of winning
let selectedBallsCount = 0;
function updateUI() {
balanceDisplay.innerText = balance.toFixed(2);
multiplierDisplay.innerText = multiplier.toFixed(2);
potentialEarningsDisplay.innerText = (betAmount * multiplier).toFixed(2);
}
function resetGameControls() {
// Reset the game controls and state
messageDisplay.innerText = "Game Over. You lost!";
// Enable the controls for the next game
startGameButton.disabled = false;
document.getElementById("redCount").disabled = false;
document.getElementById("blueCount").disabled = false;
document.getElementById("yellowCount").disabled = false;
document.getElementById("betAmount").disabled = false;
document.getElementById("betColor").disabled = false;
// Reset the multiplier and remaining balls for the next game
multiplier = 1;
remainingBalls = totalBalls;
function showContinueAndCashOut() {
// Show the buttons to continue or cash out
continueGameButton.style.display = "inline-block";
cashOutButton.style.display = "inline-block";
}