public Collision(Element[,] mapElements) { this.mapElements = mapElements; int width = Data.GetWindowWidth(); int height = Data.GetWindowHeight(); this.render = new ConsoleRender(width, height); }
public static void SaveLevel(Element[,] elements) { int levelNumber = GetNumberOfLevels() + 1; SetNumberOfLevels(levelNumber); Directory.CreateDirectory("Levels"); string path = "Levels\\level" + levelNumber.ToString() + ".city"; BinaryFormatter serializer = new BinaryFormatter(); using (FileStream stream = File.OpenWrite(path)) { serializer.Serialize(stream, elements); } }
public void DeleteElement(Element element) { Console.BackgroundColor = ConsoleColor.White; string str = new string(' ', element.Dimention); Console.CursorVisible = false; for (int row = 0; row < element.Dimention; row++) { for (int col = 0; col < element.Dimention; col++) { Console.SetCursorPosition(element.Column + col, element.Row + row); Console.Write(str[col]); } } }
public Level(string fileName) { //параметърът ще е името на файла, от който зареждаме string[] lines = System.IO.File.ReadAllLines(fileName); CurrentLevel = new Element[40, 10]; for (int currentRow = 0; currentRow < lines.Length; currentRow += 3) { string line = lines[currentRow]; for (int currentCol = 0; currentCol < line.Length; currentCol += 3) { char symbol = line[currentCol]; ElementType currentElementType = ElementType.Wother; switch (symbol) { case '~': currentElementType = ElementType.Wother; break; case '#': currentElementType = ElementType.Steel; break; case 'W': currentElementType = ElementType.Braket; break; case 'e': currentElementType = ElementType.Eagle; break; case ' ': currentElementType = ElementType.Empty; break; default: break; } Element currentElement = new Element(currentElementType, currentRow % 3, currentCol % 3); // % 3 защото всеки символ на картата е таблица 3 х 3 CurrentLevel[currentCol % 3, currentRow % 3] = currentElement; currentCol++; } currentRow++; } }
public void DrawElement(Element element) { switch (element.Type) { case ElementType.Wother: DrowWater(element); break; case ElementType.Braket: DrowBraket(element); break; case ElementType.Steel: DrowSteel(element); break; case ElementType.Eagle: DrowEagle(element); break; case ElementType.Empty: DeleteElement(element); break; default: break; } }
public static Element[,] CreateLevel() { Initialisation(); elements = new Element[rowsByDimention, colsByDimention]; // insert eagle eagleRowLevelCordinate = rowsByDimention - 1; eagleColLevelCordinate = (colsByDimention - 1) / 2; int eagleRow = eagleRowLevelCordinate * changeDistance + minRow; int eagleCol = eagleColLevelCordinate * changeDistance; Element eagle = new Element(ElementType.Eagle, eagleRow, eagleCol); elements[eagleRowLevelCordinate, eagleColLevelCordinate] = eagle; render.DrawElement(eagle); return Create(); }
public bool DoesItCollideTank(Element elemPos, Tank tank, int tankRow, int tankCol) { bool collidesDoes = false; for (int t = -1; t < 2; t++) { for (int k = -1; k < 2; k++) { for (int i = -1; i < 2; i++) { for (int j = -1; j < 2; j++) { if ((elemPos.Row + i == tankRow + t) && (elemPos.Column + j == tankCol + k)) { collidesDoes = true; } } } } } return collidesDoes; }
public bool DoesItCollideFire(Element elemPos, int fireRow, int fireCol) { bool collidesDoes = false; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if ((elemPos.Row + i == fireRow) && (elemPos.Column + j == fireCol)) { collidesDoes = true; } } } return collidesDoes; }
private void DrowWater(Element water) { Console.ForegroundColor = ConsoleColor.Blue; Console.BackgroundColor = ConsoleColor.White; string str = new string('~', water.Dimention); for (int row = 0; row < water.Dimention; row++) { for (int col = 0; col < water.Dimention; col++) { Console.SetCursorPosition(water.Column + col, water.Row + row); Console.Write(str[col]); } } Console.ResetColor(); }
private void DrowSteel(Element steel) { Console.ForegroundColor = ConsoleColor.DarkGray; Console.BackgroundColor = ConsoleColor.White; string str = new string('#', steel.Dimention); for (int row = 0; row < steel.Dimention; row++) { for (int col = 0; col < steel.Dimention; col++) { Console.SetCursorPosition(steel.Column + col, steel.Row + row); Console.Write(str[col]); } } Console.ResetColor(); }
private void DrowEagle(Element eagle) { Console.ForegroundColor = ConsoleColor.Red; Console.BackgroundColor = ConsoleColor.White; Console.SetCursorPosition(eagle.Column, eagle.Row); Console.Write(" @ "); Console.SetCursorPosition(eagle.Column, eagle.Row + 1); Console.Write("<O>"); Console.SetCursorPosition(eagle.Column, eagle.Row + 2); Console.Write("/ \\"); Console.ResetColor(); }
private void DrowBraket(Element braket) { Console.ForegroundColor = ConsoleColor.DarkRed; Console.BackgroundColor = ConsoleColor.White; string str = new string('W' , braket.Dimention); for (int row = 0; row < braket.Dimention; row++) { for (int col = 0; col < braket.Dimention; col++) { Console.SetCursorPosition(braket.Column + col, braket.Row + row); Console.Write(str[col]); } } Console.ResetColor(); }
public void Level(Element[,] elements) { WhiteGameFild(); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Red; for (int row = 0; row < elements.GetLength(0); row++) { for (int col = 0; col < elements.GetLength(1); col++) { if (elements[row, col] != null) { DrawElement(elements[row, col]); } } } Console.ResetColor(); }
private static void Initialisation() { int dimention = Data.GetElementDimention(); int height = Data.GetWindowHeight(); minRow = 2; rowsByDimention = (height - minRow) / dimention; colsByDimention = (Data.GetWindowWidth() - 1) / dimention; maxRow = height; minCol = 0; maxCol = Data.GetWindowWidth() - 1; currentElementRow = minRow; currenElementCol = minCol; isExit = false; currentElementType = ElementType.Empty; changeDistance = Data.GetElementDimention(); render = new ConsoleRender(Data.GetWindowWidth(), height); currentElementType = ElementType.Braket; element = new Element(currentElementType, minRow, minCol); ShowElement(); }
private static void CreateElement() { element = new Element(currentElementType, currentElementRow, currenElementCol); ShowElement(); }