예제 #1
0
        public void PlayerData(Board board)
        {
            int x = 0;
            int y = 0;
            PlaceShipRequest request    = new PlaceShipRequest();
            Coordinate       Coordinate = new Coordinate(x, y);

            for (int currentShipIndex = 0; currentShipIndex < 5;)
            {
                while (true)
                {
                    request.ShipType = ConsoleInput.ProcessType(currentShipIndex);

                    _strCoordinate = ConsoleInput.GetCoor(Coordinate);

                    ConsoleInput.ProcessCoor(Coordinate, x, y, _strCoordinate);

                    request.Coordinate = Coordinate;

                    _direction = ConsoleInput.GetDirection(_direction);

                    request.Direction = ConsoleInput.ProcessDirection(_direction);

                    var shipPlaced = board.PlaceShip(request);

                    if (shipPlaced == ShipPlacement.NotEnoughSpace)
                    {
                        Console.WriteLine("There's not enough space for that ship. Try again");
                    }
                    else if (shipPlaced == ShipPlacement.Overlap)
                    {
                        Console.WriteLine("Ships are overlapping. Try again.");
                    }
                    else
                    {
                        break;
                    }
                }
                currentShipIndex++;
                Console.Clear();
            }
        }
예제 #2
0
        public void StartFire()
        {
            int x = 0;
            int y = 0;

            while (true)
            {
                string strCoordinate = "";

                if (_start == 1)
                {
                    Coordinate Coordinate = new Coordinate(x, y);

                    Console.Clear();

                    DisplayBoard(_p1board);

                    Console.WriteLine("\n {0},", _p1);


                    //Asks player 1 where to fire

                    Console.WriteLine("Where would you like to fire?");

                    strCoordinate = ConsoleInput.GetCoor(Coordinate);

                    ConsoleInput.ProcessCoor(Coordinate, x, y, strCoordinate);
                    var shotResponse = _p1board.FireShot(Coordinate);

                    ResponseToShot(shotResponse);

                    if (shotResponse.ShotStatus == ShotStatus.Victory)
                    {
                        Console.WriteLine("{0}, you won!", _p1);
                        _start = -1;
                    }
                    else
                    {
                        Console.WriteLine("Press any key for {0}'s turn", _p2);

                        Console.ReadKey();
                    }
                    _start++;
                }

                else if (_start == 2)
                {
                    Coordinate Coordinate = new Coordinate(x, y);

                    Console.Clear();

                    DisplayBoard(_p2board);

                    Console.WriteLine("\n {0},", _p2);


                    //Asks player 2 where to fire

                    Console.WriteLine("Where would you like to fire?");

                    strCoordinate = ConsoleInput.GetCoor(Coordinate);

                    ConsoleInput.ProcessCoor(Coordinate, x, y, strCoordinate);

                    var shotResponse = _p2board.FireShot(Coordinate);

                    ResponseToShot(shotResponse);

                    if (shotResponse.ShotStatus == ShotStatus.Victory)
                    {
                        Console.WriteLine("{0}, you won!", _p2);
                        _start = 1;
                    }
                    else
                    {
                        Console.WriteLine("Press any key for {0}'s turn", _p1);

                        Console.ReadKey();
                    }

                    _start--;
                }
                else
                {
                    break;
                }
            }
            Console.WriteLine("Do you want to play again (Y/N)?");

            string again = Console.ReadLine();

            if (again == "Y" || again == "y")
            {
                Start();
            }
        }