<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Rock Paper…
- User
<h1>Rock Paper Scissors</h1> <div class="choices"> <div class="choice" data-choice="rock">✊ Rock</div> <div class="choice" data-choice="paper">✋ Paper</div> <div class="choice" data-choice="scissors">✌️ Scissors</div> </div> <div class="result" id="result">Make your move!</div> <div class="score" id="score"> Player Score: <span id="player-score">0</span> | Computer Score: <span id="computer-score">0</span> </div> <button class="reset-btn" id="reset-btn">Reset Game</button> <script> // JavaScript code const choices = document.querySelectorAll('.choice'); const resultDiv = document.getElementById('result'); const playerScoreSpan = document.getElementById('player-score'); const computerScoreSpan = document.getElementById('computer-score'); const resetBtn = document.getElementById('reset-btn'); const choicesArray = ['rock', 'paper', 'scissors']; let playerScore = 0; let computerScore = 0; choices.forEach(choice => { choice.addEventListener('click', () => { const playerChoice = choice.getAttribute('data-choice'); const computerChoice = getComputerChoice(); const result = determineWinner(playerChoice, computerChoice); updateScore(result); displayResult(playerChoice, computerChoice, result); }); }); resetBtn.addEventListener('click', resetGame); function getComputerChoice() { return choicesArray[Math.floor(Math.random() * 3)]; } function determineWinner(player, computer) { if (player === computer) { return 'It\'s a tie!'; } else if ( (player === 'rock' && computer === 'scissors') || (player === 'paper' && computer === 'rock') || (player === 'scissors' && computer === 'paper') ) { return 'You win!'; } else { return 'You lose!'; } } function updateScore(result) { if (result === 'You win!') { playerScore++; playerScoreSpan.textContent = playerScore; } else if (result === 'You lose!') { computerScore++; computerScoreSpan.textContent = computerScore; } } function displayResult(playerChoice, computerChoice, result) { resultDiv.innerHTML = ` You chose <strong>${capitalize(playerChoice)}</strong>.<br> The computer chose <strong>${capitalize(computerChoice)}</strong>.<br><br> <strong>${result}</strong> `; } function capitalize(word) { return word.charAt(0).toUpperCase() + word.slice(1); } function resetGame() { playerScore = 0; computerScore = 0; playerScoreSpan.textContent = playerScore; computerScoreSpan.textContent = computerScore; resultDiv.textContent = 'Make your move!'; } </script> - Assistant
Certainly! I've updated your Rock Paper Scissors game to have a more modern look with animations, vibrant colors, and responsive design. Here's the updated code:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Rock Paper Scissors</title> <!-- Link to Google Fonts --> <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet"> <style> /* CSS styles */ body { font-family: 'Poppins', sans-serif; text-align: center; margin: 0; padding: 0; background: linear-gradient(135deg, #f6d365 0%, #fda085 100%); min-height: 100vh; display: flex; flex-direction: column; justify-content: center; align-items: center; } h1 { color: #fff; font-size: 3em; margin-bottom: 20px; text-shadow: 2px 2px 4px rgba(0,0,0,0.3); } .choices { display: flex; gap: 20px; margin-bottom: 30px; flex-wrap: wrap; justify-content: center; } .choice { cursor: pointer; font-size: 1.2em; padding: 15px 25px; border: none; border-radius: 50px; background: #fff; color: #333; box-shadow: 0 8px 15px rgba(0,0,0,0.1); transition: all 0.3s ease; position: relative; overflow: hidden; } .choice::before { content: ''; position: absolute; left: -50%; top: 0; width: 0; height: 100%; background: rgba(255,255,255,0.3); transform: skewX(45deg); transition: all 0.5s; } .choice:hover { transform: translateY(-5px); background: #f1f1f1; box-shadow: 0 15px 20px rgba(0,0,0,0.2); } .choice:hover::before { width: 200%; left: -50%; } .result { font-size: 1.5em; margin-top: 20px; color: #fff; text-shadow: 1px 1px 2px rgba(0,0,0,0.2); animation: fadeIn 0.5s; } .score { margin-top: 10px; font-size: 1.2em; color: #fff; text-shadow: 1px 1px 2px rgba(0,0,0,0.2); } .score span { font-weight: bold; } .reset-btn { margin-top: 30px; padding: 12px 24px; font-size: 1em; cursor: pointer; border: none; background-color: #ff7675; color: #fff; border-radius: 50px; box-shadow: 0 8px 15px rgba(0,0,0,0.1); transition: all 0.3s ease; } .reset-btn:hover { background-color: #d63031; box-shadow: 0 15px 20px rgba(0,0,0,0.2); transform: translateY(-5px); } @keyframes fadeIn { from {opacity: 0;} to {opacity:1;} } </style> </head> <body> <h1>Rock Paper Scissors</h1> <div class="choices"> <button class="choice" data-choice="rock">✊ Rock</button> <button class="choice" data-choice="paper">✋ Paper</button> <button class="choice" data-choice="scissors">✌️ Scissors</button> </div> <div class="result" id="result">Make your move!</div> <div class="score" id="score"> Player Score: <span id="player-score">0</span> | Computer Score: <span id="computer-score">0</span> </div> <button class="reset-btn" id="reset-btn">Reset Game</button> <script> // JavaScript code const choices = document.querySelectorAll('.choice'); const resultDiv = document.getElementById('result'); const playerScoreSpan = document.getElementById('player-score'); const computerScoreSpan = document.getElementById('computer-score'); const resetBtn = document.getElementById('reset-btn'); const choicesArray = ['rock', 'paper', 'scissors']; let playerScore = 0; let computerScore = 0; choices.forEach(choice => { choice.addEventListener('click', () => { const playerChoice = choice.getAttribute('data-choice'); const computerChoice = getComputerChoice(); const result = determineWinner(playerChoice, computerChoice); updateScore(result); displayResult(playerChoice, computerChoice, result); }); }); resetBtn.addEventListener('click', resetGame); function getComputerChoice() { return choicesArray[Math.floor(Math.random() * 3)]; } function determineWinner(player, computer) { if (player === computer) { return 'It\'s a tie!'; } else if ( (player === 'rock' && computer === 'scissors') || (player === 'paper' && computer === 'rock') || (player === 'scissors' && computer === 'paper') ) { return 'You win!'; } else { return 'You lose!'; } } function updateScore(result) { if (result === 'You win!') { playerScore++; playerScoreSpan.textContent = playerScore; } else if (result === 'You lose!') { computerScore++; computerScoreSpan.textContent = computerScore; } } function displayResult(playerChoice, computerChoice, result) { resultDiv.innerHTML = ` You chose <strong>${capitalize(playerChoice)}</strong>.<br> The computer chose <strong>${capitalize(computerChoice)}</strong>.<br><br> <strong>${result}</strong> `; resultDiv.style.animation = 'none'; void resultDiv.offsetWidth; // Trigger reflow to restart animation resultDiv.style.animation = 'fadeIn 0.5s'; } function capitalize(word) { return word.charAt(0).toUpperCase() + word.slice(1); } function resetGame() { playerScore = 0; computerScore = 0; playerScoreSpan.textContent = playerScore; computerScoreSpan.textContent = computerScore; resultDiv.textContent = 'Make your move!'; } </script> </body> </html>Highlights of the Updates:
-
Modern Font: Added a link to Google Fonts to use Poppins, a clean and modern sans-serif font.
-
Gradient Background: Applied a vibrant linear gradient background to the body for a fresh and engaging look.
-
Responsive Design: Utilized Flexbox for the choices container to ensure the layout is flexible and adapts to different screen sizes.
-
Styled Buttons: Changed the choices from
divelements tobuttonelements for better semantics and accessibility. Styled them with modern button designs, including hover effects and animations. -
Hover Effects and Animations: Added transitions and animations to buttons and the reset button to enhance interactivity. Buttons animate on hover, providing a modern feel.
-
Result Animation: Implemented a fade-in animation for the result text whenever a new result is displayed.
-
Shadows and Rounded Corners: Applied box shadows and border-radius to elements for a modern, soft look.
-
Adjusted Text Styling: Enhanced the headings and text with shadows and adjusted font sizes for better readability.
Instructions to View the Updated Game:
-
Copy the Code: Copy the entire code above and paste it into a new file with the
.htmlextension (e.g.,rock-paper-scissors.html). -
Open in Browser: Open the file in a modern web browser like Chrome, Firefox, or Edge to see the updated game in action.
Feel Free to Customize Further:
-
Change Colors: You can adjust the colors of the background, buttons, and texts by modifying the CSS.
-
Add More Animations: Explore adding more CSS animations to elements to make the game even more interactive.
-
Enhance Accessibility: Consider adding ARIA labels or adjusting contrast ratios for better accessibility.
Let me know if you have any questions or need further modifications!
-