Beispiel #1
0
        public void Start()
        {
            applicationInterface.SetGameDisplay();

            try
            {
                var registrationPlayer1 = player.RegistrationForPlayer();
                Writer.WriteColorTextCenter(registrationPlayer1);
                IPlayer firstPlayer = playerCreator.CreatePlayer(player);

                var registrationPlayer2 = player.RegistrationForPlayer();
                Writer.WriteColorTextCenter(registrationPlayer2);
                IPlayer secondPlayer = playerCreator.CreatePlayer(player);

                gameController.Play(firstPlayer, secondPlayer);
            }
            catch (Exception ex)
            {
                Writer.WriteLine(ex.Message);
            }
        }
Beispiel #2
0
        public void Play(IPlayer firstPlayer, IPlayer secondPlayer)
        {
            this.firstPlayer  = firstPlayer;
            this.secondPlayer = secondPlayer;

            appInterface.SetGameDisplay();
            SetInitialPositions(firstPlayer);
            SetInitialPositions(secondPlayer);

            while (true)
            {
                if (writer.KeyAvailable())
                {
                    var keyInfo = reader.ReadKey();
                    CommandParser(keyInfo);
                }

                writer.ClearScreen();

                ManageShooting();

                if (hasWinner)
                {
                    break;
                }

                drawShip.DrawShipPlayerOne(firstPlayer);
                drawShip.DrawShipPlayerTwo(secondPlayer);

                DrawBullet(firstPlayer, 'A');
                DrawBullet(secondPlayer, 'B');

                PrintResult();
                appInterface.FreezeScreen(40);
            }

            writer.WriteColorTextCenter($"{winnerName} wins!");
        }