じゃんけんアプリ
グー・チョキ・パーに加え、アバダケダブラとプロテゴがあります。
遊び方:自分の選択肢をクリックしてください。
あなたのスコア: 0
コンピューターのスコア: 0
以下が、ユーザーが要望したじゃんけんのアプリの実装例になります。このアプリはJavaScriptを使用して実装され、HTMLファイルとして実行されます。 セキュリティ脆弱性があるコードは実装されていません。
*注意:実際にこのアプリを使って遊ぶ場合、JavaScriptを有効にする必要があります。
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>じゃんけんアプリ</title>
</head>
<body>
<h1>じゃんけんアプリ</h1>
<p>グー・チョキ・パーに加え、アバダケダブラとプロテゴがあります。</p>
<p>遊び方:自分の選択肢をクリックしてください。</p>
<p id="result"></p>
<p>あなたのスコア: <span id="userScore">0</span></p>
<p>コンピューターのスコア: <span id="computerScore">0</span></p>
<button onclick="restart()">リスタート</button>
<script>
// 変数
var userScore = 0;
var computerScore = 0;
var tieCount = 0;
var choices = ["グー", "チョキ", "パー", "アバダケダブラ", "プロテゴ"];
// 関数
function computerChoice() {
var random = Math.floor(Math.random() * choices.length);
return choices[random];
}
function playGame(choice) {
var computer = computerChoice();
var result = "";
if (choice == "グー") {
if (computer == "アバダケダブラ") {
computerScore += 1;
result = "あなたの" + choice + "は、コンピューターのアバダケダブラに負けました!";
} else if (computer == "プロテゴ") {
userScore += 2;
result = "あなたの" + choice + "は、コンピューターのプロテゴに勝ちました!";
} else if (computer == "グー") {
tieCount += 1;
result = "引き分け! もう一度!";
} else {
computerScore += 2;
result = "あなたの" + choice + "は、コンピューターの" + computer + "に負けました!";
}
} else if (choice == "チョキ") {
if (computer == "アバダケダブラ") {
computerScore += 1;
result = "あなたの" + choice + "は、コンピューターのアバダケダブラに負けました!";
} else if (computer == "プロテゴ") {
userScore += 2;
result = "あなたの" + choice + "は、コンピューターのプロテゴに勝ちました!";
} else if (computer == "チョキ") {
tieCount += 1;
result = "引き分け! もう一度!";
} else {
computerScore += 2;
result = "あなたの" + choice + "は、コンピューターの" + computer + "に負けました!";
}
} else if (choice == "パー") {
if (computer == "アバダケダブラ") {
computerScore += 1;
result = "あなたの" + choice + "は、コンピューターのアバダケダブラに負けました!";
} else if (computer == "プロテゴ") {
userScore += 2;
result = "あなたの" + choice + "は、コンピューターのプロテゴに勝ちました!";
} else if (computer == "パー") {
tieCount += 1;
result = "引き分け! もう一度!";
} else {
computerScore += 2;
result = "あなたの" + choice + "は、コンピューターの" + computer + "に負けました!";
}
} else if (choice == "アバダケダブラ") {
if (computer == "プロテゴ") {
computerScore += 3;
result = "あなたの" + choice + "は、コンピューターのプロテゴに負けました!";
} else if (computer == "アバダケダブラ") {
tieCount += 1;
result = "引き分け! もう一度!";
} else {
userScore += 1;
result = "あなたの" + choice + "は、コンピューターの" + computer + "に勝ちました!";
}
} else if (choice == "プロテゴ") {
if (computer == "グー" || computer == "チョキ" || computer == "パー") {
userScore += 3;
result = "あなたの" + choice + "は、コンピューターの" + computer + "に勝ちました!";
} else if (computer == "プロテゴ") {
tieCount += 1;
result = "引き分け! もう一度!";
} else {
computerScore += 1;
result = "あなたの" + choice + "は、コンピューターのアバダケダブラに負けました!";
}
}
document.getElementById("result").innerHTML = result;
document.getElementById("userScore").innerHTML = userScore;
document.getElementById("computerScore").innerHTML = computerScore;
}
function restart() {
userScore = 0;
computerScore = 0;
tieCount = 0;
document.getElementById("userScore").innerHTML = userScore;
document.getElementById("computerScore").innerHTML = computerScore;
document.getElementById("result").innerHTML = "";
}
</script>
<button onclick="playGame('グー')">グー</button>
<button onclick="playGame('チョキ')">チョキ</button>
<button onclick="playGame('パー')">パー</button>
<button onclick="playGame('アバダケダブラ')">アバダケダブラ</button>
<button onclick="playGame('プロテゴ')">プロテゴ</button>
</body>
</html>
```
ジョークを追加し、遊び心を加えて実装してみました。