【发布时间】:2014-02-20 17:24:57
【问题描述】:
我正在尝试使用 Javascript 开发一个简单的在线文字游戏。我有办法通过,但我现在被困住了。基本上游戏的第一部分是显示十个单词及其描述。
然后用户可以单击“测试我”按钮,然后将被定向到我称为 testme.html 的页面,我将在其中显示描述,然后,他们可以选择四个单词。一旦玩家单击按钮,下一个描述就会出现,我的描述就可以正常工作。现在,我还需要能够切换多个选择,并创建一个函数,我可以在其中查看他们是否选择了正确或错误的单词,然后最后我可以显示他们有多少正确或错误,例如: 你猜对了 9/10。
这里是主页:http://alexallin.com/wordgame/
这里是 testme.html 页面:http://alexallin.com/wordgame/Testme.html
var ThisText = 0;
var Words = [ { word: '1. Amicable', definition: 'friendly, agreeable.' },
{ word: '2. acumen', definition: 'the ability to make good judgments and quick decisions, typically in a particular domain.' },
{ word: '3. accoutrements', definition: 'additional items of dress or equipment, or other items carried or worn by a person or used for a particular activity.' },
{ word: '4. Abstinence', definition: 'the act of refraining from pleasurable activity, e.g., eating or drinking.' },
{ word: '5. Adulation', definition: 'high praise.' },
{ word: '6. Adversity', definition: 'misfortune, an unfavorable turn of events.' },
{ word: '7. Aesthetic', definition: 'pertaining to beauty or the arts.' },
{ word: '8. Anachronistic', definition: 'out-of-date, not attributed to the correct historical period.' },
{ word: '9. Anecdote', definition: 'short, usually funny account of an event.' },
{ word: '10. Antagonist', definition: 'foe, opponent, adversary.' },
];
function ChangeWordTo(NextWord) {
document.getElementById('Answer_Box_One').innerHTML = NextWord;
}
// this grabs the ID description
function ChangeDescriptionTo(NextDescription) {
document.getElementById('description').innerHTML = NextDescription;
}
// This loads it to the first definition...
function onLoad() {
switchTo(0);
}
// won't work with out
function switchTo(which) {
ChangeWordTo(Words[which].word);
ChangeDescriptionTo(Words[which].definition);
}
// This increments as button is click
function ShowDesc() {
ThisText++;
switchTo(ThisText);
}
这里是 HTML 代码------------------------
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="main.css">
<script src="score.js"></script>
</head>
<body onload="onLoad();">
<div id="main">
<div>
<center><p id="description">Read the Discription and chose your answer below.</p></center>
</div>
<br/>
<!--
<div id="Answer_Box">
<center>
<form>
<input type="checkbox" name="vehicle" value="text" id="Answer_Box_One">I have a bike
</form>
-->
<form>
<center>
<div style="float: left; width: 50%;">
<ul>
<label id="Answer_Box_One" for="male">Male</label>
<input type="radio" name="sex" id="male" value="male"><br>
<label id="Answer_Box_Two" for="male">Female</label>
<input type="radio" name="sex" id="male" value="Female"><br>
</ul>
</div>
<div style="float: right; width: 50%;">
<ul>
<label id="Answer_Box_Three" for="male">Male</label>
<input type="radio" name="sex" id="male" value="male"><br>
<label id="Answer_Box_Four" for="Not Above">Not Above</label>
<input type="radio" name="sex" id="Not Above" value="Not Above"><br>
</ul>
</div>
<button type="button" onclick="ShowDesc();">Correct</button>
</center>
</form>
</center>
</div>
</div>
</body>
</html>
【问题讨论】:
-
呃...所以您希望我们...构建您的程序?我在这里没有看到 test me、切换多项选择、选择正确或错误的单词或你答对了 9/10。这是很多问题。
-
无法理解您的游戏...您同时显示文字和描述,那么您测试什么?为什么不使用全局变量来维护分数...
-
这主要是为了练习。一旦我开始使用它,我会将描述切换为一个句子,并填写这样的空白类型的问题(什么是 1+1=_________。)。是的,我完全卡住了,我不是要求有人为我编写程序,而是请有人指导我如何完成这项任务。我已经为此工作了一段时间。我自己搞不定,我需要帮助。谢谢@Saurabh
-
请参阅 Stack Overflow 帮助以了解 on-topic 的含义,特别注意第 3 点和第 4 点。另外,您的问题太宽泛了:您的具体问题是什么?如果您不知道如何从数组中采样,请询问。或者更好的是,看看之前是否有人问过它(例如,stackoverflow.com/questions/11935175/…)。另一方面,“我该如何编写这个游戏?”这个问题太宽泛了。
-
如果你看,我自己已经走得很远了。现在,我被困住了。我只需要知道如何验证用户选择了正确的选择,并将其存储在某个地方,我对如何切换所有四个多项选择感到困惑。 @Amadan
标签: javascript jquery html