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(); } }
static SideInfo() { SideInfo.counter = 10; SideInfo.step = 50; SideInfo.health = 1000; SideInfo.healthBar = new string('█', counter); SideInfo.healthColor = ConsoleColor.DarkGreen; SideInfo.PrintInfoStrings(); }
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 static void PrintInfo() { SideInfo.ClearBar(); SideInfo.health = Entity.Health; SideInfo.counter = Entity.Health / 100; if (SideInfo.counter > 10) { SideInfo.counter = 10; } if (SideInfo.counter < 1) { SideInfo.counter = 1; } SideInfo.healthBar = new string('█', counter); if (SideInfo.counter < 10) { SideInfo.healthColor = ConsoleColor.DarkGreen; } if (SideInfo.counter < 8) { SideInfo.healthColor = ConsoleColor.Green; } if (SideInfo.counter < 6) { SideInfo.healthColor = ConsoleColor.Yellow; } if (SideInfo.counter < 4) { SideInfo.healthColor = ConsoleColor.Red; } if (SideInfo.counter < 2) { SideInfo.healthColor = ConsoleColor.DarkRed; } Utilities.PrintStringOnPositon(158, 6, healthBar, healthColor); Utilities.PrintStringOnPositon(163, 7, Entity.Exp.ToString(), ConsoleColor.Yellow); Utilities.PrintStringOnPositon(163, 8, Entity.Level.ToString(), ConsoleColor.Yellow); Utilities.PrintStringOnPositon(163, 9, Entity.Points.ToString(), ConsoleColor.Yellow); Utilities.PrintStringOnPositon(163, 10, Player.bombs.ToString(), ConsoleColor.Yellow); }
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(); }