var input = document.querySelector("input");
var button = document.querySelector("button");
var inventory = ["jacket","pants","map"];
var actionsIKnow = ["north","east","west","south"];
var messages = ["A group of dangerous minions. Turn back, you do not have a sword",
"You have gone too deep into the forest. Want to go further?",
"A giant ruby crystal",
"A silent lake; you see your reflection in the water",
"Clear patch of land",
"A sleeping dragon. Bettwe not wake it up",
"A solitary cottage. Faint music can be heard from the inside",
"Looks like this path leads to the cottage of the flute maker",
"A lot of tombstones, looks like an old graveyard"
];
var userInput;
var startingPos = 4;
button.addEventListener("click",takeMeThere,false);
function takeMeThere(){
userInput = input.value;
userInput = userInput.toLowerCase();
if(userInput!=null){
validateInput();
}
}
function validateInput(){
for(var i=0;i<actionsIKnow.length;i++){
if(userInput.indexOf(actionsIKnow[i]!=-1)){
move(actionsIKnow[i]);
}
}
}
function move(where){
console.log(where);
}
我正在制作一个基于文本的探索游戏,用户可以在其中选择去哪里。用户想去的地方取决于在文本字段中输入的内容。然后将此数据传递到move(where)
I 所在的位置console.log(where)
。它不是打印北、东等,而是打印整个actionsIKnow
数组。为什么 ?