mirror of
https://github.com/milk-net/milk-net.github.io.git
synced 2025-04-18 17:23: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
|
||||
function showHorseRacing() {
|
||||
hideAllGames();
|
||||
document.getElementById('horse-racing').style.display = 'block';
|
||||
let balance = 1000;
|
||||
|
||||
// Update balance display
|
||||
function updateBalance() {
|
||||
document.getElementById('balance').innerText = `Balance: $${balance}`;
|
||||
}
|
||||
|
||||
function showBlackjack() {
|
||||
hideAllGames();
|
||||
document.getElementById('blackjack').style.display = 'block';
|
||||
// Show selected game
|
||||
function showGame(gameId) {
|
||||
const games = document.querySelectorAll('.game');
|
||||
games.forEach(game => game.style.display = 'none');
|
||||
document.getElementById(gameId).style.display = 'block';
|
||||
}
|
||||
|
||||
function showSlots() {
|
||||
hideAllGames();
|
||||
document.getElementById('slots').style.display = 'block';
|
||||
}
|
||||
|
||||
function showCoinFlip() {
|
||||
hideAllGames();
|
||||
document.getElementById('coin-flip').style.display = 'block';
|
||||
}
|
||||
|
||||
function hideAllGames() {
|
||||
document.getElementById('horse-racing').style.display = 'none';
|
||||
document.getElementById('blackjack').style.display = 'none';
|
||||
document.getElementById('slots').style.display = 'none';
|
||||
document.getElementById('coin-flip').style.display = 'none';
|
||||
// Get bet amount
|
||||
function getBetAmount() {
|
||||
const bet = parseInt(document.getElementById('bet-amount').value);
|
||||
if (bet > balance) {
|
||||
alert("You don't have enough balance for this bet.");
|
||||
return null;
|
||||
}
|
||||
if (bet <= 0) {
|
||||
alert("Please enter a valid bet amount.");
|
||||
return null;
|
||||
}
|
||||
return bet;
|
||||
}
|
||||
|
||||
// Horse Racing Game
|
||||
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 winner = horses[Math.floor(Math.random() * horses.length)];
|
||||
document.getElementById('race-result').innerText = `The winner is ${winner}!`;
|
||||
}
|
||||
|
||||
// Blackjack Game (Basic Concept)
|
||||
function startBlackjack() {
|
||||
const playerHand = Math.floor(Math.random() * 21) + 1;
|
||||
const dealerHand = Math.floor(Math.random() * 21) + 1;
|
||||
let resultMessage = `You bet on ${playerHorse}. ${winner} wins the race! `;
|
||||
|
||||
let result = '';
|
||||
if (playerHand > 21) {
|
||||
result = `You went over 21! You lose. Your hand: ${playerHand}, Dealer's hand: ${dealerHand}`;
|
||||
} 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}`;
|
||||
if (playerHorse === winner) {
|
||||
balance += bet;
|
||||
resultMessage += `You win $${bet}!`;
|
||||
} 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)
|
||||
function startSlots() {
|
||||
const symbols = ['🍒', '🍋', '🍊', '🍇', '🍉', '🍓'];
|
||||
const spinResult = [symbols[Math.floor(Math.random() * symbols.length)],
|
||||
symbols[Math.floor(Math.random() * symbols.length)],
|
||||
symbols[Math.floor(Math.random() * symbols.length)]];
|
||||
// Blackjack Game
|
||||
let playerCards = [];
|
||||
let dealerCards = [];
|
||||
|
||||
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]) {
|
||||
resultMessage += 'You win!';
|
||||
playerCards = [drawCard(), drawCard()];
|
||||
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 {
|
||||
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;
|
||||
updateBalance();
|
||||
}
|
||||
|
||||
function randomSymbol(symbols) {
|
||||
return symbols[Math.floor(Math.random() * symbols.length)];
|
||||
}
|
||||
|
||||
// Coin Flip Game
|
||||
function flipCoin() {
|
||||
// Get the player's choice
|
||||
const bet = getBetAmount();
|
||||
if (bet === null) return;
|
||||
|
||||
const playerChoice = document.getElementById('coin-choice').value;
|
||||
const outcomes = ['Heads', 'Tails'];
|
||||
|
||||
// Randomly determine the coin flip result
|
||||
const result = outcomes[Math.floor(Math.random() * outcomes.length)];
|
||||
|
||||
// Display the result
|
||||
let resultMessage = `You chose ${playerChoice}. The coin landed on ${result}. `;
|
||||
|
||||
if (playerChoice === result) {
|
||||
resultMessage += "Congratulations, you win!";
|
||||
balance += bet;
|
||||
resultMessage += `You win $${bet}!`;
|
||||
} else {
|
||||
resultMessage += "Sorry, better luck next time!";
|
||||
balance -= bet;
|
||||
resultMessage += `You lose $${bet}.`;
|
||||
}
|
||||
|
||||
document.getElementById('coin-flip-result').innerText = resultMessage;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 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;
|
||||
updateBalance();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue