- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何让某个功能执行后出现一个按钮?
我正在尝试创建一个简单的游戏,它有 2 个按钮,当程序首次运行时,它们会导致功能 2 和 3。
按下两个按钮之一并执行其中一项功能后,该按钮消失。然后我想在第二个和第三个功能上创建另一个按钮,允许玩家重玩游戏并退出游戏。问题是我不知道如何让按钮只出现在第二个功能或第三个功能上。
<HTML>
<!Foundation Page for building our Javascript programs>
<HEAD>
<TITLE>The Foundation Page </TITLE>
<SCRIPT LANGUAGE="JavaScript">
var score;
score = 0
function mainmenu() {
var start
name = prompt("What is your name?")
document.write("Welcome " + name + " for playing game" + "<BR>")
}
function game() {
var ask
var repeat
var again
again = "yes"
while (again == "yes") {
document.write("Hello " + name + " Welcome to the game, you will decide on what action you will take depending on the situation. You will either gain or loose score depending on your decision made. GLHF!" + "<br>" + "<BR>")
document.write(" You enter the dungeon and its pitch black, you can barely see your hand infront of your face. You have a pair of flint inside your pocket and you can attempt to make a torch by ripping a piece of your cloth. What do you do?" + "<BR>")
decision1 = (" Option 1) You brave the darkness" + "<br>")
document.write(decision1)
/* dont need to use all these's variables for decision 1-16*/
decision2 = ("Option 2) You attempt to make a torch" + "<BR>")
document.write(decision2)
decision3 = ("Option 3) You attempt to find a wall and let it guide you" + "<BR>")
document.write(decision3)
decision4 = ("Option 4) You run like an animal, screaming like an animal" + "<BR>")
document.write(decision3)
ask = prompt("Which decision do you choose? Choose from 1,2,3 and 4" + "<BR>")
if (ask == "1") {
document.write("You walk for a few minute without any event but you suddenly step onto a pot-hole and loose your grip. You injured your right knee. You'll live but its gonna hurt for a while" + "<BR>")
score = score + 20
}
if (ask == "2") {
document.write("You tore off a piece of cloth from your sholder and you write it around a stick you found nearby but ask you reach into your pocket to grab your flint, you dropped it. As you attempt to find it, you accidentally felt something sharp and you started to bleed from your left hand. Tought luck m8" + "<BR>")
score = score - 30
}
if (ask == "3") {
document.write("You glide your hand agaist the wall, after half and hour of nothing happening. You finally found a ray of light at the end of the tunnel" + "<BR>")
score = score + 50
}
if (ask == "4") {
document.write("You started running and you scream your lungs out. You took 3 steps and you fell down face first. What the hell were you thinking?" + "<BR>")
score = score - 50
}
document.write("Your current score is " + score + "<BR>")
document.write(" As you finally walk past the darkness, you stumble upon a bright litted room. In the middle of the room, filled a chest. You took a survey around the room and you notice there's nothing in the room except the chest. What to do you?" + "<BR>" + "<BR>")
decision5 = ("Option 1) You rush towards the treasure chest and open it. Gotta get dat bootie!" + "<br>")
document.write(decision5)
/* dont need to use all these's variables for decision 1-16*/
decision6 = ("Option 2) You take a more carefull look around the room." + "<BR>")
document.write(decision6)
decision7 = ("Option 3) You leave the chest alone and walk straight past it and into the next room" + "<BR>")
document.write(decision7)
decision8 = ("Option 4) You kick the chest" + "<BR>")
document.write(decision8)
ask = prompt("Which decision do you choose? Choose from 5,6,7 and 8" + "<BR>")
if (ask == "1") {
document.write("You rush towards the chest with full speed and suddenly, half a dozen arrow wizzez past you. Unfortunatly, you've been hit around the sholder. You decided its too dangerous and you cut your losses and enter the next room" + "<BR>")
score = score - 50
}
if (ask == "2") {
document.write("As you walk to the side of the room, you notice there are dozens of small holes placed infront of the the treasure chest. You also notice there are pressure plates suinfront of the chest. You walk behind the chest and opened it and you fond that its completely empty!. So much for bootie." + "<BR>")
score = score + 50
}
if (ask == "3") {
document.write("You decided to play it safe and walk past the treasure chest. Nothing happens" + "<BR>")
score = score + 0
}
if (ask == "4") {
document.write("You decided to kick the chest for whatever reason. You hurt your foot during the process. Why would you do that?" + "<BR>")
score = score - 20
}
document.write("Your current score is " + score + "<BR>")
document.write(" As you continue along your journey, you stumble upon an injured adventurer! You rush to his side and he claims that his right leg is broken. He's seems to be carrying a rather heavy rucksack. You cant carry him with you because he's simply too heavy. " + "<BR>" + "<BR>")
decision9 = (" Option 1) You perform some medical treatment on him. Though you dont have much experience on medicine." + "<br>")
document.write(decision9)
/* dont need to use all these's variables for decision 1-16*/
decision10 = ("Option 2) You ignore him." + "<BR>")
document.write(decision10)
decision11 = ("Option 3) You search for his bag and see if there is anything useful to help him" + "<BR>")
document.write(decision11)
decision12 = ("Option 4) You end his misery. He's not gonna last long here anyway." + "<BR>")
document.write(decision12)
ask = prompt("Which decision do you choose? Choose from 9,10,11 and 12" + "<BR>")
if (ask == "1") {
document.write("you attempt to fix the adventurer's leg by applying some ointment onto his leg. It wont help much but at least it's something" + "<BR>")
score = score + 10
}
if (ask == "2") {
document.write("You walk past him and ignore his plea of him. There's nothing you can do to help him" + "<BR>")
score = score + 0
}
if (ask == "3") {
document.write("As you run through his bad you found a stick! Looks like he's in a sticky situation :D, you tied the stick to the adventurer's leg. It seems to be sturdy enough to hold him. He thanks you and he goes to his merry ways." + "<BR>")
score = score + 40
}
if (ask == "4") {
document.write("You decide to end his misery by knocking him in the back. He falls dead on the ground the moment your hand make contact. How this work i will nover know. Just roll with it" + "<BR>")
score = score - 20
}
document.write(" At the end of the room a giant lion statue gazes upon you. He ask you a quiz. What walks on 4 legs, then 2 and finally 3. " + "<BR>" + "<BR>")
decision13 = (" Option 1) AN ANIMAL!" + "<br>")
document.write(decision13)
/* dont need to use all these's variables for decision 1-16*/
decision14 = ("Option 2) A CHAIR!" + "<BR>")
document.write(decision14)
decision15 = ("Option 3) A MAN!" + "<BR>")
document.write(decision15)
decision16 = ("Option 4) I dunno" + "<BR>")
document.write(decision16)
ask = prompt("Which decision do you choose? Choose from 13,14,15 and 16" + "<BR>")
if (ask == "1") {
document.write("NOPE, the lion statue slowly disapears and behind it leads to the outside world" + "<BR>")
score = score - 10
}
if (ask == "2") {
document.write("NOPE, the lion statue slowly disapears and behind it leads to the outside world" + "<BR>")
score = score - 10
}
if (ask == "3") {
document.write("Correct!, the lion statue slowly disapears and behind it leads to the outside world." + "<BR>")
score = score + 10
}
if (ask == "4") {
document.write("Your not even gonna try? The lion's head shook in disapointment and slowly disapears. Behind it leads to the outside world" + "<BR>")
score = score - 20
}
document.write("Your current score is " + score)
again = prompt("would you like to play again?")
}
leaderboard()
}
function leaderboard() {
var n, temp;
ok = false;
var leaderboardarray = new Array(5);
leaderboardarray[0] = 50;
leaderboardarray[1] = 60;
leaderboardarray[2] = 130;
leaderboardarray[3] = 120;
leaderboardarray[4] = score;
leaderboardarray.sort(function (a, b) {
return b - a
});
var myContent = '';
for (var n = 0; n < 5; n++)
myContent += "score: " + leaderboardarray[n] + "<br>";
document.getElementById("leaderBoard").innerHTML = myContent;
document.write("Your current score is " + score)
}
leaderboard()
</SCRIPT>
</HEAD>
<BODY style="background-color:#cccccc;">
<INPUT NAME="dobutton" TYPE="button" value="Start game" onclick=game()>
<INPUT NAME="dobutton" TYPE="button" value="Leaderboard" onclick=leaderboard()>
<H2>The Foundation Page </H2>
<HR>
<div id="leaderBoard">
<script type="text/javascript">mainmenu();</script>
</div>
<BR>
</BODY>
</HTML>
最佳答案
您可以为这两个按钮分配广告 ID,并隐藏第二个按钮:
<INPUT ID="btn1" NAME="dobutton" TYPE="button" value="Start game" onclick="game()">
<INPUT ID="btn2" NAME="dobutton" TYPE="button" value="Leaderboard" onclick="leaderboard()" style="display:none;">
然后您可以通过以下方式显示或隐藏它们:
document.getElementById("btn1").style.display = "none"; /// first button disappear
document.getElementById("btn2").style.display = "inline"; /// second button appear
关于javascript - 多按钮帮助。某些功能上出现的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29715039/
我有这个问题: 我们声称对 float 使用相等测试是不安全的,因为算术运算会引入舍入错误,这意味着两个应该相等的数字实际上并不相等。 对于这个程序,您应该选择一个数字 N,并编写一个程序来显示 1
为什么这个脚本的输出是 5 而不是 8 ? 我认为 -- 意味着 -1 两次。 var x = 0; var y = 10; while ( x
我现在可以从 cmd 窗口中执行的 FFmpeg 过程中读取最后一行。 使用脚本主机模型对象引用此源。 Private Sub Command1_Click() Dim oExec
使用 vlookup,当匹配发生时,我想从匹配发生的同一行显示工作表 2 中 C 列的值。我想出的公式从 C 列表 2 中获取值,但它从公式粘贴在表 3 上的行中获取,而不是从匹配发生的位置获取。 这
我在破译 WCF 跟踪文件时遇到了问题,我希望有人能帮助我确定管道中的哪个位置发生了延迟。 “Processing Message XX”的跟踪如下所示,在事件边界和传输到“Process Actio
我有四个表,USER、CONTACT、CONACT_TYPE 和 USER_CONTACT USER_CONTACT 存储用户具有填充虚拟数据的表的所有联系人如下 用户表 USER_ID(int)|
以下有什么作用? public static function find_by_sql($sql="") { global $database; $result_set = $data
我正在解决 JavaBat 问题并且对我的逻辑感到困惑。 这是任务: Given a day of the week encoded as 0=Sun, 1=Mon, 2=Tue, ...6=Sat,
我正在研究一些 Scala 代码,发现这种方法让我感到困惑。在匹配语句中,sublist@ 是什么?构造?它包含什么样的值(value)?当我打印它时,它与 tail 没有区别,但如果我用尾部替换它,
我正在使用以下代码自行缩放图像。代码很好,图像缩放也没有问题。 UIImage *originImg = img; size = newSize; if (originImg.size.width >
Instruments 无法在我的 iPad 和 iPhone 上启动。两者都已正确配置,我可以毫无问题地从 xcode 调试它们上的代码,但 Instruments 无法启动。 我听到的只是一声嘟嘟
我想用 iPhone 的 NSRegularExpression 类解析此文本: Uploaded652.81 GB 用于摘录上传和652.81文本。 最佳答案 虽然我确实认为 xml 解析器更适合解
我找到了 solution在 Stackoverflow 上,根据过滤器显示 HTML“li”元素(请参阅附件)。本质上基于 HTML 元素中定义的 css 类,它填充您可以从中选择的下拉列表。 我想
这是一个简单的问题,但我是在 SQL 2005 中形成 XML 的新手,但是用于形成如下所示表中的 XML 的最佳 FOR XML SQL 语句是什么? Column1 Column2 -
我在 www.enigmafest.com 有一个网站!您可以尝试打开它!我面临的问题是,在预加载器完成后,主页会出现,但其他菜单仍然需要很长时间才能加载,而且声音也至少需要 5 分钟! :( 我怎样
好吧,我正在尝试用 Haskell 来理解 IO,我想我应该编写一个处理网页的简短小应用程序来完成它。我被绊倒的代码片段是(向 bobince 表示歉意,但公平地说,我并不想在这里解析 HTML,只是
如何使用背景页面来突出显示网站上的某个关键字,无论网站是什么(谷歌浏览器扩展)?没有弹出窗口或任何东西,它只是在某人正在查看的网站上编辑关键字。我以前见过这样的,就是不明白怎么做!谢谢你的帮助。 最佳
我是 Javascript 新手,需要一些帮助。 先看图片: . 积分预测器应用程序。 基本上当用户通过单选按钮选择获胜团队时它应该在积分栏中为获胜队添加 10 分,并且并根据得分高的球队自动对表格进
这是我的情况 - 我要发送一份时事通讯,我试图做的是,当用户单击电子邮件中的链接时,它会重定向到我的网页,然后会弹出一个灯箱,显示视频。我无法在页面加载时触发灯箱,因为您可以在查看灯箱之前转到同一页面
我有这个代码。 ¿Cuanto es ? Ir 我想获取用户输入的“验证码”值。我尝试这个但行不通。有什么帮助吗? var campo = d
我是一名优秀的程序员,十分优秀!