js小游戏

var maps = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]];

var role = [3, 4];

function up(action){
  
  if(action == 1) role[1]--;
  if(action == 2) role[0]--;
  if(action == 3) role[1]++;
  if(action == 4) role[0]++;
  
  var tmp = '';
  console.clear();

for(var i = 0; i < maps.length; i++){
  
  tmp = '';
  for(var j = 0; j < maps[i].length; j++){
    
    if(role[0] == i && role[1] == j){
      
      tmp += '* ';
      
    }else {
      
      tmp += maps[i][j] + ' ';     
      
    }
    
  }
  console.log(tmp);
  
}
  
}


document.onkeydown=function(event){
  var e = event || window.event || arguments.callee.caller.arguments[0];
  
  if(e && e.keyCode==37){ //
    up(1);
  }
  if(e && e.keyCode==38){ //
    up(2);
  }            
  if(e && e.keyCode==39){ //
    up(3);
  }            
  if(e && e.keyCode==40){ //
    up(4);
  }
  
}; 

 

posted @ 2018-06-30 17:38  大赚佬  阅读(157)  评论(0编辑  收藏  举报