<!DOCTYPE html>
<html>
<head>
    <title>猜拳小游戏 - 在线玩剪刀石头布</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            text-align: center;
            margin-top: 100px;
        }
        h1 {
            color: #333;
        }
        .choices {
            margin-top: 20px;
        }
        .choice {
            display: inline-block;
            margin: 0 10px;
            cursor: pointer;
        }
        .choice img {
            width: 100px;
            height: 100px;
        }
        #result {
            margin-top: 20px;
            font-size: 24px;
            color: #f00;
        }
    </style>
</head>
<body>
    <h1>猜拳小游戏</h1>
    <div class="choices">
        <div class="choice" onclick="playGame('rock')">
            <img src="rock.png" alt="石头">
        </div>
        <div class="choice" onclick="playGame('paper')">
            <img src="paper.png" alt="布">
        </div>
        <div class="choice" onclick="playGame('scissors')">
            <img src="scissors.png" alt="剪刀">
        </div>
    </div>
    <div id="result"></div>
<pre><code>&lt;script&gt;
    function playGame(playerChoice) {
        var choices = ['rock', 'paper', 'scissors'];
        var computerChoice = choices[Math.floor(Math.random() * choices.length)];

        if (playerChoice === computerChoice) {
            document.getElementById('result').innerHTML = '平局!';
        } else if (
            (playerChoice === 'rock' &amp;&amp; computerChoice === 'scissors') ||
            (playerChoice === 'paper' &amp;&amp; computerChoice === 'rock') ||
            (playerChoice === 'scissors' &amp;&amp; computerChoice === 'paper')
        ) {
            document.getElementById('result').innerHTML = '你赢了!';
        } else {
            document.getElementById('result').innerHTML = '你输了!';
        }
    }
&lt;/script&gt;
</code></pre>
</body>
</html>
HTML 猜拳游戏:在线玩剪刀石头布

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

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