如何在JS游戏中创建帮助页面,库存显示和Take项目

时间:2014-02-07 02:12:17

标签: javascript

我有一个textarea显示播放器的所有动作,并有一个单独的命令框用于移动和输入命令'h'以获取项目的帮助'i',以及't'用于获取项目。事情是我被困在如何实现这一目标。主要是帮助和库存部分的帮助会很棒。这是我到目前为止所得到的:

//Global Variables
var currentLocale = 0;
var direction = false;
var check = false;
function updateDisplay() {
    msg = "";
    if (direction!=true){
        if (check!=true){

            switch (currentLocale) {

                case 0:  msg = "Your home...Earth.";
                         break;
                case 1:  msg = "On Mercury.";
                         break;
                case 2:  msg = "On Mars.";
                         break;
                case 3:  msg = "On Saturn.";
                         break;
                case 4:  msg = "On Venus.";
                         break;
                case 5:  msg = "On Neptune.";
                         break;
                case 6:  msg = "On Jupiter.";
                         break;
                case 7:  msg = "On Uranus.";
                         break;    
                default: msg = "You broke me.";

            }


        }else{
            msg="Please enter a valid command ( listed below).";
            check=false;
        }
    }else{
        msg="You can not go this way."
        direction=false;
    }

    taPtr = document.getElementById("taDisplay");
    history = taPtr.value;
    taPtr.value =  msg +"\n"+ history; 

}
//             N   S   E   W 
var nav = [
    [ 1, -1, -1, -1 ], // Earth    
    [ 2, 0,-1, -1 ],    //Mercury
    [ -1, 1, 3, 4],    //Mars                     
    [ -1, -1, -1, 2], // Saturn   
    [ 5, 6, 2, -1],    //Venus
    [ -1, 4, -1, -1],  //Neptune
    [ 4, 7, -1, -1],   //Jupiter
    [ 6, -1, -1, -1],  //Uranus
];

function  go(dir){               
    var  dirNum=-1;        //Global Variable 
    if (dir == 'N'){
        dirNum=0;
    }else if (dir =='S'){
        dirNum=1;
    }else if (dir == 'E'){
        dirNum=2;
    }else if (dir == 'W'){
        dirNum=3;
    };
    changeLocale(dirNum);
}


function changeLocale(dirNum){

    var temp= nav[currentLocale][dirNum];

    if (dirNum != -1){
        if(temp >= 0 ) {    
            currentLocale= temp;  

        }else {
            direction=true;
        }

    }else {
        check= true;  
    }                                            
    updateDisplay();  

} 

function commandInput(){

    var dirNum=-1;                  
    var comm=document.getElementById("commandBox").value;
    var command= comm.toUpperCase();

    switch(command){
        case 'N': dirNum=0;
                  break;
        case 'S': dirNum=1;
                  break;
        case 'E': dirNum=2;
                  break;
        case 'W': dirNum=3;
                  break;
        default : msg= ('You broke me.');
                  break;
    }
    changeLocale(dirNum);



}

提前致谢。

0 个答案:

没有答案