Exemple #1
0
        public void ShipUI(Ship ship, Player player)
        {
            Console.WriteLine("{0} SETUP", name.ToUpper());
            Console.WriteLine("Where will you place your {0}?", ship.name.ToUpper());
            field.Print(player, player.field);
            Console.Write("Row: ");
            string row = Console.ReadLine();

            Console.Write("Column: ");
            string col = Console.ReadLine();

            Console.Write("Which direction will the ship point? (Enter 'Up', 'Down', 'Left', or 'Right'): ");
            string dir = Console.ReadLine();

            try
            {
                bool isValid = ValidateSpot(row, col, dir, ship);
                if (isValid == true)
                {
                    PlaceThisShip(row, col, dir, ship);
                    Console.Clear();
                }
                else
                {
                    Console.WriteLine("One or more spaces you chose overlaps with another ship. Press Enter to try again.");
                    Console.ReadLine();
                    Console.Clear();
                    ShipUI(ship, player);
                }
            }
            catch (IndexOutOfRangeException)
            {
                Console.WriteLine("The coordinates you selected would put the ship off the grid. Please select new coordinates.");
                Console.WriteLine("Press Enter to retry");
                Console.ReadLine();
                Console.Clear();
                ShipUI(ship, player);
            }
            catch (FormatException)
            {
                Console.WriteLine("Please enter a numerical value.");
                Console.WriteLine("Press Enter to retry");
                Console.ReadLine();
                Console.Clear();
                ShipUI(ship, player);
            }
        }