UID184318性别保密经验 EP铁粒 粒回帖0主题精华在线时间 小时注册时间2021-11-27最后登录1970-1-1
|
就闲着没事琢磨ChatGPT,整了这么个东西出来。。。
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>石头剪刀布游戏</title>
- <style>
- body {
- font-family: Arial, sans-serif;
- text-align: center;
- }
- h1 {
- margin-top: 50px;
- }
- button {
- padding: 10px;
- margin: 20px;
- font-size: 20px;
- cursor: pointer;
- }
- #result {
- font-size: 24px;
- font-weight: bold;
- margin-top: 50px;
- }
- </style>
- </head>
- <body>
- <h1>石头剪刀布游戏</h1>
- <button id="rock">石头</button>
- <button id="scissors">剪刀</button>
- <button id="paper">布</button>
- <div id="result"></div>
- <script>
- // 定义变量
- var choices = ["石头", "剪刀", "布"];
- var computerChoice;
- var playerChoice;
- // 点击按钮时触发事件
- document.getElementById("rock").onclick = function() { play("石头"); };
- document.getElementById("scissors").onclick = function() { play("剪刀"); };
- document.getElementById("paper").onclick = function() { play("布"); };
- // 游戏逻辑
- function play(playerChoice) {
- computerChoice = choices[Math.floor(Math.random() * choices.length)];
- var result = "";
- if (playerChoice === computerChoice) {
- result = "平局!";
- } else if ((playerChoice === "石头" && computerChoice === "剪刀") ||
- (playerChoice === "剪刀" && computerChoice === "布") ||
- (playerChoice === "布" && computerChoice === "石头")) {
- result = "你赢了!";
- } else {
- result = "电脑赢了!";
- }
- document.getElementById("result").innerHTML = "你出了:" + playerChoice + ",电脑出了:" + computerChoice + "," + result;
- }
- </script>
- </body>
- </html>
复制代码 它甚至添加了注释
|
|