Example #1
0
        private Board BoardCreated(string PlayerName)
        {
            Board toReturn = new Board();

            for (ShipType s = ShipType.Carrier; s >= ShipType.Destroyer; s--)
            {
                bool IsShipSpotValid = false;
                do
                {
                    PlaceShipRequest request = new PlaceShipRequest();
                    request.Coordinate = BshipInput.GetCoordinate(PlayerName);
                    request.Direction  = BshipInput.GetDirection(PlayerName, s);
                    request.ShipType   = s;

                    var result = toReturn.PlaceShip(request);

                    if (result == ShipPlacement.NotEnoughSpace)
                    {
                        BshipOutput.TooFar();
                    }
                    if (result == ShipPlacement.Overlap)
                    {
                        BshipOutput.GGOverlap();
                    }
                    if (result == ShipPlacement.Ok)
                    {
                        BshipOutput.PlaceSuccess();
                        IsShipSpotValid = true;
                    }
                }while (!IsShipSpotValid);
            }
            return(toReturn);
        }
Example #2
0
        public GameState Start()
        {
            BshipOutput.DisplayTitle();
            BshipOutput.WelcomePlayers();

            string P1 = BshipInput.GetNameFromPlayer(1);
            string P2 = BshipInput.GetNameFromPlayer(2);

            Board PlayerOneBoard = BoardCreated(P1);
            Board PlayerTwoBoard = BoardCreated(P2);

            Player p1 = new Player(P1, PlayerOneBoard);
            Player p2 = new Player(P2, PlayerTwoBoard);


            bool IsPlayerTurn = WhoGoesFirst();

            GameState gameState = new GameState(p1, p2, IsPlayerTurn);

            return(gameState);
        }
Example #3
0
        internal static void PlayGame(GameState state)
        {
            Player AttackingPlayer = null;
            Player DefendingPlayer = null;


            bool victorious = false;

            while (!victorious)
            {
                if (state.IsPlayerOneTurn)
                {
                    AttackingPlayer = state.P1;
                    DefendingPlayer = state.P2;
                }
                else
                {
                    AttackingPlayer = state.P2;
                    DefendingPlayer = state.P1;
                }
                //if (Victorious)
                //{
                //    Console.WriteLine("Do you want to play again? Enter Y/N")
                //}


                BshipOutput.DrawBoard(DefendingPlayer.PlayerBoard);

                {
                    Coordinate ToraToraTora = BshipInput.GetCoordinate(AttackingPlayer.PlayerName);

                    FireShotResponse response = DefendingPlayer.PlayerBoard.FireShot(ToraToraTora);

                    //ShotHistory LastShot = new ShotHistory();

                    switch (response.ShotStatus)
                    {
                    case ShotStatus.Invalid:
                        Console.WriteLine("U WOT M8!? Not a valid coordinate. Try again bozo.");
                        break;

                    case ShotStatus.Hit:
                        Console.WriteLine("Hey look, you proved the haters wrong! You can hit something more than the broad side of a barn! Now it's the next players turn.");
                        Console.ReadLine();
                        state.IsPlayerOneTurn = !state.IsPlayerOneTurn;
                        Console.Clear();
                        break;

                    case ShotStatus.Miss:
                        Console.WriteLine("You missed, better luck next time.");
                        Console.ReadLine();
                        state.IsPlayerOneTurn = !state.IsPlayerOneTurn;
                        Console.Clear();
                        break;


                    case ShotStatus.Duplicate:
                        Console.WriteLine("U WOT M8!? Dont you know you already shot there?");
                        break;


                    case ShotStatus.Victory:
                        Console.WriteLine("Congratulations, you rained fire and fury down on your enemies, the likes of which they have never known...");
                        Console.ReadLine();
                        victorious = true;
                        Console.Clear();
                        break;


                    case ShotStatus.HitAndSunk:
                        Console.WriteLine("To repeat the old phrase... You sunk their battleship! Well one of their ships anyway");
                        state.IsPlayerOneTurn = !state.IsPlayerOneTurn;
                        break;
                    }
                }
            }
            BshipOutput.GameOver();
        }