public void DrawMap(MapObject[][] map) { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.ClearColor(Color.Black); for (int i = 0; i < map.Length; i++) for (int j = 0; j < map[i].Length; j++) { MapTextureSwitcher(j, i, map[i][j].Type); } }
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; } }
/// <summary> /// Classical mode (one team defends its base, another one attacks trying to destroy the base) /// </summary> public MapObject[][] generateCLASSIC_Map() { while (true) { makeConcreteMap(); //clearing space for base map[0][9] = new MapObject(0, 9, MapObject.Types.EMPTY); if (rnd.Next(0, 2) == 0) addWaterOnMap(); //Water on map 50% if (isMapGood()) break; } //adding base map[0][9] = new MapObject(0, 9, MapObject.Types.BASE); //adding bricks if (map[0][9 - 1].Type == MapObject.Types.EMPTY) map[0][9 - 1] = new MapObject(0, 9 - 1, MapObject.Types.BRICK); if (map[0][9 + 1].Type == MapObject.Types.EMPTY) map[0][9 + 1] = new MapObject(0, 9 + 1, MapObject.Types.BRICK); for (int i = 8; i <= 10; i++) if (map[1][i].Type == MapObject.Types.EMPTY) map[1][i] = new MapObject(1, i, MapObject.Types.BRICK); addBricksOnMap(); addForestOnMap(); return map; }
public void DrawMapPart(int x, int y, MapObject.Types type) { MapTextureSwitcher(x, y, type); }
private void MapTextureSwitcher(int mapPartX, int mapPartY, MapObject.Types type) { switch (type) { case MapObject.Types.EMPTY: DrawMapPart(mapPartX, mapPartY, 0); break; case MapObject.Types.BRICK: DrawMapPart(mapPartX, mapPartY, 1); break; case MapObject.Types.CONCRETE: DrawMapPart(mapPartX, mapPartY, 2); break; case MapObject.Types.WATER: DrawMapPart(mapPartX, mapPartY, 3); break; case MapObject.Types.FOREST: DrawMapPart(mapPartX, mapPartY, 4); break; case MapObject.Types.BASE: DrawMapPart(mapPartX, mapPartY, 5); break; } }
private MapObject[][] rotateStaticElement(MapObject[][] element) { MapObject[][] tmp = new[] { new MapObject[3], new MapObject[3], new MapObject[3] }; for (int i = 0; i < element.Length; i++) for (int j = 0; j < element[i].Length; j++) tmp[i][j] = element[2 - j][i]; return tmp; }
private void objectInit() { //initialize mapInfo for (int i = 0; i < map.Length; i++) map[i] = new MapObject[19]; //initialize elementsInfo MapObject[][] element = new[] { new[] { new MapObject(0, 0, MapObject.Types.EMPTY), new MapObject(0, 1, MapObject.Types.CONCRETE), new MapObject(0, 2, MapObject.Types.CONCRETE) }, new[] { new MapObject(1, 0, MapObject.Types.EMPTY), new MapObject(1, 1, MapObject.Types.CONCRETE), new MapObject(1, 2, MapObject.Types.EMPTY) }, new[] { new MapObject(2, 0, MapObject.Types.EMPTY), new MapObject(2, 1, MapObject.Types.CONCRETE), new MapObject(2, 2, MapObject.Types.EMPTY) } }; listOfStaticElements.Add(element); element = new[] { new[] { new MapObject(0, 0, MapObject.Types.EMPTY), new MapObject(0, 1, MapObject.Types.EMPTY), new MapObject(0, 2, MapObject.Types.EMPTY) }, new[] { new MapObject(1, 0, MapObject.Types.CONCRETE), new MapObject(1, 1, MapObject.Types.CONCRETE), new MapObject(1, 2, MapObject.Types.CONCRETE) }, new[] { new MapObject(2, 0, MapObject.Types.EMPTY), new MapObject(2, 1, MapObject.Types.EMPTY), new MapObject(2, 2, MapObject.Types.EMPTY) } }; listOfStaticElements.Add(element); element = new[] { new[] { new MapObject(0, 0, MapObject.Types.EMPTY), new MapObject(0, 1, MapObject.Types.EMPTY), new MapObject(0, 2, MapObject.Types.EMPTY) }, new[] { new MapObject(1, 0, MapObject.Types.EMPTY), new MapObject(1, 1, MapObject.Types.CONCRETE), new MapObject(1, 2, MapObject.Types.CONCRETE) }, new[] { new MapObject(2, 0, MapObject.Types.EMPTY), new MapObject(2, 1, MapObject.Types.EMPTY), new MapObject(2, 2, MapObject.Types.EMPTY) } }; listOfStaticElements.Add(element); element = new[] { new[] { new MapObject(0, 0, MapObject.Types.EMPTY), new MapObject(0, 1, MapObject.Types.CONCRETE), new MapObject(0, 2, MapObject.Types.EMPTY) }, new[] { new MapObject(1, 0, MapObject.Types.CONCRETE), new MapObject(1, 1, MapObject.Types.CONCRETE), new MapObject(1, 2, MapObject.Types.CONCRETE) }, new[] { new MapObject(2, 0, MapObject.Types.EMPTY), new MapObject(2, 1, MapObject.Types.CONCRETE), new MapObject(2, 2, MapObject.Types.EMPTY) } }; listOfStaticElements.Add(element); element = new[] { new[] { new MapObject(0, 0, MapObject.Types.EMPTY), new MapObject(0, 1, MapObject.Types.EMPTY), new MapObject(0, 2, MapObject.Types.EMPTY) }, new[] { new MapObject(1, 0, MapObject.Types.EMPTY), new MapObject(1, 1, MapObject.Types.CONCRETE), new MapObject(1, 2, MapObject.Types.CONCRETE) }, new[] { new MapObject(2, 0, MapObject.Types.EMPTY), new MapObject(2, 1, MapObject.Types.CONCRETE), new MapObject(2, 2, MapObject.Types.EMPTY) } }; listOfStaticElements.Add(element); }
private void makeConcreteMap() { MapObject[][] partMap = new MapObject[10][]; MapObject[][] halfMap = new MapObject[20][]; for (int i = 0; i < partMap.Length; i++) partMap[i] = new MapObject[9]; for (int i = 0; i < halfMap.Length; i++) halfMap[i] = new MapObject[9]; //"clear" map for (int i = 0; i < partMap.Length; i++) for (int j = 0; j < partMap[i].Length; j++) partMap[i][j] = new MapObject(i, j, MapObject.Types.EMPTY); #region Fill part of a map (1/4) for (int i = 1; i < partMap.Length - 1; i++) for (int j = 1; j < partMap[i].Length - 1; j++) if (isEmptyBox(partMap, i, j)) if (rnd.Next(0, 4) == 0) //should be element be added { MapObject[][] element = getRandomElementFromListOfStaticElements(); addConcreteStaticElementOnMap(partMap, element, i, j); } #endregion Fill part of a map (1/4) #region Mirror of a part map (1/2) (LEFT PART OF MAP) for (int i = 0; i < partMap.Length; i++) for (int j = 0; j < partMap[i].Length; j++) { halfMap[i][j] = new MapObject(i, j, partMap[i][j].Type); halfMap[halfMap.Length - 1 - i][j] = new MapObject(halfMap.Length - 1 - i, j, partMap[i][j].Type); } #endregion Mirror of a part map (1/2) (LEFT PART OF MAP) #region Mirror of a part map (2/2) (FULL MAP) for (int i = 0; i < halfMap.Length; i++) for (int j = 0; j < halfMap[i].Length; j++) { map[i][j] = new MapObject(i, j, halfMap[i][j].Type); map[i][map[i].Length - 1 - j] = new MapObject(i, map[i].Length - 1 - j, halfMap[i][j].Type); } #endregion Mirror of a part map (2/2) (FULL MAP) //adding middle line for (int i = 0; i < map.Length; i++) { MapObject[] t = map[i]; t[9] = t[8].Type == MapObject.Types.CONCRETE ? new MapObject(i, 9, MapObject.Types.CONCRETE) : new MapObject(i, 9, MapObject.Types.EMPTY); } }
private bool isMapGood() { bool foundEmpty = true; //initialize MapObject[][] tmpMap = new MapObject[22][]; for (int i = 0; i < tmpMap.Length; i++) tmpMap[i] = new MapObject[21]; //Setting each element to 'c' for (int i = 0; i < tmpMap.Length; i++) for (int j = 0; j < tmpMap[i].Length; j++) tmpMap[i][j] = new MapObject(i, j, MapObject.Types.CONCRETE); //Adding map to tmpMap for (int i = 0; i < map.Length; i++) for (int j = 0; j < map[i].Length; j++) tmpMap[i + 1][j + 1] = new MapObject(i + 1, j + 1, map[i][j].Type); //Check if 'C' in middle line bool concreteBreak = false; for (int i = 1; i < tmpMap.Length - 1; i++) { if (tmpMap[i][10].Type == 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].Type == 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].Type != MapObject.Types.EMPTY) while (tmpMap[x][y].Type != MapObject.Types.EMPTY) { x = rnd.Next(0, 20); y = rnd.Next(0, 21); } tmpMap[x][y].Type = MapObject.Types.TEMPORARY; //Setting to check every Close 'E' to check, added before 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].Type == MapObject.Types.TEMPORARY) { if (tmpMap[i - 1][j].Type == MapObject.Types.EMPTY) { tmpMap[i - 1][j].Type = MapObject.Types.TEMPORARY; foundEmpty = true; } if (tmpMap[i + 1][j].Type == MapObject.Types.EMPTY) { tmpMap[i + 1][j].Type = MapObject.Types.TEMPORARY; foundEmpty = true; } if (tmpMap[i][j - 1].Type == MapObject.Types.EMPTY) { tmpMap[i][j - 1].Type = MapObject.Types.TEMPORARY; foundEmpty = true; } if (tmpMap[i][j + 1].Type == MapObject.Types.EMPTY) { tmpMap[i][j + 1].Type = MapObject.Types.TEMPORARY; foundEmpty = true; } } } foreach (MapObject[] t in tmpMap) foreach (MapObject t1 in t) if (t1.Type == MapObject.Types.EMPTY) foundEmpty = true; return !foundEmpty; }
/// <summary> /// Is element proper to current position /// </summary> /// <param name="map">Current Map</param> /// <param name="x">Current X</param> /// <param name="y">Current Y</param> /// <returns>true - map is good</returns> private bool isEmptyBox(MapObject[][] map, int x, int y) { if (map[x - 1][y - 1].Type == MapObject.Types.EMPTY) if (map[x - 1][y].Type == MapObject.Types.EMPTY) if (map[x - 1][y + 1].Type == MapObject.Types.EMPTY) if (map[x][y - 1].Type == MapObject.Types.EMPTY) if (map[x][y].Type == MapObject.Types.EMPTY) if (map[x][y + 1].Type == MapObject.Types.EMPTY) if (map[x + 1][y - 1].Type == MapObject.Types.EMPTY) if (map[x + 1][y].Type == MapObject.Types.EMPTY) if (map[x + 1][y + 1].Type == MapObject.Types.EMPTY) return true; return false; }
private void addConcreteStaticElementOnMap(MapObject[][] map, MapObject[][] element, int x, int y) { for (int i = 0; i < element.Length; i++) for (int j = 0; j < element[i].Length; j++) map[x - 1 + i][y - 1 + j] = new MapObject(x - 1 + i, y - 1 + j, element[i][j].Type); }
public Map LoadMap(String filePath) { int x,y; mapObjects = new MapObject[20][]; for (int i = 0; i < mapObjects.Length; i++) mapObjects[i] = new MapObject[19]; MapObject obj; String tempStr; reader = new XmlTextReader(filePath); reader.WhitespaceHandling = WhitespaceHandling.None; //skipping empty nodes while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (reader.Name == "mode") { tempStr = reader.GetAttribute("name"); switch (tempStr) { case "CLASSIC": mode = new GameMode(GameMode.Mode.CLASSIC); break; case "TDM": mode = new GameMode(GameMode.Mode.TDM); break; case "TDMB": mode = new GameMode(GameMode.Mode.TDMB); break; case "DM": mode = new GameMode(GameMode.Mode.DM); break; } } if (reader.Name == "element") { x = int.Parse(reader.GetAttribute("x")); y = int.Parse(reader.GetAttribute("y")); tempStr = reader.GetAttribute("type"); switch (tempStr) { case "EMPTY": obj = new MapObject(x, y, MapObject.Types.EMPTY); mapObjects[x][y] = obj; break; case "BRICK": obj = new MapObject(x, y, MapObject.Types.BRICK); mapObjects[x][y] = obj; break; case "CONCRETE": obj = new MapObject(x, y, MapObject.Types.CONCRETE); mapObjects[x][y] = obj; break; case "WATER": obj = new MapObject(x, y, MapObject.Types.WATER); mapObjects[x][y] = obj; break; case "FOREST": obj = new MapObject(x, y, MapObject.Types.FOREST); mapObjects[x][y] = obj; break; case "BASE": obj = new MapObject(x, y, MapObject.Types.BASE); mapObjects[x][y] = obj; break; } } } } reader.Close(); map = new Map(mapObjects); return map; }
public Map(MapObject[][] content) { map = content; }
public Map LoadMap(String filePath) { int x, y; mapObjects = new MapObject[20][]; for (int i = 0; i < mapObjects.Length; i++) { mapObjects[i] = new MapObject[19]; } MapObject obj; String tempStr; reader = new XmlTextReader(filePath); reader.WhitespaceHandling = WhitespaceHandling.None; //skipping empty nodes while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (reader.Name == "mode") { tempStr = reader.GetAttribute("name"); switch (tempStr) { case "CLASSIC": mode = new GameMode(GameMode.Mode.CLASSIC); break; case "TDM": mode = new GameMode(GameMode.Mode.TDM); break; case "TDMB": mode = new GameMode(GameMode.Mode.TDMB); break; case "DM": mode = new GameMode(GameMode.Mode.DM); break; } } if (reader.Name == "element") { x = int.Parse(reader.GetAttribute("x")); y = int.Parse(reader.GetAttribute("y")); tempStr = reader.GetAttribute("type"); switch (tempStr) { case "EMPTY": obj = new MapObject(x, y, MapObject.Types.EMPTY); mapObjects[x][y] = obj; break; case "BRICK": obj = new MapObject(x, y, MapObject.Types.BRICK); mapObjects[x][y] = obj; break; case "CONCRETE": obj = new MapObject(x, y, MapObject.Types.CONCRETE); mapObjects[x][y] = obj; break; case "WATER": obj = new MapObject(x, y, MapObject.Types.WATER); mapObjects[x][y] = obj; break; case "FOREST": obj = new MapObject(x, y, MapObject.Types.FOREST); mapObjects[x][y] = obj; break; case "BASE": obj = new MapObject(x, y, MapObject.Types.BASE); mapObjects[x][y] = obj; break; } } } } reader.Close(); map = new Map(mapObjects); return(map); }
public Map(MapObject[][] content) { this.map = content; }