Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            //Setting game colors.
            Console.BackgroundColor = ConsoleColor.DarkBlue;
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Clear();

            GameFlow gf = new GameFlow();
            StartMenu sm = new StartMenu();
            //Player player1;
            //Player player2;

            sm.DisplayStart();
            Console.Clear();

            Console.WriteLine("{0}, press enter to start placing ships.\n\n{1} LOOK AWAY!!", Player.Name1,
                Player.Name2);
            Console.ReadLine();
            Console.Clear();

            gf.Player1ShipPlacement();
            Console.Clear();

            Console.WriteLine("{0}, press enter to start placing ships.\n\n{1} LOOK AWAY!!", Player.Name2,
                Player.Name1);
            Console.ReadLine();
            Console.Clear();

            gf.Player2ShipPlacement();
            Console.Clear();

            gf.GamePlay();

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {

            PlayerInfo player1 = new PlayerInfo();
            PlayerInfo player2 = new PlayerInfo();


            StartMenu menu = new StartMenu();

            //assign turns
            player1.UserTurn = 1;
            player2.UserTurn = 2;

          //assign userName
            player1.UserName = menu.Execute(player1.UserTurn);
            player2.UserName = menu.Execute(player2.UserTurn);

            //create gameboard
            GameBoard gameBoard = new GameBoard();

        //allow users to place ships -- player1
            gameBoard.PrintGameBoard();
            ShipSetUp setUpShips = new ShipSetUp();
            setUpShips.AllowUserToPlace5Ships(gameBoard,player1);

            //allow users to place ships -- player2
            gameBoard.PrintGameBoard();
            setUpShips.AllowUserToPlace5Ships(gameBoard,player2); 
        
 
            GamePlay playGame = new GamePlay();
            playGame.PlayTheGame(player1, player2, gameBoard);
            Console.ReadLine();



        }
