Skip to content

Commit

Permalink
files added
Browse files Browse the repository at this point in the history
  • Loading branch information
AliAlmasi committed Nov 25, 2023
0 parents commit 382d03c
Show file tree
Hide file tree
Showing 2 changed files with 273 additions and 0 deletions.
182 changes: 182 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>🪨📄✂️</title>
<script src="./index.js" defer></script>
<style>
*,
*::before,
*::after {
margin: 0;
padding: 0;
box-sizing: border-box;
user-select: none;
}

html {
font-size: 62.5%;
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue",
sans-serif;
}

body {
height: 100vh;
background: linear-gradient(180deg, #131313 5%, #232323);
color: #f0f0f0;
display: flex;
justify-content: center;
align-items: center;
}

main {
position: relative;
height: 60%;
width: 50%;
background-color: #333;
padding: 2rem;
font-size: 2rem;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
gap: 1rem;
border-radius: 1.4rem;
border: #444 3px solid;
}

.buttons {
display: flex;
justify-content: center;
gap: 3rem;
margin: 2rem 0;
}

.button {
cursor: pointer;
background-color: #444;
text-align: center;
text-transform: uppercase;
padding: 0.6rem 1.2rem;
border-radius: 0.3rem;
letter-spacing: 2px;
font-family: monospace;
transition: background-color 0.1s, color 0.1s, box-shadow 0.1s;
box-shadow: 0 5px 5px 0 #252525;
}

.button:hover {
background-color: #555;
}

.button:active {
background-color: #222;
color: #888;
box-shadow: none;
}

.disabled {
cursor: wait;
background-color: #222;
color: #333;
box-shadow: none;
}

.disabled:hover {
background-color: #222;
color: #333;
}

.footer {
color: #aaa;
transition: color 0.1s;
}

.footer:hover {
color: #f0f0f0;
}

#cheat {
background-color: #aaa;
position: absolute;
top: 1rem;
display: none;
font-weight: 900;
color: darkred;
padding: 0.2rem 0.8rem;
}
</style>
</head>
<body>
<main>
<h1 class="text">Select one:</h1>
<span id="cheat">CHEAT: true</span>
<div class="buttons">
<span class="button" id="button-rock">🪨 Rock</span>
<span class="button" id="button-paper">📄 Paper</span>
<span class="button" id="button-scissors">✂️ Scissors</span>
</div>
<p id="result" class="footer">You can play infinitively.</p>
<p id="chose" class="footer">&nbsp;</p>
</main>
<a
href="https://github.al1almasi.ir"
class="github-corner"
aria-label="View source on GitHub"
><svg
width="80"
height="80"
viewBox="0 0 250 250"
style="
fill: #f0f0f0;
color: #131313;
position: absolute;
top: 0;
border: 0;
right: 0;
"
aria-hidden="true"
>
<path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
<path
d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
fill="currentColor"
style="transform-origin: 130px 106px"
class="octo-arm"
></path>
<path
d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
fill="currentColor"
class="octo-body"
></path></svg></a
><style>
.github-corner:hover .octo-arm {
animation: octocat-wave 560ms ease-in-out;
}
@keyframes octocat-wave {
0%,
100% {
transform: rotate(0);
}
20%,
60% {
transform: rotate(-25deg);
}
40%,
80% {
transform: rotate(10deg);
}
}
@media (max-width: 500px) {
.github-corner:hover .octo-arm {
animation: none;
}
.github-corner .octo-arm {
animation: octocat-wave 560ms ease-in-out;
}
}
</style>
</body>
</html>
91 changes: 91 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
"use strict";

let computerChoice;
let userChoice;
let userScore = 0;
let computerScore = 0;
const text = document.querySelector(`.text`);
const buttons = document.querySelectorAll(`.button`);
const result = document.querySelector(`#result`);
let cheatStatus = false;

function cheatSwitch() {
if (!cheatStatus) {
cheatStatus = true;
} else {
cheatStatus = false;
}
cheatStatus &&
console.warn(
"Oh! Hello there, fellow cheater. 🙂\nYou can use this function to toggle the cheat and see the computer's choice, here in the console.\nTo disable the cheat, use this function again."
);
cheatStatus &&
console.error(`CHEAT: Computer has chose ${translate(computerChoice)}`);
document.querySelector(`#cheat`).style.display = cheatStatus
? "block"
: "none";

return cheatStatus;
}

function loadComputerChoice() {
computerChoice = Math.floor(Math.random() * 3);
}

function translate(input) {
switch (input) {
case 0:
return `Rock`;
break;
case 1:
return `Paper`;
break;
case 2:
return `Scissors`;
break;
default:
return `Error`;
break;
}
}

loadComputerChoice();

for (let i = 0; i < buttons.length; i++) {
buttons[i].addEventListener("click", () => {
userChoice = i;
if (computerChoice === userChoice) {
text.innerHTML = `<span style="color: green">Won!</span>`;
userScore++;
} else {
text.innerHTML = `<span style="color: red">Lost.</span>`;
computerScore++;
}
result.textContent = `Computer: ${computerScore} | User: ${userScore}.`;
document.getElementById(
"chose"
).innerHTML = `Computer chose <em>${translate(
computerChoice
)}</em>, user chose <em>${translate(userChoice)}</em>.`;
loadComputerChoice();
buttons.forEach((button) => {
button.classList.add("disabled");
});
console.info(`Computer: ${computerScore} | User: ${userScore}.`);
console.log(
`Computer: ${translate(computerChoice)} | User: ${translate(
userChoice
)}.\n`
);
document.querySelector("body").style.cursor = "wait";
setTimeout(() => {
buttons.forEach((button) => {
button.classList.remove("disabled");
document.querySelector("body").style.cursor = "";
});
text.textContent = "Choose again:";
}, 1500);
cheatStatus &&
console.warn(`CHEAT: Computer has chose ${translate(computerChoice)}`);
});
}

0 comments on commit 382d03c

Please sign in to comment.