Exemplo n.º 1
0
        public static ShipDirection PickADirection()
        {
            string        directionTemp = "";
            ShipDirection Direction     = new ShipDirection();

            Console.WriteLine("Pick a direction");
            directionTemp = ConsoleInput.ReadLine();


            if (directionTemp == "Up" || directionTemp == "up")
            {
                Direction = ShipDirection.Up;
            }
            else if (directionTemp == "Down" || directionTemp == "down")
            {
                Direction = ShipDirection.Down;
            }
            else if (directionTemp == "Right" || directionTemp == "right")
            {
                Direction = ShipDirection.Right;
            }
            else if (directionTemp == "Left" || directionTemp == "left")
            {
                Direction = ShipDirection.Left;
            }
            else
            {
                Console.WriteLine("Invalid use, try again");
                Console.ReadKey();
                PickADirection();
            }
            return(Direction);
        }
Exemplo n.º 2
0
        public static string P2_name()
        {
            Console.WriteLine("Player 2: enter your name please");
            string answer = ConsoleInput.ReadLine();

            return(answer);
        }
Exemplo n.º 3
0
        public static void replay()
        {
            Console.WriteLine("Would you like to play again?  Yes or no ");
            string answer = ConsoleInput.ReadLine();

            if (answer == "Yes" || answer == "yes" || answer == "Y" || answer == "y")
            {
                GameFlow.Flow();
            }
            else
            {
                Console.WriteLine("Thanks for playing!, press any key to quit");
                Console.ReadKey();
            }
        }
Exemplo n.º 4
0
        public static Coordinate InputtoCoordinate()
        {
            Console.WriteLine("Enter A Coordinate (A-J for row, 1-10 for column  EX: A1, B2, C3)");
            int    First_int = 0;
            string Input     = ConsoleInput.ReadLine();

            if (Input.Length <= 1)
            {
                Console.WriteLine("Invalid input, Try again");
                return(InputtoCoordinate());
            }
            string First_String = Input.Substring(0, 1);


            switch (First_String)
            {
            case "A":
                First_int = 1;
                break;

            case "a":
                First_int = 1;
                break;

            case "B":
                First_int = 2;
                break;

            case "b":
                First_int = 2;
                break;

            case "C":
                First_int = 3;
                break;

            case "c":
                First_int = 3;
                break;

            case "D":
                First_int = 4;
                break;

            case "d":
                First_int = 4;
                break;

            case "E":
                First_int = 5;
                break;

            case "e":
                First_int = 5;
                break;

            case "F":
                First_int = 6;
                break;

            case "f":
                First_int = 6;
                break;

            case "G":
                First_int = 7;
                break;

            case "g":
                First_int = 7;
                break;

            case "H":
                First_int = 8;
                break;

            case "h":
                First_int = 8;
                break;

            case "I":
                First_int = 9;
                break;

            case "i":
                First_int = 9;
                break;

            case "J":
                First_int = 10;
                break;

            case "j":
                First_int = 10;
                break;

            default:
                Console.WriteLine("Sorry, try again");
                return(InputtoCoordinate());

                break;
            }

            string Second_String = Input.Substring(Input.Length - 1, 1);
            string Third_String  = Input.Substring(Input.Length - 2, 2);
            int    Second_int    = 0;

            if ((Second_String == "1" || Second_String == "2" || Second_String == "3" || Second_String == "4" || Second_String == "5" || Second_String == "6" || Second_String == "7" || Second_String == "8" || Second_String == "9"))
            {
                Second_int = Convert.ToInt32(Second_String);
            }
            else if (Third_String == "10")
            {
                Second_int = 10;
            }
            else
            {
                Console.WriteLine("Invalid coordinates, try again");
                return(InputtoCoordinate());
            }

            Coordinate Answer = new Coordinate(First_int, Second_int);

            return(Answer);
        }
Exemplo n.º 5
0
        public static ShipType UserTypeShip(Board x, int Count)
        {
            ShipType ship = new ShipType();

            Console.WriteLine("Enter a Ship type");
            string typeofship = ConsoleInput.ReadLine();


            if (typeofship == "Destroyer" || typeofship == "destroyer")
            {
                ship = ShipType.Destroyer;
            }
            else if (typeofship == "Submarine" || typeofship == "submarine")
            {
                ship = ShipType.Submarine;
            }
            else if (typeofship == "Cruiser" || typeofship == "cruiser")
            {
                ship = ShipType.Cruiser;
            }
            else if (typeofship == "Battleship" || typeofship == "battleship")
            {
                ship = ShipType.Battleship;
            }
            else if (typeofship == "Carrier" || typeofship == "carrier")
            {
                ship = ShipType.Carrier;
            }
            else
            {
                Console.WriteLine("Invalid Ship type, try again");
                UserTypeShip(x, Count);
            }


            for (int i = Count; i < 5; i++)
            {
                if (Count == 1)
                {
                    if (x.Ships[i - 1].ShipType == ship)
                    {
                        Console.WriteLine("You've got a duplicate ship, try again!");
                        ship = UserTypeShip(x, Count);
                    }
                }
                else if (Count == 2)
                {
                    if ((x.Ships[i - 1].ShipType == ship) || (x.Ships[i - 2].ShipType == ship))
                    {
                        Console.WriteLine("You've got a duplicate ship, try again!");
                        ship = UserTypeShip(x, Count);
                    }
                }
                else if (Count == 3)
                {
                    if ((x.Ships[i - 1].ShipType == ship) || (x.Ships[i - 2].ShipType == ship) || (x.Ships[i - 3].ShipType == ship))
                    {
                        Console.WriteLine("You've got a duplicate ship, try again!");
                        ship = UserTypeShip(x, Count);
                    }
                }
                else if (Count == 4)
                {
                    if ((x.Ships[i - 1].ShipType == ship) || (x.Ships[i - 2].ShipType == ship) || (x.Ships[i - 3].ShipType == ship) || (x.Ships[i - 4].ShipType == ship))
                    {
                        Console.WriteLine("You've got a duplicate ship, try again!");
                        ship = UserTypeShip(x, Count);
                    }
                }
                break;
            }



            return(ship);
        }