mirror of
https://github.com/MrEidam/PetPet.git
synced 2026-04-17 15:43:31 +00:00
Rock Paper Scissors + finally design of the buttons in main PetPet page + MY OWN DOMAIN https://petpet.mreidam.com
This commit is contained in:
BIN
Games/RockPaperScissors/0paper.png
Normal file
BIN
Games/RockPaperScissors/0paper.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 275 KiB |
BIN
Games/RockPaperScissors/0rock.png
Normal file
BIN
Games/RockPaperScissors/0rock.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 122 KiB |
BIN
Games/RockPaperScissors/0scissors.png
Normal file
BIN
Games/RockPaperScissors/0scissors.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 218 KiB |
@@ -10,20 +10,31 @@ window.onload = () => {
|
||||
for(let i=0;i<3;i++){
|
||||
let choice = document.createElement("img");
|
||||
choice.id = choices[i];
|
||||
choice.src = `${choices[i]}.png`;
|
||||
choice.src = `0${choices[i]}.png`;
|
||||
choice.setAttribute("draggable", "false");
|
||||
choice.addEventListener("click", selectChoice);
|
||||
choice.addEventListener("click", function() {
|
||||
selectChoice(false, this.id);
|
||||
});
|
||||
document.getElementById("choices").append(choice);
|
||||
}
|
||||
}
|
||||
|
||||
function selectChoice(){
|
||||
you = this.id;
|
||||
document.getElementById("your-choice").src = `${you}.png`;
|
||||
|
||||
opponent = choices[Math.floor(Math.random()*3)];
|
||||
document.getElementById("opponent-choice").src = `${opponent}.png`;
|
||||
document.addEventListener('keyup', (event) => {
|
||||
if(event.key === '1' || event.key === '+'){
|
||||
you = 'rock';
|
||||
selectChoice(true);
|
||||
}
|
||||
if(event.key === '2' || event.key === 'ě'){
|
||||
you = 'paper';
|
||||
selectChoice(true);
|
||||
}
|
||||
if(event.key === '3' || event.key === 'š'){
|
||||
you = 'scissors';
|
||||
selectChoice(true);
|
||||
}
|
||||
});
|
||||
|
||||
function outcome(you, opponent){
|
||||
if(you===opponent){
|
||||
playerScore++;
|
||||
opponentScore-=-1;
|
||||
@@ -51,6 +62,19 @@ function selectChoice(){
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function selectChoice(fast, choice = null){
|
||||
if(!fast && choice !== null){
|
||||
you = choice;
|
||||
}
|
||||
document.getElementById("your-choice").src = `${you}.png`;
|
||||
|
||||
opponent = choices[Math.floor(Math.random()*3)];
|
||||
document.getElementById("opponent-choice").src = `${opponent}.png`;
|
||||
|
||||
outcome(you, opponent);
|
||||
|
||||
document.getElementById("opponent-score").innerHTML = opponentScore;
|
||||
document.getElementById("your-score").innerHTML = playerScore;
|
||||
}
|
||||
Reference in New Issue
Block a user