Exemple #1
0
        static void Main(string[] args)
        {
            Battleship battle = new Battleship();

            battle.Start();

            bool won = false;

            do
            {
                Console.Write("Enter coordinate: ");
                var key = Console.ReadLine();
                if (battle.ValidateCoordinates(key))
                {
                    battle.Fight(key.ToString(), out string result);
                    if (battle.AllHaveSunk())
                    {
                        won = true;
                        Console.WriteLine("You won. All ships are sunk.");
                    }
                    else
                    {
                        Console.WriteLine(result);
                    }
                }
                else
                {
                    Console.WriteLine("You're coordinates are not ok. Please try again");
                }
            }while (won == false);

            Console.ReadKey();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            //setup the game (make the console bigger and recieve the player names)
            Console.SetWindowSize(80, 55);

            string input;

            Console.WriteLine("Player 1 will go first.");

            //Initialise Player1
            Console.WriteLine("What is player 1's name?");
            input = Console.ReadLine().ToUpper();
            Player player1;

            if (input == "")
            {
                input = "CPU";
            }
            player1 = new Player(input);

            //Initialise Player2
            Console.WriteLine("What is player 2's name? (Leave blank to play against the computer)");
            input = Console.ReadLine().ToUpper();
            Player player2;

            if (input == "")
            {
                input = "CPU";
            }
            player2 = new Player(input);

            Console.Clear();

            //Initialise a game of battleship between the two players and then begin the game.
            Battleship game = new Battleship(player1, player2);

            game.Start();
        }