Esempio n. 1
0
        static void Main(string[] args)
        {
            bool keepPlaying;

            do
            {

                GameWorkflow game = new GameWorkflow();

                game.SplashScreen();
                game.PromptPlayerName();
                game.PromptShipPlacement();
                ShipSetter.SetShip(game);
                game.NextTurn();
                game.PromptShipPlacement();
                ShipSetter.SetShip(game);
                game.NextTurn();
                GamePlay.PlayGame(game);

                keepPlaying = GamePlay.NewGame();

                Console.ReadLine();
                Console.Clear();

            } while (keepPlaying);
        }
Esempio n. 2
0
        public static void Main()
        {
            Random r          = new Random();
            int    goingFirst = r.Next(1, 3);

            SplashScreen.ShowSplashScreen();
            Player p1 = new Player();
            Player p2 = new Player();

            Console.Write("Enter Player 1's Name: ");
            string p1Name = Console.ReadLine();

            p1.Name = p1Name;
            Console.Write("Enter Player 2's Name: ");
            string p2Name = Console.ReadLine();

            p2.Name = p2Name;
            SetupWorkflow.PlaceShips(p1);
            SetupWorkflow.PlaceShips(p2);
            switch (goingFirst)
            {
            case 1:
                GameWorkflow.WhoGoesFirst(p1.Name);
                break;

            case 2:
                GameWorkflow.WhoGoesFirst(p2.Name);
                break;
            }
            bool GameOver = false;

            while (!GameOver)
            {
                GameWorkflow.PrintEnemyBoard(p2);
                BLL.Responses.ShotStatus value1 = (GameWorkflow.FireShotAtEnemey(p2));
                if (value1 == BLL.Responses.ShotStatus.Victory)
                {
                    Console.WriteLine("Game over " + p1.Name + " wins.. ROLLTIDE");
                    GameOver = true;
                }
                GameWorkflow.PrintEnemyBoard(p1);
                BLL.Responses.ShotStatus value2 = (GameWorkflow.FireShotAtEnemey(p1));
                if (value2 == BLL.Responses.ShotStatus.Victory)
                {
                    Console.WriteLine("Game over " + p1.Name + " wins.. ROLLTIDE");
                    GameOver = true;
                }
            }
            if (GameOver)
            {
                Console.Clear();
                Console.WriteLine("Would you to play again? y or n ");
                string input = Console.ReadLine();
                if (input == "y")
                {
                    Program.Main();
                }
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Console.BackgroundColor = ConsoleColor.DarkCyan;
            Console.ForegroundColor = ConsoleColor.Black;
            Console.WindowWidth     = 60;
            Console.WindowHeight    = 40;
            GameWorkflow game = new GameWorkflow();

            game.Game();
        }
Esempio n. 4
0
        public static void SetShip(GameWorkflow game)
        {
            foreach (Ship ship in game.CurrentPlayer.Ships)
            {
                PlaceShipRequest placeShipRequest = new PlaceShipRequest();
                placeShipRequest.ShipType = ship.ShipType;
                string coordinateInput = "";
                char[] coordinateOutput = new char[2];
                bool isValidInput = false;
                ShipPlacement shipPlacement;

                do
                {
                    do
                    {
                        Console.WriteLine("{0}, place your {1} ship on the board which has {2} slots.", game.CurrentPlayer.Name,
                            ship.ShipType, ship.BoardPositions.Length);
                        Console.WriteLine();
                        Console.WriteLine("Here is the game board for your reference.");
                        Console.WriteLine();
                        BoardDrawer.DrawOwnShipBoard(game);
                        Console.WriteLine();
                        Console.WriteLine("Choose a position on the board, for example \"E5\": ");
                        coordinateInput = Console.ReadLine().ToUpper();
                        Console.WriteLine();

                        if (coordinateInput.Length == 2 && (coordinateInput[1] >= '1' && coordinateInput[1] <= '9') &&
                            (coordinateInput[0] >= 'A' && coordinateInput[0] <= 'J'))
                        {
                            isValidInput = true;
                            coordinateOutput = coordinateInput.ToCharArray();
                        }
                        else if (coordinateInput.Length == 3 && (coordinateInput[1] >= '1' && coordinateInput[2] <= '0') &&
                                 (coordinateInput[0] >= 'A' && coordinateInput[0] <= 'J'))
                        {
                            isValidInput = true;
                            coordinateOutput = coordinateInput.ToCharArray();
                        }
                        else
                        {
                            isValidInput = false;
                            Console.WriteLine("Invalid input {0}, please try again!", game.CurrentPlayer.Name);
                            ScreenCleaner.ClearBoard();
                        }
                    } while (!isValidInput);

                    Coordinate coordinateForShip;

                    if (coordinateOutput.Length == 3)
                    {
                        int yCoordinate =
                            int.Parse(string.Concat(coordinateOutput[1].ToString(), coordinateOutput[2].ToString()));
                        coordinateForShip = new Coordinate(coordinateOutput[0] - 'A' + 1, yCoordinate);
                    }
                    else
                    {
                        coordinateForShip = new Coordinate((coordinateOutput[0] - 'A' + 1), int.Parse(coordinateOutput[1].ToString()));
                    }

                    placeShipRequest.Coordinate = coordinateForShip;

                    isValidInput = false;
                    string directionInput = "";
                    bool needBoard = false;

                    do
                    {
                        if (needBoard)
                        {
                            Console.WriteLine("Here is the game board for your reference.");
                            Console.WriteLine();
                            BoardDrawer.DrawOwnShipBoard(game);
                            Console.WriteLine();
                            Console.WriteLine("Your coordinate input was: {0}", coordinateInput);
                            Console.WriteLine();
                        }
                        Console.WriteLine("Please choose the direction to place the ship: \"U\" up, \"D\" down, \n \"L\" left, or \"R \" right.");
                        directionInput = Console.ReadLine().ToUpper();

                        if ((directionInput.Length == 1) && directionInput == "U"
                            || directionInput == "D" || directionInput == "L" || directionInput == "R")
                        {
                            isValidInput = true;
                            needBoard = false;
                        }
                        else
                        {
                            Console.WriteLine();
                            Console.WriteLine("Input not valid!");
                            ScreenCleaner.ClearBoard();
                            isValidInput = false;
                            needBoard = true;
                        }

                    } while (!isValidInput);

                    switch (directionInput)
                    {
                        case "U":
                            placeShipRequest.Direction = ShipDirection.Up;
                            break;
                        case "D":
                            placeShipRequest.Direction = ShipDirection.Down;
                            break;
                        case "L":
                            placeShipRequest.Direction = ShipDirection.Left;
                            break;
                        case "R":
                            placeShipRequest.Direction = ShipDirection.Right;
                            break;
                        default:
                            Console.WriteLine();
                            Console.WriteLine("You need to enter a direction: either \"U\" up, \"D\" down,\n \"L\" left, or \"R\" right");
                            ScreenCleaner.ClearBoard();
                            break;
                    }

                    shipPlacement = game.CurrentPlayer.PlayerBoard.PlaceShip(placeShipRequest);

                    if (shipPlacement == ShipPlacement.NotEnoughSpace)
                    {
                        Console.WriteLine();
                        Console.WriteLine("There is not enough space on the board.  Please choose another direction.");
                        ScreenCleaner.ClearBoard();
                    }
                    else if (shipPlacement == ShipPlacement.Overlap)
                    {
                        Console.WriteLine();
                        Console.WriteLine("You already have a ship placed there.  Please choose another direction");
                        ScreenCleaner.ClearBoard();
                    }
                    else
                    {
                        Console.WriteLine();

                        Console.WriteLine("{0} placed.", placeShipRequest.ShipType);

                        ShipCoordinates shipCoordinates = new ShipCoordinates();

                        Coordinate[] coordinates = shipCoordinates.ShipCoordinator(placeShipRequest);

                        for (int i = 0; i < coordinates.Length; i++)
                        {
                            game.CurrentPlayer.ShipLocations.Add(coordinates[i], placeShipRequest.ShipType);
                        }
                        ScreenCleaner.ClearBoard();
                    }
                }
                while (shipPlacement != ShipPlacement.Ok);
            }

            Console.WriteLine("This is your completed ship board, {0}.\n", game.CurrentPlayer.Name);
            BoardDrawer.DrawOwnShipBoard(game);
            ScreenCleaner.ClearBoard();
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            GameWorkflow game = new GameWorkflow();

            game.Run();
        }
Esempio n. 6
0
 static void Main(string[] args)
 {
     GameWorkflow game = new GameWorkflow();
     game.Start();
 }
Esempio n. 7
0
        private static void Main(string[] args)
        {
            GameWorkflow play = new GameWorkflow();

            play.StartBattleship();
        }
Esempio n. 8
0
        public static void PlayGame(GameWorkflow game)
        {
            string coordinateInput = "";
            char[] coordinateOutput;
            bool isValidInput;
            Coordinate coordinate;
            FireShotResponse response = new FireShotResponse();

            Console.WriteLine("Your ships are set, let's start the game!");

            do
            {
                Console.WriteLine("{0}, it is now your turn.", game.CurrentPlayer.Name);
                Console.WriteLine();
                do
                {
                    do
                    {
                        Console.WriteLine("This is Your Shot History...");
                        Console.WriteLine();
                        BoardDrawer.DrawShotHistoryBoard(game.OtherPlayer);
                        Console.WriteLine();
                        Console.WriteLine("Here are your ships that got hit.");
                        Console.WriteLine();
                        BoardDrawer.DrawShotHistoryBoard(game.CurrentPlayer);
                        Console.WriteLine();
                        Console.WriteLine("{0}, pick a coordinate to fire at: ", game.CurrentPlayer.Name);
                        coordinateInput = Console.ReadLine().ToUpper();

                        isValidInput = InputChecker.CheckInput(coordinateInput);

                        if (!isValidInput)
                        {
                            Console.WriteLine();
                            Console.WriteLine("{0}, that was not a valid shot coordinate.  Please try again!",
                                game.CurrentPlayer.Name);
                            ScreenCleaner.ClearBoard();
                        }
                        else
                        {
                            coordinateOutput = coordinateInput.ToCharArray();
                            coordinate = GridConversion.CoordinateConversion(coordinateOutput);
                            response = game.OtherPlayer.PlayerBoard.FireShot(coordinate);
                        }
                    } while (!isValidInput);

                    switch (response.ShotStatus)
                    {
                        case ShotStatus.Invalid:
                            Console.WriteLine();
                            Console.WriteLine("Not a valid coordinate.");
                            ScreenCleaner.ClearBoard();
                            break;
                        case ShotStatus.Duplicate:
                            Console.WriteLine();
                            Console.WriteLine("Duplicate coordinate.");
                            ScreenCleaner.ClearBoard();
                            break;
                        case ShotStatus.Miss:
                            Console.WriteLine();
                            Console.WriteLine("That was a miss!");
                            ScreenCleaner.ClearBoard();
                            break;
                        case ShotStatus.Hit:
                            Console.WriteLine();
                            Console.WriteLine("You hit the {0} ship!", response.ShipImpacted);
                            ScreenCleaner.ClearBoard();
                            break;
                        case ShotStatus.HitAndSunk:
                            Console.WriteLine();
                            Console.WriteLine("You sank the {0} ship!", response.ShipImpacted);
                            ScreenCleaner.ClearBoard();
                            break;
                        case ShotStatus.Victory:
                            Console.WriteLine();
                            Console.WriteLine("Congratulations, {0}, you won!", game.CurrentPlayer.Name);
                            ScreenCleaner.ClearBoard();
                            break;
                    }

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

                game.NextTurn();

            } while (response.ShotStatus != ShotStatus.Victory);
        }
Esempio n. 9
0
        public static void PlayerTurns(Player P1, Player P2, int firstTurn)
        {
            bool player1Victory = false;
            bool player2Victory = false;
            bool victory        = false;


            int whoseTurn = firstTurn;

            while (!victory)
            {
                if (whoseTurn == 1)
                {
                    //player 1 turn
                    //Display p2 board


                    //Fire shot
                    bool validShot = false;
                    while (!validShot)
                    {
                        ConsoleOutput.DisplayGameBoard(P2.PlayerGameBoard);
                        ConsoleOutput.WaveBorder(1);
                        ConsoleOutput.Player1Turn(P1.Name);
                        Coordinate c = ConsoleInput.GetPlayerCoordinate();

                        FireShotResponse response = P2.PlayerGameBoard.FireShot(c);
                        Console.Clear();

                        ConsoleOutput.DisplayGameBoard(P2.PlayerGameBoard);
                        ConsoleOutput.WaveBorder(1);
                        if (response.ShotStatus != ShotStatus.Duplicate && response.ShotStatus != ShotStatus.Invalid)
                        {
                            validShot = true;
                            whoseTurn = 2;
                        }
                        if (response.ShotStatus == ShotStatus.Victory)
                        {
                            validShot      = true;
                            victory        = true;
                            player1Victory = true;
                        }
                        ConsoleOutput.ShotMessage(response, P1.Name, P2.Name, P2, c);
                    }
                }
                else
                {
                    //player 2 turn
                    //Display p1 board


                    //Fire Shot
                    bool validShot = false;
                    while (!validShot)
                    {
                        ConsoleOutput.DisplayGameBoard(P1.PlayerGameBoard);
                        ConsoleOutput.WaveBorder(2);
                        ConsoleOutput.Player2Turn(P2.Name);
                        Coordinate c = ConsoleInput.GetPlayerCoordinate();

                        FireShotResponse response = P1.PlayerGameBoard.FireShot(c);
                        Console.Clear();

                        ConsoleOutput.DisplayGameBoard(P1.PlayerGameBoard);
                        ConsoleOutput.WaveBorder(2);

                        if (response.ShotStatus != ShotStatus.Duplicate && response.ShotStatus != ShotStatus.Invalid)
                        {
                            validShot = true;
                            whoseTurn = 1;
                        }
                        if (response.ShotStatus == ShotStatus.Victory)
                        {
                            validShot      = true;
                            victory        = true;
                            player2Victory = true;
                        }
                        ConsoleOutput.ShotMessage(response, P2.Name, P1.Name, P1, c);
                    }
                }
            }
            bool playAgain = false;

            playAgain = ConsoleOutput.EndGameMessage(player1Victory, player2Victory, P1.Name, P2.Name);

            if (playAgain)
            {
                //Create new game boards and go through the turns again
                Console.Clear();
                Board blank = new Board();
                ConsoleOutput.DisplayGameBoard(blank);
                ConsoleOutput.ShipKey();
                P1.PlayerGameBoard = ConsoleInput.PlaceShipLoop(P1.Name);

                Console.Clear();
                ConsoleOutput.DisplayGameBoard(blank);
                ConsoleOutput.ShipKey();
                P2.PlayerGameBoard = ConsoleInput.PlaceShipLoop(P2.Name);
                Console.Clear();
                GameWorkflow turn = new GameWorkflow();
                int          ft   = turn.WhoIsGoingFirst();
                PlayerTurns(P1, P2, ft);
            }

            ConsoleOutput.Credits();
        }
Esempio n. 10
0
        public static void DrawOwnShipBoard(GameWorkflow game)
        {
            char[] columnGrid = "\0ABCDEFGHIJ".ToCharArray();

            Console.Write("   ");
            for (int i = 1; i < 11; i++)
            {
                Console.Write(" {0} ", columnGrid[i]);
            }
            Console.WriteLine();

            for (int i = 1; i < 11; i++)
            {
                if (i == 10)
                {
                    Console.Write("{0} ", i);
                }
                else
                {
                    Console.Write("{0}  ", i);
                }

                for (int j = 1; j < 11; j++)
                {

                    Coordinate checkCoordinate = new Coordinate(j, i);
                    if (!game.CurrentPlayer.ShipLocations.ContainsKey(checkCoordinate))

                    {
                        Console.Write(" - ");
                    }
                    else if (game.CurrentPlayer.ShipLocations[checkCoordinate] == ShipType.Destroyer)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write(" {0} ", "D");
                        Console.ForegroundColor = ConsoleColor.Gray;
                    }
                    else if (game.CurrentPlayer.ShipLocations[checkCoordinate] == ShipType.Battleship)
                    {
                        Console.ForegroundColor = ConsoleColor.Cyan;
                        Console.Write(" {0} ", "B");
                        Console.ForegroundColor = ConsoleColor.Gray;
                    }
                    else if (game.CurrentPlayer.ShipLocations[checkCoordinate] == ShipType.Carrier)
                    {
                        Console.ForegroundColor = ConsoleColor.Magenta;
                        Console.Write(" {0} ", "C");
                        Console.ForegroundColor = ConsoleColor.Gray;
                    }
                    else if (game.CurrentPlayer.ShipLocations[checkCoordinate] == ShipType.Cruiser)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.Write(" {0} ", "R");
                        Console.ForegroundColor = ConsoleColor.Gray;
                    }
                    else if (game.CurrentPlayer.ShipLocations[checkCoordinate] == ShipType.Submarine)
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.Write(" {0} ", "S");
                        Console.ForegroundColor = ConsoleColor.Gray;
                    }

                }
                Console.WriteLine();
            }
        }
Esempio n. 11
0
        static void Main(string[] args)
        {
            GameWorkflow myGameFlow = new GameWorkflow();

            myGameFlow.RunProg();
        }