public Generator(int size, uint cityId) { rand = new Random(); city = new Block[20, 20]; seed = new Block.IdGenerator(cityId); CitySquareBlock centerBlock = new CitySquareBlock(rand, seed, city, 10, 10); centerBlock.Generate(rand, 75); centerBlock.GenerateCityBuildings(rand); //for (int y = 0; y < city.GetLength(1); y++) { // for (int x = 0; x < city.GetLength(0); x++) { // Block block = city[x, y]; // if (block != null) // Console.Write(block.StrShape); // else // Console.Write(" "); // //CitySquareBlock sqBlock = block as CitySquareBlock; // //if (sqBlock != null) { // // Console.Write("+"); // //} else { // // StreetBlock sBlock = block as StreetBlock; // // if (sBlock != null) { // // Console.Write((sBlock.Orientation == Orientation.Vertical) ? "|" : "-"); // // } else { // // CityBuildingBlock bBlock = block as CityBuildingBlock; // // if (bBlock != null) { // // Console.Write("#"); // // } else // // Console.Write(" "); // // } // //} // } // Console.WriteLine(); //} }
public override void Generate(Random rand, int prob) { if (this.Orientation == Generator.Orientation.Vertical) { this.North = GetBlockAt(this.X, this.Y - 1); if (North == null && rand.Next(0, 100) < prob && IsInsideCity(this.X, this.Y - 1)) { North = new CitySquareBlock(rand, this.IdSeed, City, this.X, this.Y - 1); North.Generate(rand, prob - 1); } this.South = GetBlockAt(this.X, this.Y + 1); if (South == null && rand.Next(0, 100) < prob && IsInsideCity(this.X, this.Y + 1)) { South = new CitySquareBlock(rand, this.IdSeed, City, this.X, this.Y - 1); South.Generate(rand, prob - 1); } //this.East = GetBlockAt(this.X + 1, this.Y); //if (East == null && rand.Next(0, 100) < prob && IsInsideCity(this.X + 1, this.Y)) { // East = new CitySquareBlock(rand, City, this.X + 1, this.Y); // East.Generate(rand, prob - 1); //} //this.West = GetBlockAt(this.X - 1, this.Y); //if (West == null && rand.Next(0, 100) < prob && IsInsideCity(this.X - 1, this.Y)) { // West = new CitySquareBlock(rand, City, this.X - 1, this.Y); // West.Generate(rand, prob - 1); //} } if (this.Orientation == Generator.Orientation.Horizontal) { //this.North = GetBlockAt(this.X, this.Y - 1); //if (North == null && rand.Next(0, 100) < prob && IsInsideCity(this.X, this.Y - 1)) { // North = new CitySquareBlock(rand, City, this.X, this.Y - 1); // North.Generate(rand, prob - 1); //} //this.South = GetBlockAt(this.X, this.Y + 1); //if (South == null && rand.Next(0, 100) < prob && IsInsideCity(this.X, this.Y + 1)) { // South = new CitySquareBlock(rand, City, this.X, this.Y - 1); // South.Generate(rand, prob - 1); //} this.East = GetBlockAt(this.X + 1, this.Y); if (East == null && rand.Next(0, 100) < prob && IsInsideCity(this.X + 1, this.Y)) { East = new CitySquareBlock(rand, this.IdSeed, City, this.X + 1, this.Y); East.Generate(rand, prob - 1); } this.West = GetBlockAt(this.X - 1, this.Y); if (West == null && rand.Next(0, 100) < prob && IsInsideCity(this.X - 1, this.Y)) { West = new CitySquareBlock(rand, this.IdSeed, City, this.X - 1, this.Y); East.Generate(rand, prob - 1); } } }