public override Map Generate(int width, int height) { if (width > Map.MAX_WIDTH || height > Map.MAX_HEIGHT) { throw new ArgumentOutOfRangeException("Map too big"); } Map map = new Map(width, height); TownCell cell = new TownCell(map); cell.GenerateTown(); this.map = map; return(map); }
void split() { splitOrientation = chooseSplit(); if (splitOrientation == SplitOrientation.Horizontal) { int r = Rng.Random.Next(width - 2 * MIN_CELL_SIZE); r = r + MIN_CELL_SIZE; child1 = new TownCell(map, this); child1.x1 = x1; child1.y1 = y1; child1.x2 = x1 + r; child1.y2 = y2; child2 = new TownCell(map, this); child2.x1 = x1 + r; child2.y1 = y1; child2.x2 = x2; child2.y2 = y2; } if (splitOrientation == SplitOrientation.Vertical) { int r = Rng.Random.Next(height - 2 * MIN_CELL_SIZE); r = r + MIN_CELL_SIZE; child1 = new TownCell(map, this); child1.x1 = x1; child1.y1 = y1; child1.x2 = x2; child1.y2 = y1 + r; child2 = new TownCell(map, this); child2.x1 = x1; child2.y1 = y1 + r; child2.x2 = x2; child2.y2 = y2; } if (child1.canSplit) { child1.split(); } if (child2.canSplit) { child2.split(); } }
public TownCell(Map map, TownCell parent) { splitOrientation = SplitOrientation.None; this.map = map; this.parent = parent; }