Ejemplo n.º 3
0
        public static void Play()
        {
            Console.Clear();
            WorkFlowObject wf = new WorkFlowObject
            {
                p1 = new Player()
                {
                    playerBoard = new Board(),
                    playerName  = ""
                },

                p2 = new Player()
                {
                    playerBoard = new Board(),
                    playerName  = ""
                },

                whosNext = 1
            };

            StartMenu Start = new StartMenu();

            Start.ShowMenu(wf);


            Console.WriteLine("{0} vs {1}\n", wf.p1.playerName, wf.p2.playerName);

            SetUpBoard SetItUp = new SetUpBoard();

            SetItUp.SetUpGame(wf);

            //SetUpBoard SetItUpHard = new SetUpBoard();
            //SetItUpHard.SetUpGameAuto(wf);
            //Console.ReadLine();


            do
            {
                var turn         = wf.whosNext;
                var turnResponse = wf.p1.playerBoard.FireShot(new Coordinate(100, 100));
                if (turn == 1)
                {
                    while (turnResponse.ShotStatus == ShotStatus.Invalid || turnResponse.ShotStatus == ShotStatus.Duplicate)
                    {
                        // player 1

                        Console.WriteLine("{0}, press enter to show your board.", wf.p1.playerName);
                        Console.ReadLine();
                        wf.ShowBoard(wf.p2);
                        Console.WriteLine("\n");

                        var finalP1X = 0;
                        do
                        {
                            Console.WriteLine("\n");
                            Console.WriteLine("{0}, enter your x coordinate: ", wf.p1.playerName);
                            var x = Console.ReadLine();
                            switch (x.ToUpper())
                            {
                            case "A":
                                finalP1X = 1;
                                break;

                            case "B":
                                finalP1X = 2;
                                break;

                            case "C":
                                finalP1X = 3;
                                break;

                            case "D":
                                finalP1X = 4;
                                break;

                            case "E":
                                finalP1X = 5;
                                break;

                            case "F":
                                finalP1X = 6;
                                break;

                            case "G":
                                finalP1X = 7;
                                break;

                            case "H":
                                finalP1X = 8;
                                break;

                            case "I":
                                finalP1X = 9;
                                break;

                            case "J":
                                finalP1X = 10;
                                break;
                            }
                            if (finalP1X == 0)
                            {
                                Console.WriteLine("\nInvalid inuput, press enter to try again.\n");
                                Console.ReadLine();
                                Console.Clear();
                            }
                            wf.ShowBoard(wf.p2);
                        } while (finalP1X == 0);

                        var finaly = 0;

                        do
                        {
                            Console.WriteLine("\n");
                            Console.WriteLine("{0}, enter your y coordinate: ", wf.p1.playerName);
                            var y = Console.ReadLine();
                            int value;
                            if (int.TryParse(y, out value))
                            {
                                finaly = value;
                            }
                            else
                            {
                                finaly = 0;
                            }
                            if (finaly == 0)
                            {
                                Console.WriteLine("\nInvalid inuput, press enter to try again.\n");
                                Console.ReadLine();
                                Console.Clear();
                            }
                            wf.ShowBoard(wf.p2);
                        } while (finaly == 0);

                        var turnCoordinate = new Coordinate(finalP1X, finaly);

                        turnResponse = wf.p2.playerBoard.FireShot(turnCoordinate);
                        //Console.WriteLine(turnResponse.ShotStatus);

                        if (turnResponse.ShotStatus == ShotStatus.Hit)
                        {
                            wf.ShowBoard(wf.p2);
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("\n");
                            Console.WriteLine("You hit something!");
                            Console.ResetColor();
                        }
                        else if (turnResponse.ShotStatus == ShotStatus.Miss)
                        {
                            wf.ShowBoard(wf.p2);
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine("\n");
                            Console.WriteLine("Your projectile splashes into the ocean, you missed!");
                            Console.ResetColor();
                        }
                        else if (turnResponse.ShotStatus == ShotStatus.HitAndSunk)
                        {
                            wf.ShowBoard(wf.p2);
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("\n");
                            Console.WriteLine("You sank your opponent's {0}", turnResponse.ShipImpacted);
                            Console.ResetColor();
                        }
                    }



                    Console.WriteLine("\n");
                    Console.WriteLine("Press enter to clear the board");
                    Console.ReadLine();
                    Console.Clear();

                    wf.whosNext = 2;
                }
                else
                {
                    while (turnResponse.ShotStatus == ShotStatus.Invalid || turnResponse.ShotStatus == ShotStatus.Duplicate)
                    {
                        // player 2
                        Console.WriteLine("{0}, press enter to show your board.", wf.p2.playerName);
                        Console.ReadLine();
                        wf.ShowBoard(wf.p1);

                        var finalP2X = 0;

                        do
                        {
                            Console.WriteLine("\n");

                            Console.WriteLine("{0}, enter your x coordinate: ", wf.p2.playerName);
                            var x = Console.ReadLine();

                            switch (x.ToUpper())
                            {
                            case "A":
                                finalP2X = 1;
                                break;

                            case "B":
                                finalP2X = 2;
                                break;

                            case "C":
                                finalP2X = 3;
                                break;

                            case "D":
                                finalP2X = 4;
                                break;

                            case "E":
                                finalP2X = 5;
                                break;

                            case "F":
                                finalP2X = 6;
                                break;

                            case "G":
                                finalP2X = 7;
                                break;

                            case "H":
                                finalP2X = 8;
                                break;

                            case "I":
                                finalP2X = 9;
                                break;

                            case "J":
                                finalP2X = 10;
                                break;
                            }
                            if (finalP2X == 0)
                            {
                                Console.WriteLine("\nInvalid inuput, press enter to try again.\n");
                                Console.ReadLine();
                                Console.Clear();
                            }
                            wf.ShowBoard(wf.p1);
                        } while (finalP2X == 0);

                        var finaly = 0;

                        do
                        {
                            Console.WriteLine("\n");
                            Console.WriteLine("{0}, enter your y coordinate: ", wf.p2.playerName);
                            var y = Console.ReadLine();
                            int value;
                            if (int.TryParse(y, out value))
                            {
                                finaly = value;
                            }
                            else
                            {
                                finaly = 0;
                            }
                            if (finaly == 0)
                            {
                                Console.WriteLine("\nInvalid inuput, press enter to try again.\n");
                                Console.ReadLine();
                                Console.Clear();
                            }
                            wf.ShowBoard(wf.p1);
                        } while (finaly == 0);

                        var turnCoordinate = new Coordinate(finalP2X, finaly);

                        turnResponse = wf.p1.playerBoard.FireShot(turnCoordinate);
                        //Console.WriteLine(turnResponse.ShotStatus);

                        if (turnResponse.ShotStatus == ShotStatus.Hit)
                        {
                            wf.ShowBoard(wf.p1);
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("\n");
                            Console.WriteLine("You hit something!");
                            Console.ResetColor();
                        }
                        else if (turnResponse.ShotStatus == ShotStatus.Miss)
                        {
                            wf.ShowBoard(wf.p1);
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine("\n");
                            Console.WriteLine("Your projectile splashes into the ocean, you missed!");
                            Console.ResetColor();
                        }
                        else if (turnResponse.ShotStatus == ShotStatus.HitAndSunk)
                        {
                            wf.ShowBoard(wf.p1);
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("\n");
                            Console.WriteLine("You sank your opponent's {0}", turnResponse.ShipImpacted);
                            Console.ResetColor();
                        }
                    }


                    Console.WriteLine("\n");
                    Console.WriteLine("Press enter to clear the board");
                    Console.ReadLine();
                    Console.Clear();
                    wf.whosNext = 1;
                }



                if (turnResponse.ShotStatus == ShotStatus.Victory)
                {
                    var winner = "";
                    if (wf.whosNext == 2)
                    {
                        winner = wf.p1.playerName;
                    }
                    else
                    {
                        winner = wf.p2.playerName;
                    }
                    Console.Clear();
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("*****Congrats, {0}, you've sunk all your oppenent's ships, you win!*****", winner);
                    Console.ResetColor();
                    Console.ReadLine();

                    wf.whosNext = 3;
                }
            } while (wf.whosNext != 3);

            // give some message about who won
            // ask them if they want to play again.
            // if they do, call some method called PlayGame that we haven't made yet which runs the do while loop
            // if they don't, quit the program and say bye
            Console.WriteLine("Press 1 to play again, or press 2 to quit.");
            var num       = Console.ReadLine();
            var final_num = int.Parse(num);

            if (final_num == 1)
            {
                Play();
            }
            else
            {
                return;
            }



            //Turns PlayerTurns = new Turns();
            //PlayerTurns.
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            StartMenu Game1 = new StartMenu();

            //WELCOMES PLAYERS, STORES PLAYER NAMES IN PLAYER OBJ
            while (true)
            {
                //WELCOMES PLAYERS, STORES PLAYER NAMES IN PLAYER OBJ
                Game1.StartGame();

                SetupWorkFlow Player1Setup = new SetupWorkFlow();
                SetupWorkFlow Player2Setup = new SetupWorkFlow();

                GameWorkFlow GameFlow = new GameWorkFlow();

                //INSTRUCTS PLAYER1 TO SET THEIR BOARD

                Game1.SetBoardMessage(Game1.GetPlayer1());

                //COLLECTS/VALIDATES DATA AND SETS THE BOARD FOR PLAYER 1/SETS P1Board in Gameflow TO THE SET BOARD
                GameFlow.setP1Board(Player1Setup.PlaceAllPlayerShips());


                //INSTRUCTS PLAYER 2 TO SET THEIR BOARD
                Game1.SetBoardMessage(Game1.GetPlayer2());

                //COLLECTS/VALIDATES DATA AND SETS THE BOARD FOR PLAYER 2/SETS P2Board in Gameflow TO THE SET BOARD
                GameFlow.setP2Board(Player2Setup.PlaceAllPlayerShips());

                //NOTE:  at this point Gameflow contains set boards for player 1 and player 2

                //SETS PLAYERS NAMES IN GAMEFLOW TO PLAYERS NAMES CREATED DURING SETUP
                GameFlow.SetPlayer1(Game1.GetPlayer1());
                GameFlow.SetPlayer2(Game1.GetPlayer2());

                //CHOOSES WHO GOES FIRST
                GameFlow.FirstTurn();

                while (true)
                {
                    //GETS A SHOT FROM PLAYER AND PROCESSES IT
                    // Displays current players shot history grid
                    // Calls process shot, which prompts player for a shot, and lets the player know if its a hit or miss
                    // updates players shot history (so next turns grid will display updated information)

                    GameFlow.ProcessTurn();

                    //check is victory, if true asks if players want to continue or quit
                    // if player wants to quit, the console program will end
                    // if player wants to play again;

                    // if check for victory returns true, exit the loop and go back to top to start new game


                    if (GameFlow.CheckForVictory()) // if true and player wants to quit game exits within the method via (System.Environment.Exit(0))
                    {
                        break;                      // this should exit the loop and start new game
                    }

                    //if check for victory returns false, continue to next turn
                    else
                    {
                        GameFlow.TrackTurn();
                        Console.WriteLine();
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public static void Play()
        {
            Console.Clear();
            WorkFlowObject wf = new WorkFlowObject
            {

                p1 = new Player()
                {
                    playerBoard = new Board(),
                    playerName = ""
                },

                p2 = new Player()
                {
                    playerBoard = new Board(),
                    playerName = ""
                },

                whosNext = 1
            };

            StartMenu Start = new StartMenu();
            Start.ShowMenu(wf);

            Console.WriteLine("{0} vs {1}\n", wf.p1.playerName, wf.p2.playerName);

            SetUpBoard SetItUp = new SetUpBoard();
            SetItUp.SetUpGame(wf);

            //SetUpBoard SetItUpHard = new SetUpBoard();
            //SetItUpHard.SetUpGameAuto(wf);
            //Console.ReadLine();

            do
            {
                var turn = wf.whosNext;
                var turnResponse = wf.p1.playerBoard.FireShot(new Coordinate(100, 100));
                if (turn == 1)
                {

                    while (turnResponse.ShotStatus == ShotStatus.Invalid || turnResponse.ShotStatus == ShotStatus.Duplicate)
                    {

                        // player 1

                        Console.WriteLine("{0}, press enter to show your board.", wf.p1.playerName);
                        Console.ReadLine();
                        wf.ShowBoard(wf.p2);
                        Console.WriteLine("\n");

                        var finalP1X = 0;
                        do
                        {
                            Console.WriteLine("\n");
                            Console.WriteLine("{0}, enter your x coordinate: ", wf.p1.playerName);
                            var x = Console.ReadLine();
                            switch (x.ToUpper())
                            {
                                case "A":
                                    finalP1X = 1;
                                    break;
                                case "B":
                                    finalP1X = 2;
                                    break;
                                case "C":
                                    finalP1X = 3;
                                    break;
                                case "D":
                                    finalP1X = 4;
                                    break;
                                case "E":
                                    finalP1X = 5;
                                    break;
                                case "F":
                                    finalP1X = 6;
                                    break;
                                case "G":
                                    finalP1X = 7;
                                    break;
                                case "H":
                                    finalP1X = 8;
                                    break;
                                case "I":
                                    finalP1X = 9;
                                    break;
                                case "J":
                                    finalP1X = 10;
                                    break;
                            }
                            if (finalP1X == 0)
                            {
                                Console.WriteLine("\nInvalid inuput, press enter to try again.\n");
                                Console.ReadLine();
                                Console.Clear();
                            }
                            wf.ShowBoard(wf.p2);
                        } while (finalP1X == 0);

                        var finaly = 0;

                        do
                        {
                            Console.WriteLine("\n");
                            Console.WriteLine("{0}, enter your y coordinate: ", wf.p1.playerName);
                            var y = Console.ReadLine();
                            int value;
                            if (int.TryParse(y, out value))
                            {
                                finaly = value;
                            }
                            else
                            {
                                finaly = 0;
                            }
                            if (finaly == 0)
                            {
                                Console.WriteLine("\nInvalid inuput, press enter to try again.\n");
                                Console.ReadLine();
                                Console.Clear();
                            }
                            wf.ShowBoard(wf.p2);
                        } while (finaly == 0);

                        var turnCoordinate = new Coordinate(finalP1X, finaly);

                        turnResponse = wf.p2.playerBoard.FireShot(turnCoordinate);
                       //Console.WriteLine(turnResponse.ShotStatus);

                        if (turnResponse.ShotStatus == ShotStatus.Hit)
                        {
                            wf.ShowBoard(wf.p2);
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("\n");
                            Console.WriteLine("You hit something!");
                            Console.ResetColor();
                        }
                        else if (turnResponse.ShotStatus == ShotStatus.Miss)
                        {
                            wf.ShowBoard(wf.p2);
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine("\n");
                            Console.WriteLine("Your projectile splashes into the ocean, you missed!");
                            Console.ResetColor();
                        }
                        else if (turnResponse.ShotStatus == ShotStatus.HitAndSunk)
                        {
                            wf.ShowBoard(wf.p2);
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("\n");
                            Console.WriteLine("You sank your opponent's {0}", turnResponse.ShipImpacted);
                            Console.ResetColor();
                        }

                    }

                    Console.WriteLine("\n");
                    Console.WriteLine("Press enter to clear the board");
                    Console.ReadLine();
                    Console.Clear();

                    wf.whosNext = 2;

                }
                else
                {
                    while (turnResponse.ShotStatus == ShotStatus.Invalid || turnResponse.ShotStatus == ShotStatus.Duplicate)
                    {

                        // player 2
                        Console.WriteLine("{0}, press enter to show your board.", wf.p2.playerName);
                        Console.ReadLine();
                        wf.ShowBoard(wf.p1);

                        var finalP2X = 0;

                        do
                        {
                            Console.WriteLine("\n");

                            Console.WriteLine("{0}, enter your x coordinate: ", wf.p2.playerName);
                            var x = Console.ReadLine();

                            switch (x.ToUpper())
                            {
                                case "A":
                                    finalP2X = 1;
                                    break;
                                case "B":
                                    finalP2X = 2;
                                    break;
                                case "C":
                                    finalP2X = 3;
                                    break;
                                case "D":
                                    finalP2X = 4;
                                    break;
                                case "E":
                                    finalP2X = 5;
                                    break;
                                case "F":
                                    finalP2X = 6;
                                    break;
                                case "G":
                                    finalP2X = 7;
                                    break;
                                case "H":
                                    finalP2X = 8;
                                    break;
                                case "I":
                                    finalP2X = 9;
                                    break;
                                case "J":
                                    finalP2X = 10;
                                    break;
                            }
                        if (finalP2X == 0)
                            {
                                Console.WriteLine("\nInvalid inuput, press enter to try again.\n");
                                Console.ReadLine();
                                Console.Clear();
                            }
                            wf.ShowBoard(wf.p1);
                        } while (finalP2X == 0);

                        var finaly = 0;

                        do
                        {
                            Console.WriteLine("\n");
                            Console.WriteLine("{0}, enter your y coordinate: ", wf.p2.playerName);
                            var y = Console.ReadLine();
                            int value;
                            if (int.TryParse(y, out value))
                            {
                                finaly = value;
                            }
                            else
                            {
                                finaly = 0;
                            }
                            if (finaly == 0)
                            {
                                Console.WriteLine("\nInvalid inuput, press enter to try again.\n");
                                Console.ReadLine();
                                Console.Clear();
                            }
                            wf.ShowBoard(wf.p1);
                        } while (finaly == 0);

                        var turnCoordinate = new Coordinate(finalP2X, finaly);

                        turnResponse = wf.p1.playerBoard.FireShot(turnCoordinate);
                        //Console.WriteLine(turnResponse.ShotStatus);

                        if (turnResponse.ShotStatus == ShotStatus.Hit)
                        {
                            wf.ShowBoard(wf.p1);
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("\n");
                            Console.WriteLine("You hit something!");
                            Console.ResetColor();
                        }
                        else if (turnResponse.ShotStatus == ShotStatus.Miss)
                        {
                            wf.ShowBoard(wf.p1);
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine("\n");
                            Console.WriteLine("Your projectile splashes into the ocean, you missed!");
                            Console.ResetColor();
                        }
                        else if (turnResponse.ShotStatus == ShotStatus.HitAndSunk)
                        {
                            wf.ShowBoard(wf.p1);
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("\n");
                            Console.WriteLine("You sank your opponent's {0}", turnResponse.ShipImpacted);
                            Console.ResetColor();
                        }
                    }

                    Console.WriteLine("\n");
                    Console.WriteLine("Press enter to clear the board");
                    Console.ReadLine();
                    Console.Clear();
                    wf.whosNext = 1;

                }

                if (turnResponse.ShotStatus == ShotStatus.Victory)
                {
                    var winner = "";
                    if (wf.whosNext == 2)
                    {
                        winner = wf.p1.playerName;
                    }
                    else
                    {
                        winner = wf.p2.playerName;
                    }
                    Console.Clear();
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("*****Congrats, {0}, you've sunk all your oppenent's ships, you win!*****", winner);
                    Console.ResetColor();
                    Console.ReadLine();

                    wf.whosNext = 3;
                }
            } while (wf.whosNext != 3);

            // give some message about who won
            // ask them if they want to play again.
            // if they do, call some method called PlayGame that we haven't made yet which runs the do while loop
            // if they don't, quit the program and say bye
            Console.WriteLine("Press 1 to play again, or press 2 to quit.");
            var num = Console.ReadLine();
            var final_num = int.Parse(num);
            if (final_num == 1)
            {
                Play();
            }
            else return;

            //Turns PlayerTurns = new Turns();
            //PlayerTurns.
        }