- html
好东西
- 2024-4-27 17:58:59 @
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>猜数字游戏</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
text-align: center;
}
h1 {
color: #3366ff;
}
</style>
</head>
<body>
<h1>猜数字游戏</h1>
<p>我已经想好了一个介于1到100之间的数字,请开始猜测:</p>
<input type="text" id="guess">
<button onclick="checkGuess()">提交猜测</button>
<p id="hint"></p>
<p id="attempts"></p>
<script>
// 生成随机数
var randomNumber = Math.floor(Math.random() * 100) + 1;
var gua1 = Math.floor(Math.random() * 10) + 1;
var gua2 = Math.floor(Math.random() * 10) + 1;
var attempts = 0;
var money=100;
var koushui=0;
var ksu=2;
var ksn=4;
function checkGuess() {
var guess = parseInt(document.getElementById("guess").value);
if(guess===666)
{
document.getElementById("hint").innerText = "竟敢开挂 你完了!";
if(money<50) money=25;
else money=50;
ksu*=2;
ksn*=2;
gua1+=gua2;
randomNumber = Math.floor(Math.random() * (100+randomNumber)) + 1;
}
else if(guess===gua1*gua2)
{
document.getElementById("hint").innerText = "开挂成功 \n 数字:"+randomNumber;
}
else if (guess === randomNumber) {
alert("恭喜你,猜对了!答案是 " + randomNumber + "。你一共猜了 " + (attempts + 1) + " 次。"+"你的RP增加了"+(money-koushui));
} else if (guess < randomNumber) {
document.getElementById("hint").innerText = "太小了,请再试一次。";
attempts++;
if(guess - randomNumber>=-3&&guess - randomNumber<=3) koushui+=ksu;
else koushui+=ksn;
} else {
document.getElementById("hint").innerText = "太大了,请再试一次。";
attempts++;
if(guess - randomNumber>=-3&&guess - randomNumber<=3) koushui+=ksu;
else koushui+=ksn;
}
document.getElementById("attempts").innerText = "你已经猜了 " + attempts + " 次。"+"\n";
document.getElementById("guess").value = ""; // 清空输入框
}
</script>
</body>
</html>
0 条评论
目前还没有评论...
信息
- ID
- 1074
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- (无)
- 递交数
- 1
- 已通过
- 0
- 上传者