提交 2f1534e0 编写于 作者: W weixin_67016521

Auto Commit

上级 dd4417a5
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
<link href="style.css" rel="stylesheet" type="text/css" /> <link href="style.css" rel="stylesheet" type="text/css" />
</head> </head>
<body> <body>
<div id = "score" class="score"></div>
<div id="result"> <div id="result">
<div id="players"> <div id="players">
<div id="player-icon" class="player"></div> <div id="player-icon" class="player"></div>
......
// 定义变量,记录双方出拳 // 定义变量,记录双方出拳
let playerChoice = ""; let playerChoice = "";
let computerChoice = ""; let computerChoice = "";
var wins = 0;
var losts = 0;
var draws=0;
var rate = 0;
// 定义函数,用于电脑出拳 // 定义函数,用于电脑出拳
function computerPlay() { function computerPlay() {
...@@ -44,15 +48,25 @@ function emojiOf(choice) { ...@@ -44,15 +48,25 @@ function emojiOf(choice) {
function determineOutcome(playerChoice, computerChoice) { function determineOutcome(playerChoice, computerChoice) {
if (playerChoice === computerChoice) { if (playerChoice === computerChoice) {
draws++;
rate = (wins/(wins+losts)).toFixed(3);
document.getElementById("score").innerHTML = "😊 wins: "+(wins).toString()+" 🤖️ wins: "+ losts.toString()+" odds: "+rate.toString();
return " draw "; return " draw ";
} else if ( } else if (
(playerChoice === "scissors" && computerChoice === "paper") || (playerChoice === "scissors" && computerChoice === "paper") ||
(playerChoice === "rock" && computerChoice === "scissors") || (playerChoice === "rock" && computerChoice === "scissors") ||
(playerChoice === "paper" && computerChoice === "rock") (playerChoice === "paper" && computerChoice === "rock")
) { ) {
wins++;
rate = (wins/(wins+losts)).toFixed(3);
document.getElementById("score").innerHTML = "😊 wins: "+(wins).toString()+" 🤖️ wins: "+ losts.toString()+" odds: "+rate.toString();
return "😊 wins !"; return "😊 wins !";
} else { } else {
losts++;
rate = (wins/(wins+losts)).toFixed(3);
document.getElementById("score").innerHTML = "😊 wins: "+(wins).toString()+" 🤖️ wins: "+ losts.toString()+" odds: "+rate.toString();
return "🤖️ wins !"; return "🤖️ wins !";
} }
} }
...@@ -8,6 +8,12 @@ body { ...@@ -8,6 +8,12 @@ body {
justify-content: center; justify-content: center;
} }
score{
position: absolute;
top:10px;
left: 10px;
}
button { button {
font-size: 3rem; font-size: 3rem;
margin: 10px; margin: 10px;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册