当然可以帮您做一个网页休闲多人小游戏。以下是一个简单的示例——一个双人对战的'石头、剪刀、布'游戏:

<!DOCTYPE html>
<html>
<head>
  <title>石头、剪刀、布</title>
  <style>
    body {
      text-align: center;
      font-family: Arial, sans-serif;
    }

    h1 {
      margin-top: 50px;
    }

    #game {
      margin-top: 50px;
    }

    #game img {
      width: 100px;
    }

    #result {
      margin-top: 20px;
      font-size: 20px;
    }
  </style>
</head>
<body>
  <h1>石头、剪刀、布</h1>
  <div id="game">
    <img src="rock.png" id="rock" onclick="play('rock')">
    <img src="scissors.png" id="scissors" onclick="play('scissors')">
    <img src="paper.png" id="paper" onclick="play('paper')">
  </div>
  <div id="result"></div>

  <script>
    function play(userChoice) {
      var choices = ['rock', 'scissors', 'paper'];
      var computerChoice = choices[Math.floor(Math.random() * choices.length)];

      document.getElementById('rock').style.opacity = 0.5;
      document.getElementById('scissors').style.opacity = 0.5;
      document.getElementById('paper').style.opacity = 0.5;

      if (userChoice === computerChoice) {
        document.getElementById('result').innerHTML = '平局!';
      } else if (
        (userChoice === 'rock' && computerChoice === 'scissors') ||
        (userChoice === 'scissors' && computerChoice === 'paper') ||
        (userChoice === 'paper' && computerChoice === 'rock')
      ) {
        document.getElementById('result').innerHTML = '你赢了!';
      } else {
        document.getElementById('result').innerHTML = '你输了!';
      }

      document.getElementById(userChoice).style.opacity = 1;
    }
  </script>
</body>
</html>

这是一个简单的石头、剪刀、布游戏,其中包含了石头、剪刀和布的图片。当玩家点击其中一种选项时,游戏会随机选择电脑的选项,并根据规则判断胜负,并显示结果。

您可以根据自己的需求进行修改和扩展,添加更多游戏规则、样式和功能。

网页休闲多人小游戏:石头剪刀布 - 在线对战

原文地址: https://www.cveoy.top/t/topic/o4lB 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录