RockPaperScissors
This commit is contained in:
104
MiniProjects/RockPaperScissors/game.html
Normal file
104
MiniProjects/RockPaperScissors/game.html
Normal file
@ -0,0 +1,104 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<style>
|
||||
body {
|
||||
background-color: grey;
|
||||
}
|
||||
|
||||
.title {
|
||||
text-align: center;
|
||||
margin-bottom: 10vh;
|
||||
text-decoration: underline;
|
||||
color: aqua;
|
||||
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
|
||||
font-size: 8ch;
|
||||
text-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
|
||||
text-transform: uppercase;
|
||||
}
|
||||
#images {
|
||||
width: fit-content;
|
||||
height: 150px;
|
||||
margin: auto;
|
||||
}
|
||||
img {
|
||||
width: 150px;
|
||||
height: 150px;
|
||||
border-radius: 50%;
|
||||
margin: 10px;
|
||||
display: inline-block;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
|
||||
transition: transform 0.3s;
|
||||
float: left;
|
||||
}
|
||||
img:hover {
|
||||
transform: scale(1.1);
|
||||
cursor: pointer;
|
||||
}
|
||||
#choises, #scores {
|
||||
width: fit-content;
|
||||
margin: 5vh auto;
|
||||
}
|
||||
h2 {
|
||||
color: aqua;
|
||||
display: inline-block;
|
||||
}
|
||||
.score {
|
||||
font-weight: bold;
|
||||
color: yellow;
|
||||
font-size: 1.2em;
|
||||
margin-left: 10px;
|
||||
margin-right: 20px;
|
||||
}
|
||||
#winner h1{
|
||||
font-size: 7ch;
|
||||
color: gold;
|
||||
text-align: center;
|
||||
font-family: 'Arial Black', sans-serif;
|
||||
text-shadow: 0 0 20px rgba(255, 223, 0, 0.8), 0 0 30px rgba(255, 165, 0, 0.6);
|
||||
animation: glow 3s ease-in-out infinite alternate;
|
||||
margin-top: 1vh;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
@keyframes glow {
|
||||
from {
|
||||
text-shadow: 0 0 20px rgba(255, 223, 0, 0.8), 0 0 30px rgba(255, 165, 0, 0.6);
|
||||
}
|
||||
to {
|
||||
text-shadow: 0 0 50px rgba(255, 223, 0, 1), 0 0 60px rgba(255, 165, 0, 1);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<body>
|
||||
<h1 class="title">Rock Paper Scissors</h1>
|
||||
<div id="images">
|
||||
<img src="rock.jpg" onclick="play('0')" alt="Rock">
|
||||
<img src="paper.jpg" onclick="play('1')" alt="Paper">
|
||||
<img src="scissors.jpg" onclick="play('2')" alt="Scissors">
|
||||
</div>
|
||||
|
||||
<div id="choises">
|
||||
<h2 id="">Your Choice:</h2>
|
||||
<h2 id="yourchoice" class="score">-</h2><br>
|
||||
<h2 id="">Computer Choice:</h2>
|
||||
<h2 id="computerchoice" class="score">-</h2>
|
||||
</div>
|
||||
|
||||
<div id="winner">
|
||||
<h1 id="winnertext"></h1>
|
||||
</div>
|
||||
|
||||
<div id="scores">
|
||||
<h2 id="">Your Score:</h2>
|
||||
<h2 id="yourscore" class="score">0</h2>
|
||||
<h2 id="">Computer Score:</h2>
|
||||
<h2 id="computerscore" class="score">0</h2>
|
||||
</div>
|
||||
|
||||
<script src="script.js"></script>
|
||||
</body>
|
||||
</html>
|
BIN
MiniProjects/RockPaperScissors/paper.jpg
Normal file
BIN
MiniProjects/RockPaperScissors/paper.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 214 KiB |
BIN
MiniProjects/RockPaperScissors/rock.jpg
Normal file
BIN
MiniProjects/RockPaperScissors/rock.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 204 KiB |
BIN
MiniProjects/RockPaperScissors/scissors.jpg
Normal file
BIN
MiniProjects/RockPaperScissors/scissors.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
68
MiniProjects/RockPaperScissors/script.js
Normal file
68
MiniProjects/RockPaperScissors/script.js
Normal file
@ -0,0 +1,68 @@
|
||||
window.onload = () =>{
|
||||
document.getElementById("yourscore").innerText = localStorage.getItem("playerScore");
|
||||
document.getElementById("computerscore").innerText = localStorage.getItem("computerScore");
|
||||
};
|
||||
|
||||
function play(choice) {
|
||||
let playerScore = localStorage.getItem("playerScore") == null ? 0 : Number(localStorage.getItem("playerScore"));
|
||||
let computerScore = Number(localStorage.getItem("computerScore")) == NaN ? 0 : Number(localStorage.getItem("computerScore"));
|
||||
choice = Number(choice)
|
||||
let num = Math.floor(Math.random() * 3);
|
||||
let computerChoice = makeittext(num);
|
||||
document.getElementById("computerchoice").innerText = computerChoice;
|
||||
document.getElementById("yourchoice").innerText = makeittext(choice);
|
||||
|
||||
if(num == choice){
|
||||
document.getElementById("winnertext").innerText = "It is a TIE!";
|
||||
}
|
||||
else if(num == 0 && choice == 1){
|
||||
document.getElementById("winnertext").innerText = "YOU WON!";
|
||||
playerScore += 1;
|
||||
}
|
||||
else if(choice == 0 && num == 1){
|
||||
document.getElementById("winnertext").innerText = "The COMPUTER WON!";
|
||||
computerScore += 1;
|
||||
}
|
||||
else if(num == 0 && choice == 2){
|
||||
document.getElementById("winnertext").innerText = "The COMPUTER WON!";
|
||||
computerScore += 1;
|
||||
}
|
||||
else if(num == 2 && choice == 0){
|
||||
document.getElementById("winnertext").innerText = "YOU WON!";
|
||||
playerScore += 1;
|
||||
}
|
||||
else if(num == 1 && choice == 2){
|
||||
document.getElementById("winnertext").innerText = "YOU WON!";
|
||||
playerScore += 1;
|
||||
}
|
||||
else if(num == 2 && choice == 1){
|
||||
document.getElementById("winnertext").innerText = "The COMPUTER WON!";
|
||||
computerScore += 1;
|
||||
}
|
||||
|
||||
document.getElementById("yourscore").innerText = playerScore;
|
||||
document.getElementById("computerscore").innerText = computerScore;
|
||||
|
||||
localStorage.setItem("playerScore", playerScore)
|
||||
localStorage.setItem("computerScore", computerScore)
|
||||
}
|
||||
|
||||
function computerChoise() {
|
||||
let num = Math.floor(Math.random() * 3);
|
||||
return makeittext(num);
|
||||
}
|
||||
function makeittext(num){
|
||||
let res = "";
|
||||
switch (num) {
|
||||
case 0:
|
||||
res = "Rock";
|
||||
break;
|
||||
case 1:
|
||||
res = "Paper";
|
||||
break;
|
||||
case 2:
|
||||
res = "Scissors";
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
Reference in New Issue
Block a user