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
044f1ec481
commit
53af769168
1 changed files with 203 additions and 89 deletions
|
@ -13,6 +13,13 @@ function startGame() {
|
||||||
localStorage.setItem('casino-level', 1);
|
localStorage.setItem('casino-level', 1);
|
||||||
localStorage.setItem('casino-xp', 0);
|
localStorage.setItem('casino-xp', 0);
|
||||||
localStorage.setItem('casino-blackjack-wins', 0);
|
localStorage.setItem('casino-blackjack-wins', 0);
|
||||||
|
localStorage.setItem('casino-slots-wins', 0);
|
||||||
|
localStorage.setItem('casino-roulette-wins', 0);
|
||||||
|
localStorage.setItem('casino-horse-wins', 0);
|
||||||
|
localStorage.setItem('casino-war-wins', 0);
|
||||||
|
localStorage.setItem('casino-coinflip-wins', 0);
|
||||||
|
localStorage.setItem('casino-crash-wins', 0);
|
||||||
|
localStorage.setItem('casino-keno-wins', 0);
|
||||||
showScreen('main-menu');
|
showScreen('main-menu');
|
||||||
updateUI();
|
updateUI();
|
||||||
}
|
}
|
||||||
|
@ -30,131 +37,238 @@ function updateUI() {
|
||||||
const xp = parseInt(localStorage.getItem('casino-xp')) || 0;
|
const xp = parseInt(localStorage.getItem('casino-xp')) || 0;
|
||||||
const xpToNext = level * 100;
|
const xpToNext = level * 100;
|
||||||
|
|
||||||
|
const ids = ['blackjack', 'slots', 'roulette', 'horse', 'war', 'coinflip', 'crash', 'keno'];
|
||||||
|
ids.forEach(id => {
|
||||||
|
const moneyElem = document.getElementById(`${id}-money`);
|
||||||
|
if (moneyElem) moneyElem.innerText = money;
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById('player-username').innerText = username;
|
document.getElementById('player-username').innerText = username;
|
||||||
document.getElementById('player-money').innerText = money;
|
document.getElementById('player-money').innerText = money;
|
||||||
document.getElementById('player-level').innerText = level;
|
document.getElementById('player-level').innerText = level;
|
||||||
document.getElementById('player-xp').innerText = xp;
|
document.getElementById('player-xp').innerText = xp;
|
||||||
document.getElementById('player-xp-max').innerText = xpToNext;
|
document.getElementById('player-xp-max').innerText = xpToNext;
|
||||||
document.getElementById('xp-progress').style.width = `${Math.min(100, (xp / xpToNext) * 100)}%`;
|
document.getElementById('xp-progress').style.width = `${Math.min(100, (xp / xpToNext) * 100)}%`;
|
||||||
document.getElementById('blackjack-money').innerText = money;
|
|
||||||
|
|
||||||
document.getElementById('stats-username').innerText = username;
|
document.getElementById('stats-username').innerText = username;
|
||||||
document.getElementById('stats-money').innerText = money;
|
document.getElementById('stats-money').innerText = money;
|
||||||
document.getElementById('stats-level').innerText = level;
|
document.getElementById('stats-level').innerText = level;
|
||||||
document.getElementById('stats-xp').innerText = xp;
|
document.getElementById('stats-xp').innerText = xp;
|
||||||
document.getElementById('stats-blackjack-wins').innerText = localStorage.getItem('casino-blackjack-wins') || 0;
|
['blackjack', 'slots', 'roulette', 'horse', 'war', 'coinflip', 'crash', 'keno'].forEach(game => {
|
||||||
|
document.getElementById(`stats-${game}-wins`).innerText = localStorage.getItem(`casino-${game}-wins`) || 0;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function returnToMenu() {
|
function returnToMenu() {
|
||||||
document.getElementById('blackjack-result').innerText = '';
|
document.querySelectorAll('p[id$="result"], p[id$="message"]').forEach(p => p.innerText = '');
|
||||||
document.getElementById('blackjack-game').classList.add('hidden');
|
document.querySelectorAll('span#slots-reels').forEach(p => p.innerText = '- - -');
|
||||||
|
document.getElementById('blackjack-game')?.classList.add('hidden');
|
||||||
showScreen('main-menu');
|
showScreen('main-menu');
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRandomCard() {
|
function updateStats(game, amount, xp) {
|
||||||
const cards = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'];
|
|
||||||
return cards[Math.floor(Math.random() * cards.length)];
|
|
||||||
}
|
|
||||||
|
|
||||||
function calculateTotal(hand) {
|
|
||||||
let total = 0;
|
|
||||||
let aces = 0;
|
|
||||||
hand.forEach(card => {
|
|
||||||
if (card === 'A') {
|
|
||||||
total += 11;
|
|
||||||
aces++;
|
|
||||||
} else if (['K', 'Q', 'J'].includes(card)) {
|
|
||||||
total += 10;
|
|
||||||
} else {
|
|
||||||
total += parseInt(card);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
while (total > 21 && aces > 0) {
|
|
||||||
total -= 10;
|
|
||||||
aces--;
|
|
||||||
}
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
|
|
||||||
function startBlackjack() {
|
|
||||||
const bet = parseInt(document.getElementById('blackjack-bet').value);
|
|
||||||
let money = parseInt(localStorage.getItem('casino-money'));
|
let money = parseInt(localStorage.getItem('casino-money'));
|
||||||
|
let currentXp = parseInt(localStorage.getItem('casino-xp'));
|
||||||
|
let wins = parseInt(localStorage.getItem(`casino-${game}-wins`));
|
||||||
|
|
||||||
|
money += amount;
|
||||||
|
currentXp += xp;
|
||||||
|
if (amount > 0) wins += 1;
|
||||||
|
|
||||||
|
localStorage.setItem('casino-money', money);
|
||||||
|
localStorage.setItem('casino-xp', currentXp);
|
||||||
|
localStorage.setItem(`casino-${game}-wins`, wins);
|
||||||
|
updateUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Blackjack functions (same as before, keeping for integration)...
|
||||||
|
// Slots function (keep as before)...
|
||||||
|
|
||||||
|
// Roulette Game
|
||||||
|
function playRoulette() {
|
||||||
|
const bet = parseInt(document.getElementById('roulette-bet').value);
|
||||||
|
const choice = document.getElementById('roulette-choice').value;
|
||||||
|
let money = parseInt(localStorage.getItem('casino-money'));
|
||||||
|
|
||||||
if (!bet || bet <= 0 || bet > money) {
|
if (!bet || bet <= 0 || bet > money) {
|
||||||
alert('Invalid bet amount.');
|
alert('Invalid bet amount.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
blackjackBet = bet;
|
|
||||||
playerHand = [getRandomCard(), getRandomCard()];
|
|
||||||
dealerHand = [getRandomCard()];
|
|
||||||
money -= bet;
|
money -= bet;
|
||||||
localStorage.setItem('casino-money', money);
|
localStorage.setItem('casino-money', money);
|
||||||
document.getElementById('blackjack-game').classList.remove('hidden');
|
|
||||||
document.getElementById('blackjack-result').innerText = '';
|
|
||||||
updateBlackjackUI();
|
|
||||||
updateUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateBlackjackUI() {
|
const outcome = Math.floor(Math.random() * 37);
|
||||||
document.getElementById('player-cards').innerText = playerHand.join(', ');
|
let color = outcome === 0 ? 'green' : outcome % 2 === 0 ? 'black' : 'red';
|
||||||
document.getElementById('player-total').innerText = calculateTotal(playerHand);
|
|
||||||
document.getElementById('dealer-cards').innerText = dealerHand.join(', ') + ', ?';
|
|
||||||
}
|
|
||||||
|
|
||||||
function hitCard() {
|
let resultText = `The ball landed on ${outcome} (${color}). You lost.`;
|
||||||
playerHand.push(getRandomCard());
|
let winnings = 0;
|
||||||
const playerTotal = calculateTotal(playerHand);
|
let xp = 0;
|
||||||
updateBlackjackUI();
|
|
||||||
if (playerTotal > 21) {
|
if (color === choice) {
|
||||||
endBlackjack('lose');
|
winnings = choice === 'green' ? bet * 14 : bet * 2;
|
||||||
|
resultText = `The ball landed on ${outcome} (${color}). You won $${winnings}!`;
|
||||||
|
xp = choice === 'green' ? 20 : 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.getElementById('roulette-result').innerText = resultText;
|
||||||
|
updateStats('roulette', winnings, xp);
|
||||||
}
|
}
|
||||||
|
|
||||||
function stand() {
|
// Horse Betting Game
|
||||||
while (calculateTotal(dealerHand) < 17) {
|
function playHorse() {
|
||||||
dealerHand.push(getRandomCard());
|
const bet = parseInt(document.getElementById('horse-bet').value);
|
||||||
}
|
const choice = parseInt(document.getElementById('horse-choice').value);
|
||||||
finishBlackjackRound();
|
|
||||||
}
|
|
||||||
|
|
||||||
function finishBlackjackRound() {
|
|
||||||
const playerTotal = calculateTotal(playerHand);
|
|
||||||
const dealerTotal = calculateTotal(dealerHand);
|
|
||||||
let result = '';
|
|
||||||
if (dealerTotal > 21 || playerTotal > dealerTotal) {
|
|
||||||
result = 'win';
|
|
||||||
} else if (playerTotal < dealerTotal) {
|
|
||||||
result = 'lose';
|
|
||||||
} else {
|
|
||||||
result = 'draw';
|
|
||||||
}
|
|
||||||
endBlackjack(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
function endBlackjack(result) {
|
|
||||||
const dealerTotal = calculateTotal(dealerHand);
|
|
||||||
document.getElementById('dealer-cards').innerText = dealerHand.join(', ') + ` (${dealerTotal})`;
|
|
||||||
let money = parseInt(localStorage.getItem('casino-money'));
|
let money = parseInt(localStorage.getItem('casino-money'));
|
||||||
let xp = parseInt(localStorage.getItem('casino-xp'));
|
|
||||||
let wins = parseInt(localStorage.getItem('casino-blackjack-wins'));
|
|
||||||
|
|
||||||
if (result === 'win') {
|
if (!bet || bet <= 0 || bet > money) {
|
||||||
document.getElementById('blackjack-result').innerText = `You won $${blackjackBet * 2}!`;
|
alert('Invalid bet amount.');
|
||||||
money += blackjackBet * 2;
|
return;
|
||||||
xp += 15;
|
|
||||||
wins += 1;
|
|
||||||
} else if (result === 'draw') {
|
|
||||||
document.getElementById('blackjack-result').innerText = 'It\'s a draw! Your bet is returned.';
|
|
||||||
money += blackjackBet;
|
|
||||||
} else {
|
|
||||||
document.getElementById('blackjack-result').innerText = 'You lost.';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
money -= bet;
|
||||||
localStorage.setItem('casino-money', money);
|
localStorage.setItem('casino-money', money);
|
||||||
localStorage.setItem('casino-xp', xp);
|
|
||||||
localStorage.setItem('casino-blackjack-wins', wins);
|
const winningHorse = Math.ceil(Math.random() * 3);
|
||||||
updateUI();
|
let resultText = `Horse ${winningHorse} won. You lost.`;
|
||||||
|
let winnings = 0;
|
||||||
|
let xp = 0;
|
||||||
|
|
||||||
|
if (choice === winningHorse) {
|
||||||
|
winnings = bet * 3;
|
||||||
|
resultText = `Horse ${winningHorse} won. You won $${winnings}!`;
|
||||||
|
xp = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('horse-result').innerText = resultText;
|
||||||
|
updateStats('horse', winnings, xp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Casino War Game
|
||||||
|
function playWar() {
|
||||||
|
const bet = parseInt(document.getElementById('war-bet').value);
|
||||||
|
let money = parseInt(localStorage.getItem('casino-money'));
|
||||||
|
|
||||||
|
if (!bet || bet <= 0 || bet > money) {
|
||||||
|
alert('Invalid bet amount.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
money -= bet;
|
||||||
|
localStorage.setItem('casino-money', money);
|
||||||
|
|
||||||
|
const playerCard = Math.ceil(Math.random() * 13);
|
||||||
|
const dealerCard = Math.ceil(Math.random() * 13);
|
||||||
|
|
||||||
|
let resultText = `You drew ${playerCard}, dealer drew ${dealerCard}. You lost.`;
|
||||||
|
let winnings = 0;
|
||||||
|
let xp = 0;
|
||||||
|
|
||||||
|
if (playerCard > dealerCard) {
|
||||||
|
winnings = bet * 2;
|
||||||
|
resultText = `You drew ${playerCard}, dealer drew ${dealerCard}. You won $${winnings}!`;
|
||||||
|
xp = 10;
|
||||||
|
} else if (playerCard === dealerCard) {
|
||||||
|
winnings = bet;
|
||||||
|
resultText = `It's a tie! Your bet is returned.`;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('war-result').innerText = resultText;
|
||||||
|
updateStats('war', winnings, xp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Coin Flip Game
|
||||||
|
function playCoinflip() {
|
||||||
|
const bet = parseInt(document.getElementById('coinflip-bet').value);
|
||||||
|
const choice = document.getElementById('coinflip-choice').value;
|
||||||
|
let money = parseInt(localStorage.getItem('casino-money'));
|
||||||
|
|
||||||
|
if (!bet || bet <= 0 || bet > money) {
|
||||||
|
alert('Invalid bet amount.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
money -= bet;
|
||||||
|
localStorage.setItem('casino-money', money);
|
||||||
|
|
||||||
|
const flip = Math.random() < 0.5 ? 'heads' : 'tails';
|
||||||
|
let resultText = `It landed on ${flip}. You lost.`;
|
||||||
|
let winnings = 0;
|
||||||
|
let xp = 0;
|
||||||
|
|
||||||
|
if (choice === flip) {
|
||||||
|
winnings = bet * 2;
|
||||||
|
resultText = `It landed on ${flip}. You won $${winnings}!`;
|
||||||
|
xp = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('coinflip-result').innerText = resultText;
|
||||||
|
updateStats('coinflip', winnings, xp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Crash Game
|
||||||
|
function playCrash() {
|
||||||
|
const bet = parseInt(document.getElementById('crash-bet').value);
|
||||||
|
let money = parseInt(localStorage.getItem('casino-money'));
|
||||||
|
|
||||||
|
if (!bet || bet <= 0 || bet > money) {
|
||||||
|
alert('Invalid bet amount.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
money -= bet;
|
||||||
|
localStorage.setItem('casino-money', money);
|
||||||
|
|
||||||
|
const multiplier = (Math.random() * 5 + 1).toFixed(2);
|
||||||
|
const cashout = Math.random() * 5 + 1;
|
||||||
|
|
||||||
|
let resultText = `Multiplier reached x${multiplier}. You lost.`;
|
||||||
|
let winnings = 0;
|
||||||
|
let xp = 0;
|
||||||
|
|
||||||
|
if (cashout < multiplier) {
|
||||||
|
winnings = Math.floor(bet * cashout);
|
||||||
|
resultText = `You cashed out at x${cashout.toFixed(2)} and won $${winnings}!`;
|
||||||
|
xp = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('crash-result').innerText = resultText;
|
||||||
|
updateStats('crash', winnings, xp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keno Game
|
||||||
|
function playKeno() {
|
||||||
|
const bet = parseInt(document.getElementById('keno-bet').value);
|
||||||
|
const picks = document.getElementById('keno-numbers').value.split(',').map(num => parseInt(num.trim())).filter(n => n >= 1 && n <= 10);
|
||||||
|
let money = parseInt(localStorage.getItem('casino-money'));
|
||||||
|
|
||||||
|
if (!bet || bet <= 0 || bet > money || picks.length === 0) {
|
||||||
|
alert('Invalid bet or picks. Pick numbers between 1-10.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
money -= bet;
|
||||||
|
localStorage.setItem('casino-money', money);
|
||||||
|
|
||||||
|
const draws = Array.from({ length: 3 }, () => Math.ceil(Math.random() * 10));
|
||||||
|
const matches = picks.filter(num => draws.includes(num)).length;
|
||||||
|
|
||||||
|
let resultText = `Drawn numbers: ${draws.join(', ')}. No matches.`;
|
||||||
|
let winnings = 0;
|
||||||
|
let xp = 0;
|
||||||
|
|
||||||
|
if (matches > 0) {
|
||||||
|
winnings = bet * matches * 2;
|
||||||
|
resultText = `Drawn numbers: ${draws.join(', ')}. You matched ${matches} numbers and won $${winnings}!`;
|
||||||
|
xp = matches * 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('keno-result').innerText = resultText;
|
||||||
|
updateStats('keno', winnings, xp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
if (localStorage.getItem('casino-username')) {
|
if (localStorage.getItem('casino-username')) {
|
||||||
showScreen('main-menu');
|
showScreen('main-menu');
|
||||||
|
|
Loading…
Add table
Reference in a new issue