mirror of
https://github.com/milk-net/milk-net.github.io.git
synced 2025-04-19 21:53:40 -05:00
Update script.js
This commit is contained in:
parent
b94bf2fcf2
commit
1f0844f6ab
1 changed files with 136 additions and 77 deletions
|
@ -1,115 +1,174 @@
|
||||||
// Switch between game views
|
let balance = 1000;
|
||||||
function showHorseRacing() {
|
|
||||||
hideAllGames();
|
// Update balance display
|
||||||
document.getElementById('horse-racing').style.display = 'block';
|
function updateBalance() {
|
||||||
|
document.getElementById('balance').innerText = `Balance: $${balance}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function showBlackjack() {
|
// Show selected game
|
||||||
hideAllGames();
|
function showGame(gameId) {
|
||||||
document.getElementById('blackjack').style.display = 'block';
|
const games = document.querySelectorAll('.game');
|
||||||
|
games.forEach(game => game.style.display = 'none');
|
||||||
|
document.getElementById(gameId).style.display = 'block';
|
||||||
}
|
}
|
||||||
|
|
||||||
function showSlots() {
|
// Get bet amount
|
||||||
hideAllGames();
|
function getBetAmount() {
|
||||||
document.getElementById('slots').style.display = 'block';
|
const bet = parseInt(document.getElementById('bet-amount').value);
|
||||||
}
|
if (bet > balance) {
|
||||||
|
alert("You don't have enough balance for this bet.");
|
||||||
function showCoinFlip() {
|
return null;
|
||||||
hideAllGames();
|
}
|
||||||
document.getElementById('coin-flip').style.display = 'block';
|
if (bet <= 0) {
|
||||||
}
|
alert("Please enter a valid bet amount.");
|
||||||
|
return null;
|
||||||
function hideAllGames() {
|
}
|
||||||
document.getElementById('horse-racing').style.display = 'none';
|
return bet;
|
||||||
document.getElementById('blackjack').style.display = 'none';
|
|
||||||
document.getElementById('slots').style.display = 'none';
|
|
||||||
document.getElementById('coin-flip').style.display = 'none';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Horse Racing Game
|
// Horse Racing Game
|
||||||
function startHorseRacing() {
|
function startHorseRacing() {
|
||||||
|
const bet = getBetAmount();
|
||||||
|
if (bet === null) return;
|
||||||
|
|
||||||
|
const playerHorse = document.getElementById('horse-selection').value;
|
||||||
const horses = ['Horse 1', 'Horse 2', 'Horse 3', 'Horse 4'];
|
const horses = ['Horse 1', 'Horse 2', 'Horse 3', 'Horse 4'];
|
||||||
const winner = horses[Math.floor(Math.random() * horses.length)];
|
const winner = horses[Math.floor(Math.random() * horses.length)];
|
||||||
document.getElementById('race-result').innerText = `The winner is ${winner}!`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Blackjack Game (Basic Concept)
|
let resultMessage = `You bet on ${playerHorse}. ${winner} wins the race! `;
|
||||||
function startBlackjack() {
|
|
||||||
const playerHand = Math.floor(Math.random() * 21) + 1;
|
|
||||||
const dealerHand = Math.floor(Math.random() * 21) + 1;
|
|
||||||
|
|
||||||
let result = '';
|
if (playerHorse === winner) {
|
||||||
if (playerHand > 21) {
|
balance += bet;
|
||||||
result = `You went over 21! You lose. Your hand: ${playerHand}, Dealer's hand: ${dealerHand}`;
|
resultMessage += `You win $${bet}!`;
|
||||||
} else if (dealerHand > 21) {
|
|
||||||
result = `Dealer went over 21! You win. Your hand: ${playerHand}, Dealer's hand: ${dealerHand}`;
|
|
||||||
} else if (playerHand > dealerHand) {
|
|
||||||
result = `You win! Your hand: ${playerHand}, Dealer's hand: ${dealerHand}`;
|
|
||||||
} else if (dealerHand > playerHand) {
|
|
||||||
result = `You lose. Your hand: ${playerHand}, Dealer's hand: ${dealerHand}`;
|
|
||||||
} else {
|
} else {
|
||||||
result = `It's a tie! Your hand: ${playerHand}, Dealer's hand: ${dealerHand}`;
|
balance -= bet;
|
||||||
|
resultMessage += `You lose $${bet}.`;
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('blackjack-result').innerText = result;
|
document.getElementById('race-result').innerText = resultMessage;
|
||||||
|
updateBalance();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Slots Game (Random result with 3 symbols)
|
// Blackjack Game
|
||||||
function startSlots() {
|
let playerCards = [];
|
||||||
const symbols = ['🍒', '🍋', '🍊', '🍇', '🍉', '🍓'];
|
let dealerCards = [];
|
||||||
const spinResult = [symbols[Math.floor(Math.random() * symbols.length)],
|
|
||||||
symbols[Math.floor(Math.random() * symbols.length)],
|
|
||||||
symbols[Math.floor(Math.random() * symbols.length)]];
|
|
||||||
|
|
||||||
let resultMessage = `You spun: ${spinResult.join(' | ')}\n`;
|
function startBlackjack() {
|
||||||
|
const bet = getBetAmount();
|
||||||
|
if (bet === null) return;
|
||||||
|
|
||||||
if (spinResult[0] === spinResult[1] && spinResult[1] === spinResult[2]) {
|
playerCards = [drawCard(), drawCard()];
|
||||||
resultMessage += 'You win!';
|
dealerCards = [drawCard(), drawCard()];
|
||||||
|
|
||||||
|
document.getElementById('blackjack-status').innerText = 'Game started. Your move!';
|
||||||
|
showBlackjackCards();
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawCard() {
|
||||||
|
return Math.floor(Math.random() * 11) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function calculateTotal(cards) {
|
||||||
|
return cards.reduce((a, b) => a + b, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function showBlackjackCards() {
|
||||||
|
document.getElementById('blackjack-cards').innerText =
|
||||||
|
`Your cards: ${playerCards.join(', ')} (Total: ${calculateTotal(playerCards)})\n` +
|
||||||
|
`Dealer shows: ${dealerCards[0]}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function hit() {
|
||||||
|
playerCards.push(drawCard());
|
||||||
|
showBlackjackCards();
|
||||||
|
const total = calculateTotal(playerCards);
|
||||||
|
if (total > 21) endBlackjackGame('lose');
|
||||||
|
}
|
||||||
|
|
||||||
|
function stand() {
|
||||||
|
while (calculateTotal(dealerCards) < 17) {
|
||||||
|
dealerCards.push(drawCard());
|
||||||
|
}
|
||||||
|
|
||||||
|
const playerTotal = calculateTotal(playerCards);
|
||||||
|
const dealerTotal = calculateTotal(dealerCards);
|
||||||
|
|
||||||
|
if (dealerTotal > 21 || playerTotal > dealerTotal) {
|
||||||
|
endBlackjackGame('win');
|
||||||
|
} else if (playerTotal === dealerTotal) {
|
||||||
|
endBlackjackGame('draw');
|
||||||
} else {
|
} else {
|
||||||
resultMessage += 'Try again!';
|
endBlackjackGame('lose');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function endBlackjackGame(result) {
|
||||||
|
const bet = getBetAmount();
|
||||||
|
if (bet === null) return;
|
||||||
|
|
||||||
|
let message = '';
|
||||||
|
if (result === 'win') {
|
||||||
|
balance += bet;
|
||||||
|
message = `You win $${bet}!`;
|
||||||
|
} else if (result === 'lose') {
|
||||||
|
balance -= bet;
|
||||||
|
message = `You lose $${bet}.`;
|
||||||
|
} else {
|
||||||
|
message = "It's a draw!";
|
||||||
|
}
|
||||||
|
|
||||||
|
updateBalance();
|
||||||
|
document.getElementById('blackjack-status').innerText =
|
||||||
|
`${message} Dealer's cards: ${dealerCards.join(', ')} (Total: ${calculateTotal(dealerCards)})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Slots Game
|
||||||
|
function playSlots() {
|
||||||
|
const bet = getBetAmount();
|
||||||
|
if (bet === null) return;
|
||||||
|
|
||||||
|
const symbols = ['🍒', '🍋', '🍊', '🍉', '⭐'];
|
||||||
|
const spin = [randomSymbol(symbols), randomSymbol(symbols), randomSymbol(symbols)];
|
||||||
|
|
||||||
|
let resultMessage = `Result: ${spin.join(' ')}`;
|
||||||
|
if (spin.every(s => s === spin[0])) {
|
||||||
|
balance += bet * 5;
|
||||||
|
resultMessage += `\nJackpot! You win $${bet * 5}!`;
|
||||||
|
} else if (new Set(spin).size === 2) {
|
||||||
|
balance += bet * 2;
|
||||||
|
resultMessage += `\nTwo of a kind! You win $${bet * 2}!`;
|
||||||
|
} else {
|
||||||
|
balance -= bet;
|
||||||
|
resultMessage += `\nYou lose $${bet}.`;
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('slots-result').innerText = resultMessage;
|
document.getElementById('slots-result').innerText = resultMessage;
|
||||||
|
updateBalance();
|
||||||
|
}
|
||||||
|
|
||||||
|
function randomSymbol(symbols) {
|
||||||
|
return symbols[Math.floor(Math.random() * symbols.length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Coin Flip Game
|
// Coin Flip Game
|
||||||
function flipCoin() {
|
function flipCoin() {
|
||||||
// Get the player's choice
|
const bet = getBetAmount();
|
||||||
|
if (bet === null) return;
|
||||||
|
|
||||||
const playerChoice = document.getElementById('coin-choice').value;
|
const playerChoice = document.getElementById('coin-choice').value;
|
||||||
const outcomes = ['Heads', 'Tails'];
|
const outcomes = ['Heads', 'Tails'];
|
||||||
|
|
||||||
// Randomly determine the coin flip result
|
|
||||||
const result = outcomes[Math.floor(Math.random() * outcomes.length)];
|
const result = outcomes[Math.floor(Math.random() * outcomes.length)];
|
||||||
|
|
||||||
// Display the result
|
|
||||||
let resultMessage = `You chose ${playerChoice}. The coin landed on ${result}. `;
|
let resultMessage = `You chose ${playerChoice}. The coin landed on ${result}. `;
|
||||||
|
|
||||||
if (playerChoice === result) {
|
if (playerChoice === result) {
|
||||||
resultMessage += "Congratulations, you win!";
|
balance += bet;
|
||||||
|
resultMessage += `You win $${bet}!`;
|
||||||
} else {
|
} else {
|
||||||
resultMessage += "Sorry, better luck next time!";
|
balance -= bet;
|
||||||
|
resultMessage += `You lose $${bet}.`;
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('coin-flip-result').innerText = resultMessage;
|
document.getElementById('coin-flip-result').innerText = resultMessage;
|
||||||
}
|
updateBalance();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Horse Racing Game
|
|
||||||
function startHorseRacing() {
|
|
||||||
// Get the horse selected by the player
|
|
||||||
const playerHorse = document.getElementById('horse-selection').value;
|
|
||||||
const horses = ['Horse 1', 'Horse 2', 'Horse 3', 'Horse 4'];
|
|
||||||
|
|
||||||
// Simulate the race and randomly choose a winner
|
|
||||||
const winner = horses[Math.floor(Math.random() * horses.length)];
|
|
||||||
|
|
||||||
// Display the results
|
|
||||||
let resultMessage = `You bet on ${playerHorse}. `;
|
|
||||||
if (playerHorse === winner) {
|
|
||||||
resultMessage += `Congratulations! ${winner} wins the race!`;
|
|
||||||
} else {
|
|
||||||
resultMessage += `Sorry, ${winner} wins the race. Better luck next time!`;
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById('race-result').innerText = resultMessage;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue