public Shot(Ship player) { this.posX = player.XPos; this.posY = player.YPos; this.direction = player.shipDirection; List<int> shot = new List<int>(); shot.Add(this.posX); shot.Add(this.posY); shot.Add(this.direction); shots.Add(shot); }
public static void CollisionEnemyPlayer(Ship player) { for (int i = 0; i < enemies.Count; i++) { if (player.XPos == enemies[i][0] && player.YPos == enemies[i][1]) { Engine.PrintOnConsole(player.XPos, player.YPos, 'X', ConsoleColor.Red); Console.Beep(1200, 150); player.XPos = 1; player.YPos = 1; GameData.playerLives--; } } }
public static void ShipMoveShoot(Ship player) { if (Console.KeyAvailable) { ConsoleKeyInfo pressedKey = Console.ReadKey(true); while (Console.KeyAvailable) Console.ReadKey(true); if (pressedKey.Key == ConsoleKey.LeftArrow) { if (player.XPos - 1 >= 0 && Labyrinth.labyrinth[player.YPos, player.XPos - 1] == ' ') { Engine.PrintOnConsole(player.XPos, player.YPos, ' '); player.XPos = player.XPos - 1; player.shipDirection = 0; } else { player.shipDirection = 0; } } else if (pressedKey.Key == ConsoleKey.RightArrow) { if (player.XPos + 1 < Console.WindowWidth && Labyrinth.labyrinth[player.YPos, player.XPos + 1] == ' ') { Engine.PrintOnConsole(player.XPos, player.YPos, ' '); player.XPos = player.XPos + 1; player.shipDirection = 1; } else { player.shipDirection = 1; } } else if (pressedKey.Key == ConsoleKey.UpArrow) { if (player.YPos - 1 >= 0 && Labyrinth.labyrinth[player.YPos - 1, player.XPos] == ' ') { Engine.PrintOnConsole(player.XPos, player.YPos, ' '); player.YPos = player.YPos - 1; player.shipDirection = 2; } else { player.shipDirection = 2; } } else if (pressedKey.Key == ConsoleKey.DownArrow) { if (player.YPos + 1 < Console.WindowHeight && Labyrinth.labyrinth[player.YPos + 1, player.XPos] == ' ') { Engine.PrintOnConsole(player.XPos, player.YPos, ' '); player.YPos = player.YPos + 1; player.shipDirection = 3; } else { player.shipDirection = 3; } } else if (pressedKey.Key == ConsoleKey.Spacebar) { Shot shooting = new Shot(player); Console.Beep(240, 100); } } }
public static void InitializeGame() { userShip = new Ship(1, 1); endPointX = 44; endPointY = 1; Labyrinth.labyrinth = new char[fieldSizeY, fieldSizeX]; randomLabyrinthNum = rnd.Next(1, 12); flag = new object(); Engine.PrintStringOnConsole(gameInfoX, gameInfoY + 2, "Time left: ", ConsoleColor.Red); timer = new Timer(gameInfoX + "Time left: ".Length, gameInfoY + 2); isGameOver = false; isGameWon = false; Labyrinth.ReadLabyrinth(); Labyrinth.PrintLabyrinth(); Enemy.GenerateNewEnemy((GameData.gameDifficulty * 3) + enemiesLeft); }