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
87b0f7c3ba
commit
fde4985a89
1 changed files with 231 additions and 59 deletions
|
@ -1,71 +1,78 @@
|
|||
let playerHand = [];
|
||||
let dealerHand = [];
|
||||
let blackjackBet = 0;
|
||||
let dailyBonusGiven = false;
|
||||
|
||||
function startGame() {
|
||||
const username = document.getElementById('username-input').value.trim();
|
||||
if (!username) {
|
||||
// Load user data from localStorage or set default values
|
||||
function loadUserData() {
|
||||
const username = localStorage.getItem('casino-username');
|
||||
if (username) {
|
||||
// Check for daily bonus
|
||||
if (isNewDay()) {
|
||||
let balance = parseInt(localStorage.getItem('casino-money'));
|
||||
balance += 300; // Add daily bonus
|
||||
localStorage.setItem('casino-money', balance);
|
||||
dailyBonusGiven = true;
|
||||
}
|
||||
} else {
|
||||
alert('Please enter a username!');
|
||||
return;
|
||||
}
|
||||
localStorage.setItem('casino-username', username);
|
||||
localStorage.setItem('casino-money', 1000);
|
||||
localStorage.setItem('casino-level', 1);
|
||||
localStorage.setItem('casino-xp', 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');
|
||||
updateUI();
|
||||
}
|
||||
|
||||
function showScreen(screenId) {
|
||||
document.querySelectorAll('.screen').forEach(screen => screen.classList.remove('active'));
|
||||
document.getElementById(screenId).classList.add('active');
|
||||
// Check if it's a new day for daily bonus
|
||||
function isNewDay() {
|
||||
const lastLogin = localStorage.getItem('lastLogin');
|
||||
const today = new Date().toISOString().split('T')[0]; // Format: YYYY-MM-DD
|
||||
if (!lastLogin || lastLogin !== today) {
|
||||
localStorage.setItem('lastLogin', today);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Export user data to a downloadable file
|
||||
function exportUserData() {
|
||||
const dataStr = JSON.stringify(localStorage);
|
||||
const blob = new Blob([dataStr], { type: 'application/json' });
|
||||
const link = document.createElement('a');
|
||||
link.href = URL.createObjectURL(blob);
|
||||
link.download = `${localStorage.getItem('casino-username')}_data.json`;
|
||||
link.click();
|
||||
}
|
||||
|
||||
// Import user data from a file
|
||||
function importUserData(file) {
|
||||
const reader = new FileReader();
|
||||
reader.onload = function(event) {
|
||||
const importedData = JSON.parse(event.target.result);
|
||||
for (let key in importedData) {
|
||||
localStorage.setItem(key, importedData[key]);
|
||||
}
|
||||
loadUserData(); // Reload user data after import
|
||||
};
|
||||
reader.readAsText(file);
|
||||
}
|
||||
|
||||
// Save user data to localStorage
|
||||
function saveUserData() {
|
||||
const username = localStorage.getItem('casino-username');
|
||||
localStorage.setItem(username, JSON.stringify({
|
||||
money: localStorage.getItem('casino-money'),
|
||||
level: localStorage.getItem('casino-level'),
|
||||
xp: localStorage.getItem('casino-xp')
|
||||
}));
|
||||
}
|
||||
|
||||
// Set a new username for the user
|
||||
function setUsername(newUsername) {
|
||||
localStorage.setItem('casino-username', newUsername);
|
||||
saveUserData();
|
||||
updateUI();
|
||||
}
|
||||
|
||||
function updateUI() {
|
||||
const username = localStorage.getItem('casino-username') || 'Player';
|
||||
const money = parseInt(localStorage.getItem('casino-money')) || 0;
|
||||
const level = parseInt(localStorage.getItem('casino-level')) || 1;
|
||||
const xp = parseInt(localStorage.getItem('casino-xp')) || 0;
|
||||
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-money').innerText = money;
|
||||
document.getElementById('player-level').innerText = level;
|
||||
document.getElementById('player-xp').innerText = xp;
|
||||
document.getElementById('player-xp-max').innerText = xpToNext;
|
||||
document.getElementById('xp-progress').style.width = `${Math.min(100, (xp / xpToNext) * 100)}%`;
|
||||
|
||||
document.getElementById('stats-username').innerText = username;
|
||||
document.getElementById('stats-money').innerText = money;
|
||||
document.getElementById('stats-level').innerText = level;
|
||||
document.getElementById('stats-xp').innerText = xp;
|
||||
['blackjack', 'slots', 'roulette', 'horse', 'war', 'coinflip', 'crash', 'keno'].forEach(game => {
|
||||
document.getElementById(`stats-${game}-wins`).innerText = localStorage.getItem(`casino-${game}-wins`) || 0;
|
||||
});
|
||||
}
|
||||
|
||||
function returnToMenu() {
|
||||
document.querySelectorAll('p[id$="result"], p[id$="message"]').forEach(p => p.innerText = '');
|
||||
document.querySelectorAll('span#slots-reels').forEach(p => p.innerText = '- - -');
|
||||
document.getElementById('blackjack-game')?.classList.add('hidden');
|
||||
showScreen('main-menu');
|
||||
}
|
||||
|
||||
// Update balance after a game
|
||||
function updateStats(game, amount, xp) {
|
||||
let money = parseInt(localStorage.getItem('casino-money'));
|
||||
let currentXp = parseInt(localStorage.getItem('casino-xp'));
|
||||
|
@ -81,6 +88,53 @@ function updateStats(game, amount, xp) {
|
|||
updateUI();
|
||||
}
|
||||
|
||||
// Show the main menu and update UI
|
||||
function showScreen(screenId) {
|
||||
document.querySelectorAll('.screen').forEach(screen => screen.classList.remove('active'));
|
||||
document.getElementById(screenId).classList.add('active');
|
||||
updateUI();
|
||||
}
|
||||
|
||||
// Update the UI with the current player stats
|
||||
function updateUI() {
|
||||
const username = localStorage.getItem('casino-username') || 'Player';
|
||||
const money = parseInt(localStorage.getItem('casino-money')) || 0;
|
||||
const level = parseInt(localStorage.getItem('casino-level')) || 1;
|
||||
const xp = parseInt(localStorage.getItem('casino-xp')) || 0;
|
||||
const xpToNext = level * 100;
|
||||
|
||||
document.getElementById('player-username').innerText = username;
|
||||
document.getElementById('player-money').innerText = money;
|
||||
document.getElementById('player-level').innerText = level;
|
||||
document.getElementById('player-xp').innerText = xp;
|
||||
document.getElementById('player-xp-max').innerText = xpToNext;
|
||||
document.getElementById('xp-progress').style.width = `${Math.min(100, (xp / xpToNext) * 100)}%`;
|
||||
|
||||
['blackjack', 'slots', 'roulette', 'horse', 'war', 'coinflip', 'crash', 'keno'].forEach(game => {
|
||||
document.getElementById(`stats-${game}-wins`).innerText = localStorage.getItem(`casino-${game}-wins`) || 0;
|
||||
});
|
||||
}
|
||||
|
||||
// Blackjack Game
|
||||
function playBlackjack() {
|
||||
const bet = parseInt(document.getElementById('blackjack-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);
|
||||
|
||||
// Simulate game result (basic example)
|
||||
const win = Math.random() < 0.5;
|
||||
let message = win ? `You won $${bet * 2}!` : `You lost $${bet}.`;
|
||||
updateStats('blackjack', win ? bet * 2 : -bet, win ? 20 : 0);
|
||||
document.getElementById('blackjack-message').innerText = message;
|
||||
}
|
||||
|
||||
// Slots Game
|
||||
function playSlots() {
|
||||
const bet = parseInt(document.getElementById('slots-bet').value);
|
||||
|
@ -205,10 +259,128 @@ function playCrash() {
|
|||
}, 1000);
|
||||
}
|
||||
|
||||
// (Other game functions stay as they are...)
|
||||
// Horse Betting Game
|
||||
function playHorseBetting() {
|
||||
const bet = parseInt(document.getElementById('horse-bet').value);
|
||||
let money = parseInt(localStorage.getItem('casino-money'));
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
if (localStorage.getItem('casino-username')) {
|
||||
showScreen('main-menu');
|
||||
if (!bet || bet <= 0 || bet > money) {
|
||||
alert('Invalid bet amount.');
|
||||
return;
|
||||
}
|
||||
|
||||
money -= bet;
|
||||
localStorage.setItem('casino-money', money);
|
||||
|
||||
const outcome = Math.floor(Math.random() * 4) + 1; // 4 horses
|
||||
const playerHorse = document.getElementById('horse-choice').value;
|
||||
|
||||
let message = `You lost. Horse #${outcome} won.`;
|
||||
let winnings = 0;
|
||||
let xp = 0;
|
||||
|
||||
if (outcome == playerHorse) {
|
||||
winnings = bet * 3; // Win 3x bet if correct
|
||||
message = `You won $${winnings}! Horse #${outcome} won.`;
|
||||
xp = 15;
|
||||
}
|
||||
|
||||
document.getElementById('horse-message').innerText = message;
|
||||
updateStats('horse', winnings, xp);
|
||||
}
|
||||
|
||||
// Casino War Game
|
||||
function playCasinoWar() {
|
||||
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.floor(Math.random() * 13) + 1; // 1-13 (Ace to King)
|
||||
const dealerCard = Math.floor(Math.random() * 13) + 1;
|
||||
|
||||
let message = `You lost. Dealer's card (${dealerCard}) was higher.`;
|
||||
let winnings = 0;
|
||||
let xp = 0;
|
||||
|
||||
if (playerCard > dealerCard) {
|
||||
winnings = bet * 2;
|
||||
message = `You won $${winnings}! Your card (${playerCard}) was higher.`;
|
||||
xp = 10;
|
||||
}
|
||||
|
||||
document.getElementById('war-message').innerText = message;
|
||||
updateStats('war', winnings, xp);
|
||||
}
|
||||
|
||||
// Coinflip Game
|
||||
function playCoinflip() {
|
||||
const bet = parseInt(document.getElementById('coinflip-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 result = Math.random() < 0.5 ? 'heads' : 'tails';
|
||||
const playerChoice = document.getElementById('coinflip-choice').value;
|
||||
|
||||
let message = `You lost. The coin landed on ${result}.`;
|
||||
let winnings = 0;
|
||||
let xp = 0;
|
||||
|
||||
if (result === playerChoice) {
|
||||
winnings = bet * 2;
|
||||
message = `You won $${winnings}! The coin landed on ${result}.`;
|
||||
xp = 5;
|
||||
}
|
||||
|
||||
document.getElementById('coinflip-message').innerText = message;
|
||||
updateStats('coinflip', winnings, xp);
|
||||
}
|
||||
|
||||
// Keno Game
|
||||
function playKeno() {
|
||||
const bet = parseInt(document.getElementById('keno-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 drawnNumbers = Array.from({ length: 20 }, () => Math.floor(Math.random() * 80) + 1);
|
||||
const playerNumbers = Array.from(document.getElementsByClassName('keno-number')).map(num => parseInt(num.value));
|
||||
const matchedNumbers = playerNumbers.filter(num => drawnNumbers.includes(num));
|
||||
|
||||
let message = `You lost.`;
|
||||
let winnings = 0;
|
||||
let xp = 0;
|
||||
|
||||
if (matchedNumbers.length > 0) {
|
||||
winnings = bet * matchedNumbers.length;
|
||||
message = `You matched ${matchedNumbers.length} numbers: ${matchedNumbers.join(', ')}. You won $${winnings}!`;
|
||||
xp = 20;
|
||||
}
|
||||
|
||||
document.getElementById('keno-message').innerText = message;
|
||||
updateStats('keno', winnings, xp);
|
||||
}
|
||||
|
||||
// Event listener to load user data when the document is loaded
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
loadUserData(); // Load user data on page load
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue