Beispiel #1
0
        public void Play()
        {
            while (!board1.HasLost && !board2.HasLost)
            {
                var shootingCoord  = player1.MakeMove();
                var shootingResult = board2.GetShot(shootingCoord.x, shootingCoord.y);
                board1.OffensePanel[shootingCoord.x][shootingCoord.y]
                    = shootingResult == ShootingResultEnum.Missed
                        ? OffenseOcupationTypeEnum.Missed
                        : OffenseOcupationTypeEnum.Hit;

                ConsoleUi.DrawBoard(board1.GetBoardAsListOfStringRows(), 0, 1);

                if (board2.HasLost)
                {
                    break;
                }

                shootingCoord  = player2.MakeMove();
                shootingResult = board1.GetShot(shootingCoord.x, shootingCoord.y);
                board2.OffensePanel[shootingCoord.x][shootingCoord.y]
                    = shootingResult == ShootingResultEnum.Missed
                        ? OffenseOcupationTypeEnum.Missed
                        : OffenseOcupationTypeEnum.Hit;


                ConsoleUi.DrawBoard(board2.GetBoardAsListOfStringRows(), 35, 1);

                //Thread.Sleep(500);
                Console.ReadKey();
            }

            ConsoleUi.MovingScreen();
            ConsoleUi.ShowWinner(board1.HasLost ? "Player 2 Won": "Player 1 Won");
        }
Beispiel #2
0
        public void PlaceShips()
        {
            IShipPlacer shipPlacement = new ShipPlacementRandomizer();

            shipPlacement.PlaceShips(board1);
            shipPlacement.PlaceShips(board2);

            ConsoleUi.DrawBoard(board1.GetBoardAsListOfStringRows(), 0, 1);
            ConsoleUi.DrawBoard(board2.GetBoardAsListOfStringRows(), 35, 1);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var engine = new GameEngine();

            Console.SetWindowSize(90, 30);
            Console.SetBufferSize(90, 30);

            ConsoleUi.MovingScreen();

            engine.PlaceShips();
            Console.ReadKey();

            engine.Play();
            Console.ReadKey();
        }