-
Notifications
You must be signed in to change notification settings - Fork 15
rps game #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
rps game #9
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
*{ | ||
font-family: 'Source Code Pro', monospace; | ||
background-color: rgb(248, 244, 238); | ||
} | ||
.outer_container{ | ||
margin: auto; | ||
display: flex; | ||
flex-direction: column; | ||
height: 80%; | ||
width: 60%; | ||
border: 2px solid black; | ||
/* background-color: rgb(236, 228, 228); */ | ||
box-shadow: 0px 0px 10px inset ; | ||
border-radius: 20px; | ||
} | ||
.score_container{ | ||
border: 2px solid black; | ||
border-radius: 15px; | ||
box-shadow: 0px 0px 5px ; | ||
margin: 3rem; | ||
display: flex; | ||
flex-wrap: wrap; | ||
justify-content: space-around; | ||
} | ||
.status{ | ||
border: 2px solid black; | ||
margin: 3rem; | ||
display: flex; | ||
flex-wrap: wrap; | ||
justify-content: space-around; | ||
border-radius: 15px; | ||
box-shadow: 0px 0px 5px ; | ||
} | ||
.buttons_container{ | ||
border: 2px solid black; | ||
border-radius: 15px; | ||
box-shadow: 0px 0px 5px ; | ||
margin: 3rem; | ||
display: flex; | ||
flex-wrap: wrap; | ||
justify-content: space-around; | ||
|
||
} | ||
#rock ,#paper, #scissor{ | ||
padding: 20px; | ||
border-radius: 25px; | ||
background-color:#16437E; | ||
color: white; | ||
cursor: pointer; | ||
margin: 1rem; | ||
border: 2px solid white; | ||
font-size: 1.3rem; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
<link rel="preconnect" href="https://fonts.googleapis.com"> | ||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> | ||
<link href="https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap" rel="stylesheet"> | ||
<link rel="stylesheet" href="index.css"> | ||
</head> | ||
<body> | ||
<!-- outer container --> | ||
<div class="outer_container"> | ||
<!-- container showing the score --> | ||
<div class="score_container"> | ||
<h3>Your Score | ||
<div class="score" id="human"></div> | ||
</h3> | ||
<h3> Bot score | ||
<div class="score" id="bot"></div> | ||
</h3> | ||
|
||
</div> | ||
<!-- container showing the status --> | ||
<div class="status"> | ||
<h1 id="status_human"></h1> | ||
<h1 id = "status"></h1> | ||
<h1 id="status_bot"></h1> | ||
</div> | ||
<!-- container containing the buttons --> | ||
<div class="buttons_container"> | ||
<button class="btn" id = "rock">Rock</button> | ||
<button class="btn" id = "paper">Paper</button> | ||
<button class="btn" id = "scissor">Scissor</button> | ||
</div> | ||
</div> | ||
|
||
<script src="index.js"></script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
const rock = document.getElementById("rock") | ||
const paper = document.getElementById("paper") | ||
const scissor = document.getElementById("scissor") | ||
const stat = document.getElementById("status") | ||
stat.innerText = "Start" | ||
const status_human = document.getElementById("status_human") | ||
const status_bot = document.getElementById("status_bot") | ||
|
||
|
||
let human_count = 0 | ||
let bot_count = 0 | ||
const human_score = document.getElementById('human') | ||
human_score.innerText = human_count | ||
const bot_score = document.getElementById('bot') | ||
bot_score.innerText = bot_count | ||
|
||
const random_number_generator = ()=>(Math.ceil(Math.random()*3)) //random number generator | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use proper spacings. const random_number_generator = () => (Math.ceil(Math.random()*3)) |
||
const evaluator = (id)=>{ | ||
const computer_choice = random_number_generator() | ||
console.log(computer_choice) | ||
// For rock | ||
if(id===1){ | ||
if(computer_choice == 2){ | ||
status_human.innerText ="Rock" | ||
stat.innerText= "You lose" | ||
status_bot.innerText= "Paper" | ||
bot_count++ | ||
bot_score.innerText = bot_count | ||
} | ||
else if(computer_choice == 3){ | ||
status_human.innerText ="Rock" | ||
stat.innerText = "You won" | ||
status_bot.innerText= "Scissor" | ||
human_count++ | ||
human_score.innerText = human_count | ||
} | ||
else{ | ||
status_human.innerText ="Rock" | ||
stat.innerText = "Score are tied" | ||
status_bot.innerText= "Rock" | ||
} | ||
|
||
stat.remove | ||
} | ||
// For paper | ||
else if(id===2){ | ||
if(computer_choice == 1) { | ||
status_human.innerText ="Paper" | ||
stat.innerText= "You won" | ||
status_bot.innerText= "Rock" | ||
human_count++ | ||
human_score.innerText = human_count | ||
} | ||
|
||
else if(computer_choice == 3){ | ||
status_human.innerText ="Paper" | ||
stat.innerText = "You Lose" | ||
status_bot.innerText= "Scissor" | ||
bot_count++ | ||
bot_score.innerText = bot_count | ||
} | ||
else{ | ||
status_human.innerText ="Paper" | ||
stat.innerText = "Score are tied" | ||
status_bot.innerText= "paper" | ||
} | ||
|
||
stat.remove | ||
} | ||
// For Scissors | ||
else{ | ||
if(computer_choice == 1) { | ||
status_human.innerText ="Scissor" | ||
stat.innerText= "You Lose" | ||
status_bot.innerText= "Rock" | ||
bot_count++ | ||
bot_score.innerText = bot_count | ||
} | ||
|
||
else if(computer_choice == 2){ | ||
status_human.innerText ="Scissor" | ||
stat.innerText = "You Won" | ||
status_bot.innerText= "Paper" | ||
human_count++ | ||
human_score.innerText = human_count | ||
} | ||
else{ | ||
status_human.innerText ="Scissor" | ||
stat.innerText = "Score are tied" | ||
status_bot.innerText= "Scissor" | ||
} | ||
|
||
stat.remove | ||
} | ||
Comment on lines
+22
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. optimize this code using ternary operator, avoid using multiple if..else and repeating statements, |
||
} | ||
rock.addEventListener('click',()=>{ | ||
evaluator(1) | ||
}) | ||
paper.addEventListener('click',()=>{ | ||
evaluator(2) | ||
|
||
}) | ||
scissor.addEventListener('click',()=>{ | ||
evaluator(3) | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dont push unnecessary spaces. always check the code before updating.