mirror of
https://github.com/milk-net/milk-net.github.io.git
synced 2025-04-19 05:33:40 -05:00
Update script.js
This commit is contained in:
parent
53f980a4f0
commit
0311f5cd2e
1 changed files with 189 additions and 115 deletions
|
@ -1,132 +1,206 @@
|
|||
let playerHand = [];
|
||||
let dealerHand = [];
|
||||
let blackjackBet = 0;
|
||||
let dailyBonusGiven = false;
|
||||
// Global variables to hold player data
|
||||
let username = '';
|
||||
let money = 1000; // Starting money
|
||||
let level = 1;
|
||||
let xp = 0;
|
||||
let xpMax = 100;
|
||||
|
||||
// Load user data from localStorage or set default values
|
||||
// Load user data from localStorage (if any)
|
||||
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;
|
||||
}
|
||||
const inputUsername = document.getElementById('username-input').value;
|
||||
if (inputUsername) {
|
||||
username = inputUsername;
|
||||
// Load other data if exists in localStorage
|
||||
money = parseInt(localStorage.getItem('money')) || money;
|
||||
level = parseInt(localStorage.getItem('level')) || level;
|
||||
xp = parseInt(localStorage.getItem('xp')) || xp;
|
||||
xpMax = parseInt(localStorage.getItem('xpMax')) || xpMax;
|
||||
|
||||
// Set the player data on the main menu
|
||||
document.getElementById('player-username').textContent = username;
|
||||
document.getElementById('player-money').textContent = money;
|
||||
document.getElementById('player-level').textContent = level;
|
||||
document.getElementById('player-xp').textContent = xp;
|
||||
document.getElementById('player-xp-max').textContent = xpMax;
|
||||
document.getElementById('xp-progress').style.width = (xp / xpMax) * 100 + '%';
|
||||
|
||||
// Save data to localStorage
|
||||
localStorage.setItem('username', username);
|
||||
localStorage.setItem('money', money);
|
||||
localStorage.setItem('level', level);
|
||||
localStorage.setItem('xp', xp);
|
||||
localStorage.setItem('xpMax', xpMax);
|
||||
|
||||
// Show the main menu screen
|
||||
showScreen('main-menu');
|
||||
} else {
|
||||
alert('Please enter a username!');
|
||||
return;
|
||||
alert('Please enter a username.');
|
||||
}
|
||||
updateUI();
|
||||
}
|
||||
|
||||
// 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;
|
||||
// Show a specific screen
|
||||
function showScreen(screenId) {
|
||||
const screens = document.querySelectorAll('.screen');
|
||||
screens.forEach(screen => {
|
||||
screen.classList.remove('active');
|
||||
});
|
||||
const screenToShow = document.getElementById(screenId);
|
||||
if (screenToShow) {
|
||||
screenToShow.classList.add('active');
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
// Start the game, setting username and showing the main menu
|
||||
function startGame() {
|
||||
const usernameInput = document.getElementById('username-input').value.trim();
|
||||
|
||||
if (usernameInput === "") {
|
||||
alert("Please enter a valid username.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the username and store it in localStorage
|
||||
setUsername(usernameInput);
|
||||
|
||||
// Show the main menu after setting the username
|
||||
// Return to the main menu
|
||||
function returnToMenu() {
|
||||
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'));
|
||||
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();
|
||||
// Export user data as JSON
|
||||
function exportUserData() {
|
||||
const userData = {
|
||||
username: localStorage.getItem('username'),
|
||||
money: localStorage.getItem('money'),
|
||||
level: localStorage.getItem('level'),
|
||||
xp: localStorage.getItem('xp'),
|
||||
xpMax: localStorage.getItem('xpMax'),
|
||||
};
|
||||
const fileContent = JSON.stringify(userData);
|
||||
const blob = new Blob([fileContent], { type: 'application/json' });
|
||||
const link = document.createElement('a');
|
||||
link.href = URL.createObjectURL(blob);
|
||||
link.download = 'userData.json';
|
||||
link.click();
|
||||
}
|
||||
|
||||
// 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();
|
||||
// Handle daily rewards
|
||||
function addDailyReward() {
|
||||
const lastLogin = localStorage.getItem('lastLogin');
|
||||
const today = new Date().toLocaleDateString();
|
||||
if (lastLogin !== today) {
|
||||
money += 300; // Add $300 as a daily reward
|
||||
localStorage.setItem('lastLogin', today);
|
||||
alert('You have received your daily reward of $300!');
|
||||
}
|
||||
document.getElementById('player-money').textContent = money;
|
||||
localStorage.setItem('money', money);
|
||||
}
|
||||
|
||||
// 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 logic
|
||||
function startBlackjack() {
|
||||
const bet = parseInt(document.getElementById('blackjack-bet').value);
|
||||
if (isNaN(bet) || bet <= 0) {
|
||||
alert('Please enter a valid bet amount.');
|
||||
return;
|
||||
}
|
||||
// Blackjack game logic goes here...
|
||||
// Update balance after game logic
|
||||
money -= bet;
|
||||
document.getElementById('blackjack-money').textContent = money;
|
||||
localStorage.setItem('money', money);
|
||||
}
|
||||
|
||||
// Slots game logic
|
||||
function playSlots() {
|
||||
const bet = parseInt(document.getElementById('slots-bet').value);
|
||||
if (isNaN(bet) || bet <= 0) {
|
||||
alert('Please enter a valid bet amount.');
|
||||
return;
|
||||
}
|
||||
// Simulate a slot machine spin
|
||||
const results = ['🍒', '🍉', '🍇', '🍓', '🍊'];
|
||||
const reel1 = results[Math.floor(Math.random() * results.length)];
|
||||
const reel2 = results[Math.floor(Math.random() * results.length)];
|
||||
const reel3 = results[Math.floor(Math.random() * results.length)];
|
||||
|
||||
document.getElementById('slots-reels').innerHTML = `<span class="reel">${reel1}</span><span class="reel">${reel2}</span><span class="reel">${reel3}</span>`;
|
||||
// Logic for checking winning and updating balance goes here
|
||||
money -= bet;
|
||||
document.getElementById('slots-money').textContent = money;
|
||||
localStorage.setItem('money', money);
|
||||
}
|
||||
|
||||
// Roulette game logic
|
||||
function playRoulette() {
|
||||
const bet = parseInt(document.getElementById('roulette-bet').value);
|
||||
if (isNaN(bet) || bet <= 0) {
|
||||
alert('Please enter a valid bet amount.');
|
||||
return;
|
||||
}
|
||||
const choice = document.getElementById('roulette-choice').value;
|
||||
const result = Math.floor(Math.random() * 37); // 0-36 for roulette numbers
|
||||
const colors = ['red', 'black', 'green'];
|
||||
const color = result === 0 ? 'green' : (result % 2 === 0 ? 'black' : 'red');
|
||||
|
||||
let message = `Result: ${result} (${color})`;
|
||||
if ((choice === 'red' && color === 'red') || (choice === 'black' && color === 'black') || (choice === 'green' && result === 0)) {
|
||||
message += ' - You win!';
|
||||
money += bet;
|
||||
} else {
|
||||
message += ' - You lose.';
|
||||
money -= bet;
|
||||
}
|
||||
document.getElementById('roulette-result').textContent = message;
|
||||
document.getElementById('roulette-money').textContent = money;
|
||||
localStorage.setItem('money', money);
|
||||
}
|
||||
|
||||
// Horse Betting game logic
|
||||
function placeHorseBet() {
|
||||
const bet = parseInt(document.getElementById('horse-bet').value);
|
||||
if (isNaN(bet) || bet <= 0) {
|
||||
alert('Please enter a valid bet amount.');
|
||||
return;
|
||||
}
|
||||
// Simulate the horse race (random outcome)
|
||||
const winner = Math.floor(Math.random() * 4) + 1; // 1 to 4 horses
|
||||
const message = `Horse ${winner} wins!`;
|
||||
|
||||
if (winner === 1) { // Let's assume betting on Horse 1 wins
|
||||
message += ' - You win!';
|
||||
money += bet;
|
||||
} else {
|
||||
message += ' - You lose.';
|
||||
money -= bet;
|
||||
}
|
||||
|
||||
document.getElementById('horse-result').textContent = message;
|
||||
document.getElementById('horse-money').textContent = money;
|
||||
localStorage.setItem('money', money);
|
||||
}
|
||||
|
||||
// Coin Flip game logic
|
||||
function flipCoin() {
|
||||
const bet = parseInt(document.getElementById('coinflip-bet').value);
|
||||
if (isNaN(bet) || bet <= 0) {
|
||||
alert('Please enter a valid bet amount.');
|
||||
return;
|
||||
}
|
||||
const result = Math.random() > 0.5 ? 'Heads' : 'Tails';
|
||||
document.getElementById('coinflip-result').textContent = `Result: ${result}`;
|
||||
// Update balance after coin flip outcome
|
||||
money -= bet;
|
||||
document.getElementById('coinflip-money').textContent = money;
|
||||
localStorage.setItem('money', money);
|
||||
}
|
||||
|
||||
// Keno game logic
|
||||
function playKeno() {
|
||||
const bet = parseInt(document.getElementById('keno-bet').value);
|
||||
if (isNaN(bet) || bet <= 0) {
|
||||
alert('Please enter a valid bet amount.');
|
||||
return;
|
||||
}
|
||||
// Keno logic (random number selection)
|
||||
const numbers = [];
|
||||
for (let i = 0; i < 5; i++) {
|
||||
numbers.push(Math.floor(Math.random() * 80) + 1); // 1 to 80
|
||||
}
|
||||
document.getElementById('keno-result').textContent = `Selected Numbers: ${numbers.join(', ')}`;
|
||||
// Update balance based on winnings (example)
|
||||
money -= bet;
|
||||
document.getElementById('keno-money').textContent = money;
|
||||
localStorage.setItem('money', money);
|
||||
}
|
||||
|
||||
// Add daily reward if applicable
|
||||
addDailyReward();
|
||||
|
|
Loading…
Add table
Reference in a new issue