Ejemplo n.º 1
0
        public void Run()
        {
            do
            {
                //splash screen
                ASCIIBattleShip.Welcome();
                ASCIIBattleShip.Bship();
                Console.WriteLine("Hit any key to continue");
                Console.ReadKey();
                Console.Clear();

                //getting players names
                Console.WriteLine("Battleship is a 2 player HUMAN game.");
                Player PlayerOne = new Player();
                PlayerOne.PlayerName = GameFlowHelper.GetStringFromUser("HUMAN ONE: What is your name?");
                Console.Clear();
                Console.WriteLine($"Thank you HUMAN {PlayerOne.PlayerName}");
                Player PlayerTwo = new Player();
                PlayerTwo.PlayerName = GameFlowHelper.GetStringFromUser("HUMAN TWO: What is your name?");
                Console.Clear();
                Console.WriteLine($"Thank you HUMAN {PlayerTwo.PlayerName}, hand the COMPUTER to HUMAN {PlayerOne.PlayerName} so they may set up their board.");
                Console.ReadKey();
                Console.Clear();


                //Setting up the board P1
                Console.WriteLine($"HUMAN {PlayerOne.PlayerName} it's time to set up your board!");
                PlayerOne.PlayerBoard = PlayerOneBoard.SetupPOneBoard();
                Console.WriteLine($"Great! Now press any key and hand the COMPUTER to HUMAN {PlayerTwo.PlayerName}");
                Console.ReadKey();
                Console.Clear();

                //Setting up the board P2
                Console.WriteLine($"HUMAN {PlayerTwo.PlayerName} it's time to set up your board!");
                PlayerTwo.PlayerBoard = PlayerTwoBoard.SetupPTwoBoard();

                //Decides who plays first
                int whoGoesFirst = GameFlowHelper.WhoGoesFirst();
                if (whoGoesFirst == 1)
                {
                    GameFlowHelper.Turns(PlayerOne, PlayerTwo);
                }
                else
                {
                    GameFlowHelper.Turns(PlayerTwo, PlayerOne);
                }
            }while (GameFlowHelper.PlayAgain("Do you want to play agian [Y/N]?"));
        }
Ejemplo n.º 2
0
        public static void PlaceBattleshipP1(Board playerOneBoard)
        {
            ASCIIBattleShip.Bship();
            while (true)
            {
                int           CoorX;
                int           CoorY;
                ShipDirection DirectionOne;


                Console.WriteLine("We will set up the Battleship (4 spaces long) ship now.");
                GameFlowHelper.GetCoorFromUser("What row LETTER (A-J) AND column NUMBER (1-10) would you like to place your ship on?");
                CoorX = GameFlowHelper.GetXcoor();
                CoorY = GameFlowHelper.GetYCoor();

                DirectionOne = GameFlowHelper.GetDirectionFromUser("Great! Now what direction would you like to place your ship? (Up, Down, Left, Right");


                var request = new PlaceShipRequest()
                {
                    Coordinate = new Coordinate(CoorX, CoorY),
                    Direction  = DirectionOne,
                    ShipType   = ShipType.Battleship
                };
                ShipPlacement help = new ShipPlacement();
                help = playerOneBoard.PlaceShip(request);
                switch (help)
                {
                case ShipPlacement.NotEnoughSpace:
                    Console.WriteLine("Not enough space, try again");
                    continue;

                case ShipPlacement.Overlap:
                    Console.WriteLine("Ship overlap, try again");
                    continue;

                case ShipPlacement.Ok:
                    break;
                }
                Console.Clear();
                break;
            }
        }
Ejemplo n.º 3
0
        public static void Turns(Player pCurrent, Player pOther)
        {
            bool             victory  = false;
            Player           pSwitch  = new Player();
            FireShotResponse response = new FireShotResponse();

            while (victory == false)
            {
                do
                {
                    PlayerDisplay(pOther.PlayerBoard);
                    GetCoorFromUser($"{pCurrent.PlayerName} Call your shot");
                    var coordinate = new Coordinate(GetXcoor(), GetYCoor());
                    response = pOther.PlayerBoard.FireShot(coordinate);

                    switch (response.ShotStatus)
                    {
                    case ShotStatus.Invalid:
                        Console.WriteLine("That was an invaild entry. Try again.");
                        break;

                    case ShotStatus.Duplicate:
                        Console.WriteLine("You've already called that shot.");
                        break;

                    case ShotStatus.Miss:
                        ASCIIBattleShip.Missed();
                        Console.WriteLine("You missed! Better luck next turn!");
                        Console.ReadKey();
                        break;

                    case ShotStatus.Hit:
                        ASCIIBattleShip.Hit();
                        Console.WriteLine($"HIT! Congrats {pCurrent.PlayerName}!");
                        Console.ReadKey();
                        break;

                    case ShotStatus.HitAndSunk:
                        ASCIIBattleShip.HitAndSunk();
                        Console.WriteLine($"You sunk {pOther.PlayerName}'s ship!!");
                        Console.ReadKey();
                        break;

                    case ShotStatus.Victory:

                        break;
                    }
                } while (response.ShotStatus == ShotStatus.Duplicate || response.ShotStatus == ShotStatus.Invalid);

                switch (response.ShotStatus)
                {
                case ShotStatus.Hit:
                case ShotStatus.HitAndSunk:
                case ShotStatus.Miss:
                    pSwitch  = pCurrent;
                    pCurrent = pOther;
                    pOther   = pSwitch;
                    Console.Clear();
                    break;

                case ShotStatus.Victory:
                    victory = true;
                    ASCIIBattleShip.Winner();
                    Console.WriteLine("YOU WON");
                    break;
                }
            }
        }