private void InitCell(Point point, char c) { KilledAntsMap[point] = new List<Cell>(); if (c >= '0' && c <= '9') { int command = c - '0'; var hill = new Hill(point, command, this); Armies[command].Hills.Add(hill); OriginalMap[point] = hill; ObjectsMap[point] = new Empty(point, this); } else if (c >= 'a' && c <= 'j') { int command = c - 'a'; var ant = new Ant(point, command, this); Armies[command].Ants.Add(ant); OriginalMap[point] = new UnMovableCell(point, Cell.CellType.Land, this); ObjectsMap[point] = ant; } else if (c >= 'A' && c <= 'J') { int command = c - 'A'; var hill = new Hill(point, command, this); Armies[command].Hills.Add(hill); var ant = new Ant(point, command, this); Armies[command].Ants.Add(ant); OriginalMap[point] = hill; ObjectsMap[point] = ant; } else if (c == '*') { var food = new Food(point, this); Food.Add(food); OriginalMap[point] = new UnMovableCell(point, Cell.CellType.Land, this); ObjectsMap[point] = food; } else if (c == '!') { OriginalMap[point] = new UnMovableCell(point, Cell.CellType.Land, this); ObjectsMap[point] = new Empty(point, this); KilledAntsMap[point].Add(new Ant(point, -1, this).GetDead()); } else if (c == '%') { OriginalMap[point] = new UnMovableCell(point, Cell.CellType.Water, this); ObjectsMap[point] = new Empty(point, this); } else if (c == '.') { OriginalMap[point] = new UnMovableCell(point, Cell.CellType.Land, this); ObjectsMap[point] = new Empty(point, this); } else { OriginalMap[point] = new UnMovableCell(point, Cell.CellType.Unseen, this); ObjectsMap[point] = new Empty(point, this); } }
public void FoodGeneration(double prob) { prob -= Rndom.NextDouble(); while (prob >= 0) { bool foodPlaced = false; while (!foodPlaced) { int dx = Rndom.Next(Width); int dy = Rndom.Next(Height); var dPoint = new Point(dx, dy); var d2Point = YSymmetrical ? new Point(dx, -dy, Width, Height) : new Point(dx, dy, Width, Height); if (OriginalMap[Hills[0].Coords + dPoint].Type != Cell.CellType.Land) continue; foreach (var hill in Hills) { var newPoint = hill.Coords.Y < Height / 2 ? hill.Coords + dPoint : hill.Coords + d2Point; if (ObjectsMap[newPoint].Type == Cell.CellType.Empty) { var food = new Food(newPoint, this); ObjectsMap[newPoint] = food; Food.Add(food); } } foodPlaced = true; } prob -= Rndom.NextDouble(); } }