public void PlayOnline(IClient client) { IPlayer currentPlayer; IPlayer opponent; List <IEnemy> enemies; while (true) { Console.Clear(); Console.CursorVisible = false; // Read GameObjects from server and print ReceiveSerializedList(client); currentPlayer = (IPlayer)gameObjects[0]; opponent = (IPlayer)gameObjects[1]; enemies = (List <IEnemy>)gameObjects[2]; // Game end ----------- if (opponent.Health == 0) { GameStory.printGameComplete(); break; } else if (currentPlayer.Health == 0) { GameStory.printGameOver(); break; } Instance.MirrorOpponent(opponent); Screen.PrintStats(currentPlayer, opponent); currentPlayer.ShootedBullets.ForEach(Screen.PrintObject); Screen.PrintObject(currentPlayer); Screen.PrintObject(opponent); enemies.ForEach(Screen.PrintObject); int pressedKey = ReadPressedKey(); client.SendData(pressedKey.ToString()); Thread.Sleep(100); } }
public void PlayOffline(IPlayer offlinePlayer) { PlaySound("../../Core/Resources/music/singlePlayer.wav"); List <IEnemy> enemies = new List <IEnemy>(); IBoss boss = null; Random rnd = new Random(); int randX = 0; int counter = 0; while (true) { Console.Clear(); Console.CursorVisible = false; offlinePlayer.ShootedBullets.RemoveAll(b => b.ObjectPosition.Y == 0); offlinePlayer.ShootedBullets.ForEach(Screen.PrintObject); offlinePlayer.ShootedBullets.ForEach(b => b.Move()); randX = rnd.Next(0, Console.WindowWidth - 2); if (counter == 1000) { Instance.GameSpeed = 20; boss = InvadersFactory.Instance.CreateBoss(null, 10, null, ConsoleColor.Red, randX); boss.ObjectPosition.Y = 1; PlaySound("../../Core/Resources/music/bossMusic.wav"); } else if (counter < 1000 && counter % 10 == 0) { enemies.Add(InvadersFactory.Instance.CreateEnemy(null, 1, null, ConsoleColor.Green, randX)); Instance.GameSpeed++; } enemies.Remove(enemies.Find(i => i.ObjectPosition.Y == Console.WindowHeight)); Screen.PrintObject(offlinePlayer); Screen.PrintStats(offlinePlayer); if (boss != null) { if (counter % 5 == 0) { boss.Move(); } boss.ShootedBullets.RemoveAll(bull => bull.ObjectPosition.Y == Console.WindowHeight); boss.ShootedBullets.ForEach(b => { Screen.PrintObject(b); b.ObjectPosition.Y++; }); Screen.PrintObject(boss); HitCheck(offlinePlayer, null, null, boss); Screen.PrintStats(offlinePlayer, null, boss); if (boss.Health == 0) { Console.Clear(); GameStory.printGameComplete(); break; } } enemies.ForEach(Screen.PrintObject); enemies.ForEach(p => p.Move()); offlinePlayer.Move(); Instance.HitCheck(offlinePlayer, enemies); // Game end ----------- if (offlinePlayer.Health == 0) { Console.Clear(); GameStory.printGameOver(); break; } counter++; Thread.Sleep(100 - Instance.GameSpeed); } }