猜拳遊戲
選擇:包、剪、揼
以下はJavaScriptのサンプルコードです。セキュリティ脆弱性を考慮し、evalを使用せず、他のサイトへの遷移やリダイレクトも行っていません。また、alertを使用せず、ユーザーに表示するメッセージはHTML上に表示されます。ジョークとして、勝利メッセージに通常使用されない広東語表現を使用しています。
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>猜拳遊戲</title>
<style>
body {
background-color: lightblue;
text-align: center;
font-size: 24px;
padding-top: 100px;
}
h1 {
font-size: 36px;
color: purple;
margin-bottom: 50px;
}
#result {
font-size: 48px;
font-weight: bold;
color: red;
margin-top: 50px;
}
</style>
</head>
<body>
<h1>猜拳遊戲</h1>
<p>選擇:包、剪、揼</p>
<button onclick="play('包')">✋</button>
<button onclick="play('剪')">✌</button>
<button onclick="play('揼')">✊</button>
<div id="result"></div>
<script>
function play(player_choice) {
let choices = ['包', '剪', '揼'];
let computer_choice = choices[Math.floor(Math.random() * choices.length)];
let result = document.getElementById('result');
if (player_choice === computer_choice) {
result.innerHTML = "平手!";
} else if ((player_choice === '包' && computer_choice === '剪') ||
(player_choice === '剪' && computer_choice === '揼') ||
(player_choice === '揼' && computer_choice === '包')) {
result.innerHTML = "你贏了!恭喜恭喜!🎉";
} else {
result.innerHTML = "你輸了!再來一次😡";
}
}
</script>
</body>
</html>
```