mirror of
https://github.com/milk-net/milk-net.github.io.git
synced 2025-04-19 17:43:42 -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 = [];
|
// Global variables to hold player data
|
||||||
let dealerHand = [];
|
let username = '';
|
||||||
let blackjackBet = 0;
|
let money = 1000; // Starting money
|
||||||
let dailyBonusGiven = false;
|
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() {
|
function loadUserData() {
|
||||||
const username = localStorage.getItem('casino-username');
|
const inputUsername = document.getElementById('username-input').value;
|
||||||
if (username) {
|
if (inputUsername) {
|
||||||
// Check for daily bonus
|
username = inputUsername;
|
||||||
if (isNewDay()) {
|
// Load other data if exists in localStorage
|
||||||
let balance = parseInt(localStorage.getItem('casino-money'));
|
money = parseInt(localStorage.getItem('money')) || money;
|
||||||
balance += 300; // Add daily bonus
|
level = parseInt(localStorage.getItem('level')) || level;
|
||||||
localStorage.setItem('casino-money', balance);
|
xp = parseInt(localStorage.getItem('xp')) || xp;
|
||||||
dailyBonusGiven = true;
|
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 {
|
} else {
|
||||||
alert('Please enter a username!');
|
alert('Please enter a username.');
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
updateUI();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if it's a new day for daily bonus
|
// Show a specific screen
|
||||||
function isNewDay() {
|
function showScreen(screenId) {
|
||||||
const lastLogin = localStorage.getItem('lastLogin');
|
const screens = document.querySelectorAll('.screen');
|
||||||
const today = new Date().toISOString().split('T')[0]; // Format: YYYY-MM-DD
|
screens.forEach(screen => {
|
||||||
if (!lastLogin || lastLogin !== today) {
|
screen.classList.remove('active');
|
||||||
localStorage.setItem('lastLogin', today);
|
});
|
||||||
return true;
|
const screenToShow = document.getElementById(screenId);
|
||||||
|
if (screenToShow) {
|
||||||
|
screenToShow.classList.add('active');
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export user data to a downloadable file
|
// Return to the main menu
|
||||||
function exportUserData() {
|
function returnToMenu() {
|
||||||
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
|
|
||||||
showScreen('main-menu');
|
showScreen('main-menu');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update balance after a game
|
// Export user data as JSON
|
||||||
function updateStats(game, amount, xp) {
|
function exportUserData() {
|
||||||
let money = parseInt(localStorage.getItem('casino-money'));
|
const userData = {
|
||||||
let currentXp = parseInt(localStorage.getItem('casino-xp'));
|
username: localStorage.getItem('username'),
|
||||||
let wins = parseInt(localStorage.getItem(`casino-${game}-wins`));
|
money: localStorage.getItem('money'),
|
||||||
|
level: localStorage.getItem('level'),
|
||||||
money += amount;
|
xp: localStorage.getItem('xp'),
|
||||||
currentXp += xp;
|
xpMax: localStorage.getItem('xpMax'),
|
||||||
if (amount > 0) wins += 1;
|
};
|
||||||
|
const fileContent = JSON.stringify(userData);
|
||||||
localStorage.setItem('casino-money', money);
|
const blob = new Blob([fileContent], { type: 'application/json' });
|
||||||
localStorage.setItem('casino-xp', currentXp);
|
const link = document.createElement('a');
|
||||||
localStorage.setItem(`casino-${game}-wins`, wins);
|
link.href = URL.createObjectURL(blob);
|
||||||
updateUI();
|
link.download = 'userData.json';
|
||||||
|
link.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show the main menu and update UI
|
// Handle daily rewards
|
||||||
function showScreen(screenId) {
|
function addDailyReward() {
|
||||||
document.querySelectorAll('.screen').forEach(screen => screen.classList.remove('active'));
|
const lastLogin = localStorage.getItem('lastLogin');
|
||||||
document.getElementById(screenId).classList.add('active');
|
const today = new Date().toLocaleDateString();
|
||||||
updateUI();
|
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
|
// Blackjack game logic
|
||||||
function updateUI() {
|
function startBlackjack() {
|
||||||
const username = localStorage.getItem('casino-username') || 'Player';
|
const bet = parseInt(document.getElementById('blackjack-bet').value);
|
||||||
const money = parseInt(localStorage.getItem('casino-money')) || 0;
|
if (isNaN(bet) || bet <= 0) {
|
||||||
const level = parseInt(localStorage.getItem('casino-level')) || 1;
|
alert('Please enter a valid bet amount.');
|
||||||
const xp = parseInt(localStorage.getItem('casino-xp')) || 0;
|
return;
|
||||||
const xpToNext = level * 100;
|
}
|
||||||
|
// Blackjack game logic goes here...
|
||||||
document.getElementById('player-username').innerText = username;
|
// Update balance after game logic
|
||||||
document.getElementById('player-money').innerText = money;
|
money -= bet;
|
||||||
document.getElementById('player-level').innerText = level;
|
document.getElementById('blackjack-money').textContent = money;
|
||||||
document.getElementById('player-xp').innerText = xp;
|
localStorage.setItem('money', money);
|
||||||
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;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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