简体   繁体   English

需要帮助制作这个小型 javascript“游戏”

[英]Need help making this small javascript 'game'

Trying to use javascript to make a game/script that:尝试使用 javascript 制作一个游戏/脚本:
- each number from 0-20 equal a specific word. - 0-20 之间的每个数字都等于一个特定的单词。 Ex: 0=saw, 1=tie, 2=noah.例如:0=saw,1=tie,2=noah。
- a number pops up on the screen and the user needs to type in the word that = that number. - 屏幕上会弹出一个数字,用户需要输入单词 that = 该数字。
- Then the program says if I was correct or not and adds to my points. - 然后程序会说我是否正确并增加我的分数。

Demo: http://jsfiddle.net/elclanrs/gfQsP/演示: http : //jsfiddle.net/elclanrs/gfQsP/

var points = 0;
function game() {
    var words = 'lorem ipsum dolor sit amet consecteur adipisci elit'.split(' ');
    var rand = -~(Math.random() * words.length);
    var result = prompt('Word number '+ rand +'?');
    var match = words[rand-1] === result.toLowerCase();
    alert( match ? 'Good' : 'Bad');
    match && points++;
}

well this can be easy:好吧,这很容易:

just make a object containing key value pairs like this:只需创建一个包含键值对的对象,如下所示:

var obj = {
key1: value1,
key2: value2
};

Then ask the player the value of particular number.然后询问玩家特定数字的值。 Loop through this object to scan the value of that particular number to match the value as entered by the player.循环遍历此对象以扫描该特定数字的值以匹配玩家输入的值。 if found increment the points counter.如果发现增加点计数器。

Its pretty straight forward.它非常直接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM