0

此代码不会打印我们的 roomC,而是返回 nan 我已通过代码追溯并确定该代码

var minR = (Game.height * Game.width) / 300;
var maxR = (Game.height * Game.width) /150;

导致 nan 发生在这里是代码的全部,任何帮助将不胜感激!

Game = {


mapG:{
    width: 75,
    height: 50,
    tile:{
        width: 10,
        height: 10
    }
},


width: function() {
 return this.mapG.width * this.mapG.tile.width;
},


height: function() {
  return this.mapG.height * this.mapG.tile.height;
},

start: function() {

var minR = (Game.height * Game.width) / 300;
var maxR = (Game.height * Game.width) /150;
var range = maxR - minR + 1;
var roomC = Math.floor((Math.random()*maxR)+minR);

//#3L11Tw0w0w0w0
Crafty.init(Game.width(), Game.height());
Crafty.background('rgb(6, 38, 111)');

var map =[];
for(var x = 0; x < 100; x++){
    map[x] = [];
    for(var y = 0; y < 100; y++){
       map[x][y] = x*y;
   }


  }



console.log(map[10][11]);
    //Need this to print out!
console.log(roomC);
}

}
4

1 回答 1

2

错误是当您调用函数宽度和高度时。你需要这样称呼他们:

var minR = (Game.height() * Game.width()) / 300;
var maxR = (Game.height() * Game.width()) /150;

我认为这应该可以解决问题。

于 2013-04-23T14:21:26.670 回答