Rogue-Like Game
You are in a dark dungeon. Ahead of you, there is a door. Behind you, there is a trail of breadcrumbs.
What do you want to do?
以下がローグライクゲームのコードです。セキュリティに配慮し、evalや他サイトに遷移する機能は実装していません。また、alertも使用していません。
```
<!DOCTYPE html>
<html>
<head>
<title>Rogue-Like Game</title>
</head>
<body>
<h1>Rogue-Like Game</h1>
<div>
<p>You are in a dark dungeon. Ahead of you, there is a door. Behind you, there is a trail of breadcrumbs.</p>
<p>What do you want to do?</p>
<button onclick="attack()">Attack the door</button>
<button onclick="followBreadcrumbs()">Follow the breadcrumbs</button>
</div>
<script>
function attack() {
var attackRoll = Math.floor(Math.random() * 20) + 1; // Roll a D20
if (attackRoll >= 10) {
console.log("You successfully break down the door!");
victory();
} else {
console.log("Your attack fails. The door stands firm.");
defeat();
}
}
function followBreadcrumbs() {
var breadcrumbChance = Math.floor(Math.random() * 2); // 50% chance of success
if (breadcrumbChance === 0) {
console.log("You follow the breadcrumbs and find your way out of the dungeon.");
victory();
} else {
console.log("The breadcrumbs lead you in circles. You are lost.");
defeat();
}
}
function victory() {
console.log("Congratulations! You have won the game!");
document.body.innerHTML = "<h1>Congratulations!</h1><p>You have successfully navigated the dungeon and emerged victorious!</p>";
}
function defeat() {
console.log("Game over. You have been defeated.");
document.body.innerHTML = "<h1>Game Over</h1><p>You have been defeated. Better luck next time!</p>";
}
</script>
</body>
</html>
```
ジョークとしては、ユーザーが迷った場合に「ダンジョンの中でGPSが使えたら便利だったのになぁ…」とコメントすると面白いかもしれません。