Nahrání kódu od kolegy do větve test_web
This commit is contained in:
51
index/games/rps/index.html
Executable file
51
index/games/rps/index.html
Executable file
@ -0,0 +1,51 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en-US">
|
||||
<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>Rock Paper Scissors</title>
|
||||
<link rel="stylesheet" href="../../../style/style.css" />
|
||||
<link
|
||||
rel="icon"
|
||||
type="image/x-icon"
|
||||
href="../../../res/site/icons/favicon.ico"
|
||||
/>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header class="page-header" role="banner">
|
||||
<h1 class="project-name">Rock Paper Scissors</h1>
|
||||
<h2 class="project-tagline">Made using Javascript.</h2>
|
||||
|
||||
<a href="../../../" class="btn">Home</a>
|
||||
<a href="../" class="btn">Games</a>
|
||||
</header>
|
||||
|
||||
<main id="content" class="main-content" role="main">
|
||||
<section class="game">
|
||||
<div id="gameScore">
|
||||
<p><span id="scorePlayer"></span> <span id="scoreCPU"></span></p>
|
||||
<p><span id="round"></span></p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<script src="./script/script.js"></script>
|
||||
<button class="btn gameButton" onclick="play('rock')">🪨</button>
|
||||
<button class="btn gameButton" onclick="play('paper')">📄</button>
|
||||
<button class="btn gameButton" onclick="play('scissors')">✂️</button>
|
||||
</div>
|
||||
|
||||
<div id="evaluation">
|
||||
<p id="choice">
|
||||
<span id="choicePlayer"></span> <span id="choiceCPU"></span>
|
||||
</p>
|
||||
<p><strong id="gameWinner"> </strong></p>
|
||||
</div>
|
||||
</section>
|
||||
<footer class="site-footer">
|
||||
You have reached the end of the page. (ノ◕ヮ◕)ノ*:・゚✧
|
||||
</footer>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
93
index/games/rps/script/script.js
Executable file
93
index/games/rps/script/script.js
Executable file
@ -0,0 +1,93 @@
|
||||
let userChoice = "";
|
||||
|
||||
const getUserChoice = (userInput) => {
|
||||
userChoice = userInput;
|
||||
};
|
||||
|
||||
function getComputerChoice() {
|
||||
let cpuChoice = Math.floor(Math.random() * 3);
|
||||
if (cpuChoice === 0) {
|
||||
return "rock";
|
||||
} else if (cpuChoice === 1) {
|
||||
return "paper";
|
||||
} else if (cpuChoice === 2) {
|
||||
return "scissors";
|
||||
}
|
||||
}
|
||||
|
||||
function determineWinner(userChoice, computerChoice) {
|
||||
if (userChoice === computerChoice) {
|
||||
return "Tie";
|
||||
}
|
||||
if (userChoice === "rock") {
|
||||
if (computerChoice === "paper") {
|
||||
return "Computer";
|
||||
} else {
|
||||
return "Player";
|
||||
}
|
||||
}
|
||||
if (userChoice === "paper") {
|
||||
if (computerChoice === "scissors") {
|
||||
return "Computer";
|
||||
} else {
|
||||
return "Player";
|
||||
}
|
||||
}
|
||||
if (userChoice === "scissors") {
|
||||
if (computerChoice === "rock") {
|
||||
return "Computer";
|
||||
} else {
|
||||
return "Player";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const score = {
|
||||
player: 0,
|
||||
cpu: 0,
|
||||
ties: 0,
|
||||
rounds: 0,
|
||||
};
|
||||
|
||||
function playGame() {
|
||||
var computerChoice = getComputerChoice();
|
||||
const winner = determineWinner(userChoice, computerChoice);
|
||||
|
||||
score.rounds++;
|
||||
switch (winner) {
|
||||
case "Player":
|
||||
score.player++;
|
||||
break;
|
||||
case "Computer":
|
||||
score.cpu++;
|
||||
break;
|
||||
case "Tie":
|
||||
score.ties++;
|
||||
break;
|
||||
}
|
||||
|
||||
console.log("\nPlayer: " + userChoice);
|
||||
console.log("CPU: " + computerChoice);
|
||||
if (winner != "Tie") {
|
||||
console.log("Winner: " + winner);
|
||||
} else {
|
||||
console.log("Tie game!");
|
||||
}
|
||||
console.log(score);
|
||||
|
||||
scorePlayer.textContent = `Player wins: ${score.player}` + " ";
|
||||
scoreCPU.textContent = `Computer wins: ${score.cpu}`;
|
||||
round.textContent = `Round ${score.rounds}`;
|
||||
choicePlayer.textContent = `You: ${userChoice}`;
|
||||
choiceCPU.textContent = `CPU: ${computerChoice}`;
|
||||
if (winner != "Tie") {
|
||||
gameWinner.textContent = "Winner: " + winner;
|
||||
} else {
|
||||
gameWinner.textContent = "Tie game!";
|
||||
}
|
||||
}
|
||||
|
||||
function play(input) {
|
||||
getUserChoice(input);
|
||||
playGame();
|
||||
}
|
Reference in New Issue
Block a user