八重豆子 发表于 2023-3-18 21:07:54

【非MC】让chatgpt做了个猜拳游戏

就闲着没事琢磨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;
            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>
它甚至添加了注释

芓又又zyew 发表于 2023-3-18 21:25:35

chatgpt写代码?

portedboar44215 发表于 2023-3-18 21:26:10

我让他帮我写了个个人网站,贼丑[贴吧_滑稽]

八重豆子 发表于 2023-3-19 11:25:07

芓又又zyew 发表于 2023-3-18 21:25
chatgpt写代码?

当然可以啊
页: [1]
查看完整版本: 【非MC】让chatgpt做了个猜拳游戏