public bool AutomaticShipCoordinates1()
        {
            int shipCount = 0;

            while (true)
            {
                Ships shipType = (Ships)shipCount;
                x_coord = rnd.Next(1, boardSize + 1);
                y_coord = rnd.Next(1, boardSize + 1);
                Player1ShipCoordinates.Add(x_coord.ToString() + y_coord.ToString());
                direction  = GameBoard.directionNumberToString[rnd.Next(0, 2)];
                shipLength = shipCount;
                if (ShipLocationCheck1(x_coord, y_coord,
                                       StringToEnum(direction), shipType))
                {
                    Player1ShipCoordinates.Add(x_coord.ToString() + y_coord.ToString());
                    Player1ShipDirections.Add(StringToEnum(direction));
                    PlaceOneShip(Player1Board1);
                    shipCount++;
                    if (shipCount == 5)
                    {
                        break;
                    }
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
示例#2
0
        public void ManualShipCoordinates1()
        {
            //ask player 1 for ship coordinates
            Console.WriteLine(GetBoardString11());
            Console.WriteLine("Please enter the vertical coordinate of your carrier (1-...)");
            x_coord_string = Console.ReadLine();
            Console.WriteLine("Please enter the horizontal coordinate of your carrier (a-...)");
            y_coord = letterToNumber[Console.ReadLine()];
            Player1ShipCoordinates.Add(x_coord_string + y_coord.ToString());
            Console.WriteLine(
                "Please enter the direction of the ship: \"W\" - west, \"N\" - north, \"E\" - east, \"S\" - south");
            direction = Console.ReadLine().ToUpper();
            Player1ShipDirections.Add(StringToEnum(direction));


            Console.WriteLine(GetBoardString11());
            Console.WriteLine("Please enter the vertical coordinate of your battleship (1-...)");
            x_coord_string = Console.ReadLine();
            Console.WriteLine("Please enter the horizontal coordinate of your battleship (a-...)");
            y_coord = letterToNumber[Console.ReadLine()];
            Player1ShipCoordinates.Add(x_coord_string + y_coord.ToString());
            Console.WriteLine(
                "Please enter the direction of the ship: \"W\" - west, \"N\" - north, \"E\" - east, \"S\" - south");
            direction = Console.ReadLine().ToUpper();
            Player1ShipDirections.Add(StringToEnum(direction));

            Console.WriteLine(GetBoardString11());
            Console.WriteLine("Please enter the vertical coordinate of your submarine (1-...)");
            x_coord_string = Console.ReadLine();
            Console.WriteLine("Please enter the horizontal coordinate of your submarine (a-...)");
            y_coord = letterToNumber[Console.ReadLine()];
            Player1ShipCoordinates.Add(x_coord_string + y_coord.ToString());
            Console.WriteLine(
                "Please enter the direction of the ship: \"W\" - west, \"N\" - north, \"E\" - east, \"S\" - south");
            direction = Console.ReadLine().ToUpper();
            Player1ShipDirections.Add(StringToEnum(direction));

            Console.WriteLine(GetBoardString11());
            Console.WriteLine("Please enter the vertical coordinate of your cruiser (1-...)");
            x_coord_string = Console.ReadLine();
            Console.WriteLine("Please enter the horizontal coordinate of your cruiser (a-...)");
            y_coord = letterToNumber[Console.ReadLine()];
            Player1ShipCoordinates.Add(x_coord_string + y_coord.ToString());
            Console.WriteLine(
                "Please enter the direction of the ship: \"W\" - west, \"N\" - north, \"E\" - east, \"S\" - south");
            direction = Console.ReadLine().ToUpper();
            Player1ShipDirections.Add(StringToEnum(direction));

            Console.WriteLine(GetBoardString11());
            Console.WriteLine("Please enter the vertical coordinate of your patrol (1-...)");
            x_coord_string = Console.ReadLine();
            Console.WriteLine("Please enter the horizontal coordinate of your patrol (a-...)");
            y_coord = letterToNumber[Console.ReadLine()];
            Player1ShipCoordinates.Add(x_coord_string + y_coord.ToString());
            Console.WriteLine(
                "Please enter the direction of the ship: \"W\" - west, \"N\" - north, \"E\" - east, \"S\" - south");
            direction = Console.ReadLine().ToUpper();
            Player1ShipDirections.Add(StringToEnum(direction));
        }
示例#3
0
        public void AutomaticShipCoordinates1()
        {
            for (int i = 0; i < 5; i++)
            {
                StringBuilder sb1 = new StringBuilder();
                sb1.Append(random.Next(0, 10).ToString());
                sb1.Append(random.Next(0, 10).ToString());
                Player1ShipCoordinates.Add(sb1.ToString());

                Player1ShipDirections.Add(NumberToEnum(random.Next(0, 4)));
            }
        }