public void ChekForEnemy() { if (GameField.matrix[this.PosY - 1, this.PosX - 1] == "D" || GameField.matrix[this.PosY, this.PosX - 1] == "D" || GameField.matrix[this.PosY + 1, this.PosX - 1] == "D" || GameField.matrix[this.PosY + 2, this.PosX - 1] == "D" || GameField.matrix[this.PosY + 3, this.PosX - 1] == "D" || GameField.matrix[this.PosY - 1, this.PosX] == "D" || GameField.matrix[this.PosY, this.PosX] == "D" || GameField.matrix[this.PosY + 1, this.PosX] == "D" || GameField.matrix[this.PosY + 2, this.PosX] == "D" || GameField.matrix[this.PosY + 3, this.PosX] == "D" || GameField.matrix[this.PosY - 1, this.PosX + 1] == "D" || GameField.matrix[this.PosY, this.PosX + 1] == "D" || GameField.matrix[this.PosY + 1, this.PosX + 1] == "D" || GameField.matrix[this.PosY + 2, this.PosX + 1] == "D" || GameField.matrix[this.PosY + 3, this.PosX + 1] == "D" || GameField.matrix[this.PosY - 1, this.PosX + 2] == "D" || GameField.matrix[this.PosY, this.PosX + 2] == "D" || GameField.matrix[this.PosY + 1, this.PosX + 2] == "D" || GameField.matrix[this.PosY + 2, this.PosX + 2] == "D" || GameField.matrix[this.PosY + 3, this.PosX + 2] == "D" || GameField.matrix[this.PosY - 1, this.PosX + 3] == "D" || GameField.matrix[this.PosY, this.PosX + 3] == "D" || GameField.matrix[this.PosY + 1, this.PosX + 3] == "D" || GameField.matrix[this.PosY + 2, this.PosX + 3] == "D" || GameField.matrix[this.PosY + 3, this.PosX + 3] == "D") { Player.Health -= 2; SideInfo.PrintInfo(); } }
private void LevelUpdate() { this.currLevel = Entity.Level; if (Entity.Exp > this.expStep) { Entity.Level += 1; this.bombsCounter = 1; SideInfo.PrintInfo(); expStep += Entity.Exp; } if (Entity.Level > currLevel) { Entity.Health += Entity.Level * 100; } }
public static bool CheckSymbolCollision(Entity entity, string direction) { int matrixPosX; int matrixPosY; try { matrixPosX = entity.CollisionCheck(entity.PosX, entity.PosY, entity.SizeX, entity.SizeY, direction)[0]; matrixPosY = entity.CollisionCheck(entity.PosX, entity.PosY, entity.SizeX, entity.SizeY, direction)[1]; } catch (Exception e) { return(false); } switch (GameField.matrix[matrixPosX, matrixPosY]) { case "@": Player.Health += HealthCollectable.bonusHealth; break; case "$": Player.Exp += ExperienceCollectable.bonusExp; break; case "B": Player.bombs += BombCollectable.bombs; break; case "*": Player.Points += BonusCollectable.bonusPoints; break; default: return(false); } GameField.matrix[matrixPosX, matrixPosY] = " "; Utilities.PrintStringOnPositon(matrixPosY, matrixPosX, " "); SideInfo.PrintInfo(); return(true); }
public void MovePlayer() { if (Console.KeyAvailable) { ConsoleKeyInfo pressedKey = Console.ReadKey(true); while (Console.KeyAvailable) { Console.ReadKey(true); } if (pressedKey.Key == ConsoleKey.LeftArrow) { string direction = "left"; if (CollisionCheck(this.PosX, this.PosY, this.SizeX, this.SizeY, direction).Length == 0) { this.PosX -= 1; ClearTrace(); } else { if (Collectable.CheckSymbolCollision(this, direction)) { Collectable.CheckSymbolCollision(this, direction); this.PosX -= 1; ClearTrace(); } else { Utilities.PrintStringOnPositon(143, 2, "<", ConsoleColor.Red); } } } else if (pressedKey.Key == ConsoleKey.RightArrow) { string direction = "right"; if (CollisionCheck(this.PosX, this.PosY, this.SizeX, this.SizeY, direction).Length == 0) { this.PosX += 1; ClearTrace(); } else { if (Collectable.CheckSymbolCollision(this, direction)) { Collectable.CheckSymbolCollision(this, direction); this.PosX += 1; ClearTrace(); } else { Utilities.PrintStringOnPositon(145, 2, ">", ConsoleColor.Red); } } } else if (pressedKey.Key == ConsoleKey.UpArrow) { string direction = "up"; if (CollisionCheck(this.PosX, this.PosY, this.SizeX, this.SizeY, direction).Length == 0) { this.PosY -= 1; ClearTrace(); } else { if (Collectable.CheckSymbolCollision(this, direction)) { Collectable.CheckSymbolCollision(this, direction); this.PosY -= 1; ClearTrace(); } else { Utilities.PrintStringOnPositon(144, 1, "^", ConsoleColor.Red); } } } else if (pressedKey.Key == ConsoleKey.DownArrow) { string direction = "down"; if (CollisionCheck(this.PosX, this.PosY, this.SizeX, this.SizeY, direction).Length == 0) { this.PosY += 1; ClearTrace(); } else { if (Collectable.CheckSymbolCollision(this, direction)) { Collectable.CheckSymbolCollision(this, direction); this.PosY += 1; ClearTrace(); } else { Utilities.PrintStringOnPositon(144, 3, "v", ConsoleColor.Red); } } } else if (pressedKey.Key == ConsoleKey.Enter && this.bombsCounter <= Entity.Level && Player.bombs > 0) { this.bombsCounter += 1; Bomb.NewBomb(this.PosY + 2, this.PosX + 3); SideInfo.PrintInfo(); } DrawPlayer(); } }
public static void Main() { int bufferHeight = 40; int bufferWidth = 170; // Setting the parameters of the Console Console.BufferHeight = bufferHeight; Console.BufferWidth = bufferWidth; Console.WindowHeight = bufferHeight; Console.WindowWidth = bufferWidth; Console.CursorVisible = false; GameField gameField = new GameField(); List <Enemy> dragons = new List <Enemy>() { new DragonEnemy(), new DragonEnemy(), new DragonEnemy(), new DragonEnemy(), new DragonEnemy(), new DragonEnemy(), new DragonEnemy(), new DragonEnemy(), new DragonEnemy() }; for (int col = 0; col < GameField.matrix.GetLength(0); col++) { for (int row = 0; row < GameField.matrix.GetLength(1); row++) { Console.Write(GameField.matrix[col, row]); } Console.WriteLine(); } Gate gate = new Gate(33, 1, "R", ConsoleColor.Red); gate.DrawGate(); Collectable[] healthCollectables = new HealthCollectable(0, 0).GenerateCollectables(5); Collectable[] experienceCollectables = new ExperienceCollectable(0, 0).GenerateCollectables(5); Collectable[] gunCollectables = new BombCollectable(0, 0).GenerateCollectables(5); Collectable[] bonusCollectables = new BonusCollectable(0, 0).GenerateCollectables(5); Collectable[][] allCollectables = { healthCollectables, experienceCollectables, gunCollectables, bonusCollectables }; for (int i = 0; i < allCollectables.Length; i++) { for (int j = 0; j < allCollectables[i].Length; j++) { allCollectables[i][j].drawCollectable(); } } Player tempPlayer = new Player(); tempPlayer.DrawPlayer(); SideInfo.PrintInfo(); while (tempPlayer.isAlive) { tempPlayer.MovePlayer(); foreach (Enemy dragon in dragons) { dragon.MoveEnemy(); tempPlayer.ChekForEnemy(); } } SideInfo.GameOver(); }