【发布时间】:2014-10-11 01:14:17
【问题描述】:
SetType(type);
for (int x = (Globals.tileSize + (int)position.X); x < ((int)position.X + (Globals.screenWidth - Globals.tileSize)); x += Globals.tileSize)
{
for (int y = (Globals.tileSize + (int)position.Y); y < ((int)position.Y + (Globals.screenHeight - Globals.tileSize)); y += Globals.tileSize)
{
tileType = tileFillTypes[random.Next(1, tileFillTypes.Count())];
Tile tile = new Tile(new Vector2(x, y), tileType, false);
tiles.Add(tile);
}
}
地图生成调用这个类在一个盒子里随机绘制图块。调用 SetType(type) 执行此操作:
void SetType(int type)
{
if (type == 1) //ROOM TYPE
{
tileWallTypesBottom = new string[] { "", "stonewallBottom1", "stonewallBottom2", "stonewallBottom3" };
tileFillTypes = new String[] { "" };
}
else if (type == 2)
{
tileWallTypesBottom = new string[] { "", "stonewallBottom1", "stonewallBottom2", "stonewallBottom3" };
tileWallTypesLeft = new string[] { "", "stonewallLeft1", "stonewallLeft2", "stonewallLeft3" };
tileWallTypesRight = new string[] { "", "stonewallRight1", "stonewallRight2", "stonewallRight3" };
tileWallTypesTop = new string[] { "", "stonewallTop1", "stonewallTop2", "stonewallTop3" };
tileFillTypes = new String[] { "", "dirt1", "dirt1", "dirt1", "dirt1", "dirt1", "dirt1", "dirt1", "dirt1", "dirt1", "dirt2", "dirtGrassPatch", "dirt4", "dirt4", "dirt4", };
tileWallCornerType = new string[] { "", "stonewallTopLeft", "stonewallTopRight", "stonewallBottomRight", "stonewallBottomLeft" };
}
}
这设置了我的数组,我可以从中随机选择哪些图块。 我的问题是,当我在每个房间实例中使用此代码生成多个房间时,房间不会彼此随机出现。我试过设置 random = new Random();在每种情况下,它们始终具有相同的图块输出。
【问题讨论】:
-
不要每次都创建一个新的随机,因为它不会特别随机。 Would you like to know more?