我正在尝试跨数组访问对象值,但每次都显示为未定义。如何让数组“terrain”使用“Dirt”对象变量,例如 SpawnChance?
var terrain = new Array("Dirt1", "Dirt2", "Dirt3");
var Dirt1 = new Object();
Dirt1.Name = 'Dirt1';
Dirt1.Level = '1';
Dirt1.SpawnChance = '70';
var Dirt2 = new Object();
Dirt2.Name = 'Dirt2';
Dirt2.Level = '1';
Dirt2.SpawnChance = '15';
var Dirt3 = new Object();
Dirt3.Name = 'Dirt3';
Dirt3.Level = '1';
Dirt3.SpawnChance = '10';
if ($("#startingblock").hasClass("Dirt1")) {
var blockcount = (Math.floor(Math.random() * 20) + 1) * 2;
var blockcount = blockcount * blockcount;
var i = 0;
while (i < blockcount) {
var randomizer = (Math.floor(Math.random() * 100) + 1);
var terraintypes = terrain.length;
var terrainrandoms = (Math.floor(Math.random() * terraintypes) + 0);
var newrandomterrain = (terrain[terrainrandoms]);
var randomterrainspawnchance = newrandomterrain.SpawnChance;
terrain.push(newrandomterrain);
alert(newrandomterrain);
i++;
}
蝴蝶刀刀
相关分类