Exemplo n.º 1
0
        public void SetUpGameAuto(WorkFlowObject wf)
        {
            //wf.ShowBoard(wf.p1);
            SetUpPlayerAutomatically(wf.p1);

            Console.Clear();

            // wf.ShowBoard(wf.p2);
            SetUpPlayerAutomatically(wf.p2);

            Console.Clear();
        }
Exemplo n.º 2
0
        public void SetUpGameAuto(WorkFlowObject wf)
        {
            //wf.ShowBoard(wf.p1);
            SetUpPlayerAutomatically(wf.p1);

            Console.Clear();

               // wf.ShowBoard(wf.p2);
            SetUpPlayerAutomatically(wf.p2);

            Console.Clear();
        }
Exemplo n.º 3
0
        public void SetUpGame(WorkFlowObject wf)
        {
            wf.ShowBoard(wf.p1);
            SetupPlayer(wf.p1);

            Console.Clear();

            wf.ShowBoard(wf.p2);
            SetupPlayer(wf.p2);

            Console.Clear();
        }
Exemplo n.º 4
0
        public void SetUpGame(WorkFlowObject wf)
        {
            wf.ShowBoard(wf.p1);
            SetupPlayer(wf.p1);

            Console.Clear();

            wf.ShowBoard(wf.p2);
            SetupPlayer(wf.p2);

            Console.Clear();
        }
Exemplo n.º 5
0
        public void ShowMenu(WorkFlowObject wf)
        {
            Console.WriteLine("**** BATTLESHIP ****");

            Console.WriteLine("\n");

            Console.Write("What is player 1's name? ");
            wf.p1.playerName = Console.ReadLine();
            if (wf.p1.playerName == String.Empty)
            {
                wf.p1.playerName = "Player 1";
            }

            Console.WriteLine("\n");

            Console.Write("What is player 2's name? ");
            wf.p2.playerName = Console.ReadLine();
            if (wf.p2.playerName == String.Empty)
            {
                wf.p2.playerName = "Player 2";
            }

            Console.WriteLine("\n");
        }
Exemplo n.º 6
0
        public void ShowMenu(WorkFlowObject wf)
        {
            Console.WriteLine("**** BATTLESHIP ****");

            Console.WriteLine("\n");

            Console.Write("What is player 1's name? ");
            wf.p1.playerName = Console.ReadLine();
            if (wf.p1.playerName == String.Empty)
            {
                wf.p1.playerName = "Player 1";
            }

            Console.WriteLine("\n");

            Console.Write("What is player 2's name? ");
            wf.p2.playerName = Console.ReadLine();
            if (wf.p2.playerName == String.Empty)
            {
                wf.p2.playerName = "Player 2";
            }

            Console.WriteLine("\n");
        }
Exemplo n.º 7
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.
        }
Exemplo n.º 8
0
        public void PlaceTheShips(Player player)
        {
            PlaceShipRequest ShipToPlace = new PlaceShipRequest();

            int howManyShipsPlaced = 0;

            for (int i = 0; i < 5; i++)
            {
                ShipPlacement response;

                do
                {
                    Console.WriteLine("Place your {0} on the x axis with a letter: ", ShipToPlace.ShipType);
                    string userinputXCoord = Console.ReadLine();
                    int    Xcoord          = 0;

                    switch (userinputXCoord.ToUpper())
                    {
                    case "A":
                        Xcoord = 1;
                        break;

                    case "B":
                        Xcoord = 2;
                        break;

                    case "C":
                        Xcoord = 3;
                        break;

                    case "D":
                        Xcoord = 4;
                        break;

                    case "E":
                        Xcoord = 5;
                        break;

                    case "F":
                        Xcoord = 6;
                        break;

                    case "G":
                        Xcoord = 7;
                        break;

                    case "H":
                        Xcoord = 8;
                        break;

                    case "I":
                        Xcoord = 9;
                        break;

                    case "J":
                        Xcoord = 10;
                        break;
                    }

                    Console.WriteLine("\nPlace your {0} on the y axis with a number: ", ShipToPlace.ShipType);
                    string inputYCoord = Console.ReadLine();
                    var    new_string  = 0;
                    if (int.TryParse(inputYCoord, out new_string))
                    {
                        new_string = new_string;
                    }
                    else
                    {
                        new_string = 0;
                    }
                    //int Ycoord = int.Parse(inputYCoord);
                    int Ycoord = new_string;
                    Console.WriteLine("\nWhat direction should your carrier point? (Up, Down, Right, Left): ");
                    string        inputCarrierDirection = Console.ReadLine();
                    ShipDirection myDirection           = 0;
                    switch (inputCarrierDirection.ToUpper())
                    {
                    case "UP":
                    case "U":
                        myDirection = ShipDirection.Up;
                        break;

                    case "DOWN":
                    case "D":
                        myDirection = ShipDirection.Down;
                        break;

                    case "RIGHT":
                    case "R":
                        myDirection = ShipDirection.Right;
                        break;

                    case "LEFT":
                    case "L":
                        myDirection = ShipDirection.Left;
                        break;
                    }

                    ShipToPlace.Direction = myDirection;

                    ShipToPlace.Coordinate = new Coordinate(Xcoord, Ycoord);

                    response = player.playerBoard.PlaceShip(ShipToPlace);

                    if (ShipToPlace.Coordinate.Equals(new Coordinate(0, 0)))
                    {
                        Console.WriteLine("\nInvalid input...Make sure x is a letter, and y is a number. " +
                                          "Press enter to try again.\n");
                        Console.ReadLine();
                    }
                    else
                    {
                        if (response == ShipPlacement.NotEnoughSpace)
                        {
                            Console.WriteLine("\nThere isn't enough room.  Try again.\n");
                            Console.ReadLine();
                        }
                        else if (response == ShipPlacement.Overlap)
                        {
                            Console.WriteLine("\nThat ship overlaps another.  Please try again.\n");
                            Console.ReadLine();
                        }
                    }


                    Console.Clear();

                    //wf.ShowBoard(wf.p1);
                    WorkFlowObject.ShowBoard1(player);
                    Console.WriteLine("\n");
                } while (response != ShipPlacement.Ok);

                ShipToPlace.ShipType++;

                Console.WriteLine("\n");


                howManyShipsPlaced++;

                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("You've placed {0} of 5 ships so far. \n", howManyShipsPlaced);
                Console.ResetColor();
            }
        }
Exemplo n.º 9
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.
        }