此代码不会打印我们的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);
}
}
答案 0 :(得分:2)
错误是在调用函数宽度和高度时。你需要这样称呼它们:
var minR = (Game.height() * Game.width()) / 300;
var maxR = (Game.height() * Game.width()) /150;
我认为这应该可以解决问题。