public void drawMap(int x, int y, MapObject.Types type) { switch (type) { case MapObject.Types.EMPTY: DrawMapPart(x, y, 0); break; case MapObject.Types.BRICK: DrawMapPart(x, y, 1); break; case MapObject.Types.CONCRETE: DrawMapPart(x, y, 2); break; case MapObject.Types.WATER: DrawMapPart(x, y, 3); break; case MapObject.Types.FOREST: DrawMapPart(x, y, 4); break; case MapObject.Types.BASE: DrawMapPart(x, y, 5); break; } }
private static bool IsMapGood() { //initialize tmpMap with size +2 then map by x and y MapObject.Types[][] tmpMap = new MapObject.Types[22][]; for (int i = 0; i < tmpMap.Length; i++) { tmpMap[i] = new MapObject.Types[21]; } for (int i = 0; i < tmpMap.Length; i++) { for (int j = 0; j < tmpMap[i].Length; j++) { tmpMap[i][j] = MapObject.Types.CONCRETE; //each element = Concrete } } for (int i = 0; i < map.Length; i++) { for (int j = 0; j < map[i].Length; j++) { tmpMap[i + 1][j + 1] = map[i][j].Type; //copy map to tmpMap } } //Check if 'C' in middle line bool concreteBreak = false; for (int i = 3; i < tmpMap.Length - 3; i++) { if (tmpMap[i][10].Equals(MapObject.Types.CONCRETE)) { concreteBreak = true; } } if (!concreteBreak) { return(false); } //Check Concrete blocks count int concreteCount = 0; for (int i = 1; i <= 9; i++) { for (int j = 1; j <= 10; j++) { if (tmpMap[i][j].Equals(MapObject.Types.CONCRETE)) { concreteCount++; } } } if (concreteCount < 25 || concreteCount > 35) { return(false); } //Getting random element with 'E' int x = rnd.Next(5, 16); int y = rnd.Next(5, 16); if (!tmpMap[x][y].Equals(MapObject.Types.EMPTY)) { while (!tmpMap[x][y].Equals(MapObject.Types.EMPTY)) { x = rnd.Next(0, 20); y = rnd.Next(0, 21); } } tmpMap[x][y] = MapObject.Types.TEMPORARY; //Setting to check every Close 'E' to check, added before bool foundEmpty = true; while (foundEmpty) { foundEmpty = false; for (int i = 1; i < tmpMap.Length - 1; i++) { for (int j = 1; j < tmpMap[i].Length - 1; j++) { if (tmpMap[i][j].Equals(MapObject.Types.TEMPORARY)) { if (tmpMap[i - 1][j].Equals(MapObject.Types.EMPTY)) { tmpMap[i - 1][j] = MapObject.Types.TEMPORARY; foundEmpty = true; } if (tmpMap[i + 1][j].Equals(MapObject.Types.EMPTY)) { tmpMap[i + 1][j] = MapObject.Types.TEMPORARY; foundEmpty = true; } if (tmpMap[i][j - 1].Equals(MapObject.Types.EMPTY)) { tmpMap[i][j - 1] = MapObject.Types.TEMPORARY; foundEmpty = true; } if (tmpMap[i][j + 1].Equals(MapObject.Types.EMPTY)) { tmpMap[i][j + 1] = MapObject.Types.TEMPORARY; foundEmpty = true; } } } } } foreach (MapObject.Types[] t in tmpMap) { foreach (MapObject.Types t1 in t) { if (t1.Equals(MapObject.Types.EMPTY)) { foundEmpty = true; } } } return(!foundEmpty); }
private static bool IsMapGood() { //initialize tmpMap with size +2 then map by x and y MapObject.Types[][] tmpMap = new MapObject.Types[22][]; for (int i = 0; i < tmpMap.Length; i++) tmpMap[i] = new MapObject.Types[21]; for (int i = 0; i < tmpMap.Length; i++) for (int j = 0; j < tmpMap[i].Length; j++) tmpMap[i][j] = MapObject.Types.CONCRETE; //each element = Concrete for (int i = 0; i < map.Length; i++) for (int j = 0; j < map[i].Length; j++) tmpMap[i + 1][j + 1] = map[i][j].Type; //copy map to tmpMap //Check if 'C' in middle line bool concreteBreak = false; for (int i = 3; i < tmpMap.Length - 3; i++) if (tmpMap[i][10].Equals(MapObject.Types.CONCRETE)) concreteBreak = true; if (!concreteBreak) return false; //Check Concrete blocks count int concreteCount = 0; for (int i = 1; i <= 9; i++) for (int j = 1; j <= 10; j++) if (tmpMap[i][j].Equals(MapObject.Types.CONCRETE)) concreteCount++; if (concreteCount < 25 || concreteCount > 35) return false; //Getting random element with 'E' int x = rnd.Next(5, 16); int y = rnd.Next(5, 16); if (!tmpMap[x][y].Equals(MapObject.Types.EMPTY)) while (!tmpMap[x][y].Equals(MapObject.Types.EMPTY)) { x = rnd.Next(0, 20); y = rnd.Next(0, 21); } tmpMap[x][y] = MapObject.Types.TEMPORARY; //Setting to check every Close 'E' to check, added before bool foundEmpty = true; while (foundEmpty) { foundEmpty = false; for (int i = 1; i < tmpMap.Length - 1; i++) for (int j = 1; j < tmpMap[i].Length - 1; j++) if (tmpMap[i][j].Equals(MapObject.Types.TEMPORARY)) { if (tmpMap[i - 1][j].Equals(MapObject.Types.EMPTY)) { tmpMap[i - 1][j] = MapObject.Types.TEMPORARY; foundEmpty = true; } if (tmpMap[i + 1][j].Equals(MapObject.Types.EMPTY)) { tmpMap[i + 1][j] = MapObject.Types.TEMPORARY; foundEmpty = true; } if (tmpMap[i][j - 1].Equals(MapObject.Types.EMPTY)) { tmpMap[i][j - 1] = MapObject.Types.TEMPORARY; foundEmpty = true; } if (tmpMap[i][j + 1].Equals(MapObject.Types.EMPTY)) { tmpMap[i][j + 1] = MapObject.Types.TEMPORARY; foundEmpty = true; } } } foreach (MapObject.Types[] t in tmpMap) foreach (MapObject.Types t1 in t) if (t1.Equals(MapObject.Types.EMPTY)) foundEmpty = true; return !foundEmpty; }