This commit is contained in:
Robert
2025-04-08 14:00:54 +00:00
committed by GitHub
parent 70035ce29a
commit c1ccb13890
5 changed files with 126 additions and 28 deletions
@@ -0,0 +1,69 @@
let wins = parseInt(localStorage.getItem("wins")) || 0;
let losses = parseInt(localStorage.getItem("losses")) || 0;
const choices = document.querySelectorAll(".choice");
const msg = document.querySelector("#msg");
const winsPara = document.querySelector("#wins");
const lossesPara = document.querySelector("#losses");
// Initialize the UI with saved values
winsPara.innerText = wins;
lossesPara.innerText = losses;
const genCompChoice = () => {
const options = ["rock", "paper", "scissors"];
const randIdx = Math.floor(Math.random() * 3);
return options[randIdx];
};
const drawGame = () => {
msg.innerText = "Game was Draw. Play again.";
msg.style.backgroundColor = "#081b31";
};
const showWinner = (userWin, userChoice, compChoice) => {
if (userWin) {
wins++;
localStorage.setItem("wins", wins); // Save wins to localStorage
winsPara.innerText = wins;
msg.innerText = `You win! Your ${userChoice} beats ${compChoice}`;
msg.style.backgroundColor = "green";
} else {
losses++;
localStorage.setItem("losses", losses); // Save losses to localStorage
lossesPara.innerText = losses;
msg.innerText = `You lost. ${compChoice} beats your ${userChoice}`;
msg.style.backgroundColor = "red";
}
};
const playGame = (userChoice) => {
//Generate computer choice
const compChoice = genCompChoice();
if (userChoice === compChoice) {
//Draw Game
drawGame();
} else {
let userWin = true;
if (userChoice === "rock") {
//scissors, paper
userWin = compChoice === "paper" ? false : true;
} else if (userChoice === "paper") {
//rock, scissors
userWin = compChoice === "scissors" ? false : true;
} else {
//rock, paper
userWin = compChoice === "rock" ? false : true;
}
showWinner(userWin, userChoice, compChoice);
}
};
choices.forEach((choice) => {
choice.addEventListener("click", () => {
const userChoice = choice.getAttribute("id");
playGame(userChoice);
});
});
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

+1
View File
@@ -206,6 +206,7 @@ h1 {
font-size: 3rem; font-size: 3rem;
text-transform: uppercase; text-transform: uppercase;
animation: glow 1.5s infinite alternate; animation: glow 1.5s infinite alternate;
text-shadow: 0 0 10px #00ff00, 0 0 20px #00ff00, 0 0 30px #00ff00;
} }
@keyframes glow { @keyframes glow {
+53 -26
View File
@@ -8,6 +8,59 @@
<link rel="stylesheet" href="/index.css"> <link rel="stylesheet" href="/index.css">
<link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@700&family=Press+Start+2P&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@700&family=Press+Start+2P&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css" integrity="sha512-z3gLpd7yknf1YoNbCzqRKc4qyor8gaKU1qmn+CShxbuBusANI9QpRohGBreCFkKxLhei6S9CQXFEbbKuqLg0DA==" crossorigin="anonymous" referrerpolicy="no-referrer"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css" integrity="sha512-z3gLpd7yknf1YoNbCzqRKc4qyor8gaKU1qmn+CShxbuBusANI9QpRohGBreCFkKxLhei6S9CQXFEbbKuqLg0DA==" crossorigin="anonymous" referrerpolicy="no-referrer">
<style>
body {
background-color: #282c34;
color: #ffffff;
font-family: 'Orbitron', sans-serif;
text-align: center;
margin: 0;
padding: 0;
}
h1 {
font-size: 3rem;
margin-top: 20px;
text-shadow: 0 0 10px #00ff00, 0 0 20px #00ff00, 0 0 30px #00ff00;
}
.button-container {
margin-top: 50px;
}
.button {
background-color: #61dafb;
color: #282c34;
border: none;
border-radius: 5px;
padding: 15px 30px;
font-size: 1.2rem;
cursor: pointer;
margin: 10px;
transition: background-color 0.3s;
}
.button:hover {
background-color: #21a1f1;
}
.top-left-button {
position: absolute;
top: 10px;
left: 10px;
width: 60px;
height: 60px;
background: url('hihihi.jpeg') no-repeat center center;
background-size: cover;
border: none;
border-radius: 8px;
cursor: pointer;
}
.light-mode .top-left-button {
filter: invert(1);
}
</style>
</head> </head>
<body> <body>
<h1>Moon Gaming</h1> <h1>Moon Gaming</h1>
@@ -38,32 +91,6 @@
return null; return null;
} }
// Apply dark or light mode based on cookie
function applyDarkMode(enabled) {
if (enabled) {
document.body.style.setProperty('--background-color', 'var(--background-color-dark)');
document.body.style.setProperty('--text-color', 'var(--text-color-dark)');
document.body.style.setProperty('--button-bg', 'var(--button-bg-dark)');
document.body.style.setProperty('--button-hover-bg', 'var(--button-hover-bg-dark)');
document.body.style.setProperty('--button-hover-text', 'var(--button-hover-text-dark)');
} else {
document.body.style.setProperty('--background-color', 'var(--background-color-light)');
document.body.style.setProperty('--text-color', 'var(--text-color-light)');
document.body.style.setProperty('--button-bg', 'var(--button-bg-light)');
document.body.style.setProperty('--button-hover-bg', 'var(--button-hover-bg-light)');
document.body.style.setProperty('--button-hover-text', 'var(--button-hover-text-light)');
}
}
// Ensure dark mode is the default
if (getCookie('darkMode') === null) {
setCookie('darkMode', 'true', 30); // Default to dark mode
}
// Apply saved mode on load
const darkModeEnabled = getCookie('darkMode') === 'true';
applyDarkMode(darkModeEnabled);
// Clock Functionality // Clock Functionality
function updateClock() { function updateClock() {
const now = new Date(); const now = new Date();
+3 -2
View File
@@ -137,10 +137,10 @@
return null; return null;
} }
// Dark Mode Toggle // Remove the toggle button from other pages
const toggleDarkModeButton = document.getElementById('toggleDarkMode'); const toggleDarkModeButton = document.getElementById('toggleDarkMode');
const darkModeEnabled = getCookie('darkMode') === 'true';
// Ensure this button is the only one controlling dark mode
function applyDarkMode(enabled) { function applyDarkMode(enabled) {
if (enabled) { if (enabled) {
document.body.style.setProperty('--background-color', '#121212'); document.body.style.setProperty('--background-color', '#121212');
@@ -162,6 +162,7 @@
}); });
// Apply saved dark mode preference on load // Apply saved dark mode preference on load
const darkModeEnabled = getCookie('darkMode') === 'true';
applyDarkMode(darkModeEnabled); applyDarkMode(darkModeEnabled);
// Clear Cookies Button // Clear Cookies Button