2014-01-29 17 views
-3

我正在尝试开发一个简单的使用Javascript的在线文字游戏。我现在已经过了,但现在我陷入了困境。基本上游戏的第一部分是显示十个单词,它是描述。在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> 
+3

呃...所以你想让我们......建立你的程序?我在这里没有看到任何相关的代码** **测试我**,**切换多个选择**,**选择了正确或错误的单词**,或**你有9/10右**。这是很多问题的萌芽。 –

+0

不能理解你的游戏...你正在显示的话和描述,然后你测试什么?为什么你不使用全局变量来维护分数... – Saurabh

+0

这主要是为了练习。一旦我开始工作,我会将描述转换成一个句子,填入空白类型的问题,如下所示(什么是1 + 1 = _________)。是的,我完全陷入困境,我没有要求某人为我编写程序,但有人请指导我如何完成此任务。我一直在努力。我无法自己弄清楚,我需要帮助。谢谢@Saurabh –

回答

1

嘿,我只是帮助,因为我认为你真的卡住了。但稍后请注意您提出的问题,并请具体说明。

你的HTML有点乱,所以我不得不改变它(主要讨论各种选择,部分原因是游戏的主要部分)

现在你的游戏让我告诉你这一点。

  1. <input type='radio'>应该有与您显示的标签相同的值,因为它会帮助您检查正确的答案。
  2. 你必须动态加载选项(在演示中我已经展示了如何做一个休息的请搞清楚)
  3. 在你开始再次使用这个之前阅读一下关于jQuery,JavaScript和html的一些信息。

现在我已经使用jQuery,因此我建议ü也用它作为以后这将是一个很大的帮助你,如果你知道的JavaScript,然后jQuery的将是U A容易的工作。(相信我这一)。

This is the demo for your game

+0

非常感谢。我一直在研究javascript的基础知识,但是我看到我需要一遍又一遍地阅读,直到我把它打包下来。 –