Пример #1
0
        static void Main(string[] args)
        {
            // Display introduction
            Console.WriteLine("KarliCards: a new and exciting card game.");
            Console.WriteLine("To win, you must have 7 cards of the same suit in your hand.");
            Console.WriteLine();

            // Prompt for number of players
            bool inputOkay       = false;
            int  numberOfPlayers = -1;

            do
            {
                Console.WriteLine("How many players (2-7)?");
                string input = Console.ReadLine();
                try
                {
                    // Attempt to convert input into a valid number of players
                    numberOfPlayers = Convert.ToInt32(input);
                    if (numberOfPlayers >= 2 && numberOfPlayers <= 7)
                    {
                        inputOkay = true;
                    }
                }
                catch
                {
                    // Ignore failed conversions, just continue prompting
                }
            } while (inputOkay == false);

            // Initialize player array
            Player[] players = new Player[numberOfPlayers];

            // Get player names
            for (int p = 0; p < players.Length; p++)
            {
                Console.WriteLine("Player {0}, enter your name:", p + 1);
                string playerName = Console.ReadLine();

                // Create a new player object for the player array
                players[p] = new Player(playerName);
            }

            // Start the game
            Game newGame = new Game();

            newGame.SetPlayers(players);
            int whoWon = newGame.PlayGame();

            // Display winning player
            Console.WriteLine("{0} has won the game!", players[whoWon].Name);
            Console.ReadKey();
        }
Пример #2
0
        static void Main(string[] args)
        {
            // Display introduction.

            Console.WriteLine("Beanie card game");
            Console.WriteLine();

            // Prompt for number of players.
            bool inputOK = false;
            int choice = -1;
            do
            {
                Console.WriteLine("How many players (2-7)?");
                string input = Console.ReadLine();
                try
                {
                    // Attempt to convert input into a valid number of players.
                    choice = Convert.ToInt32(input);
                    if ((choice >= 2) && (choice <= 7))
                        inputOK = true;
                }
                catch
                {
                    // Ignore failed conversions, just continue prompting.
                }
            } while (inputOK == false);

            // Initialize array of Player objects.
            Player[] players = new Player[choice];

            // Get player names.
            for (int p = 0; p < players.Length; p++)
            {
                Console.WriteLine("Player {0}, enter your name:", p + 1);
                string playerName = Console.ReadLine();
                players[p] = new Player(playerName);
            }

            // Start game.
            Game newGame = new Game();
            newGame.SetPlayers(players);
            int whoWon = newGame.PlayGame();

            // Display winning player.
            Console.WriteLine("{0} has won the game!", players[whoWon].Name);
        }
Пример #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("KarliCards: a new and exciting card game.");
            Console.WriteLine("To win you must have 7 cards of the same suit in" +
                              " your hand.");
            Console.WriteLine();
            bool inputOK = false;
            int  choice  = -1;

            do
            {
                Console.WriteLine("How many players (2–7)?");
                string input = Console.ReadLine();
                try
                {
                    // Attempt to convert input into a valid number of players.
                    choice = Convert.ToInt32(input);
                    if ((choice >= 2) && (choice <= 7))
                    {
                        inputOK = true;
                    }
                }
                catch
                {
                    // Ignore failed conversions, just continue prompting.
                }
            } while (inputOK == false);
            // Initialize array of Player objects.
            Player[] players = new Player[choice];
            // Get player names.
            for (int p = 0; p < players.Length; p++)
            {
                Console.WriteLine("Player {0}, enter your name:", p + 1);
                string playerName = Console.ReadLine();
                players[p] = new Player(playerName);
            }
            // Start game.
            Game newGame = new Game();

            newGame.SetPlayers(players);
            int whoWon = newGame.PlayGame();

            // Display winning player.
            Console.WriteLine("{0} has won the game!", players[whoWon].Name);
        }
Пример #4
0
        static void Main(string[] args)
        {
            WriteLine("BenjaminCards: a new and exciting card game.");
            WriteLine("To win you must have 7 cards of the same suit in your hand.");
            WriteLine();
            bool inputOK = false;
            int  choice  = -1;

            do
            {
                WriteLine("How many players (2-7)?");
                string input = ReadLine();
                try
                {
                    choice = Convert.ToInt32(input);
                    if ((choice >= 2) && (choice <= 7))
                    {
                        inputOK = true;
                    }
                }
                catch
                {
                }
            } while (inputOK == false);
            Player[] players = new Player[choice];
            for (int p = 0; p < players.Length; p++)
            {
                WriteLine($"Player {p + 1},enter your name:");
                string playerName = ReadLine();
                players[p] = new Player(playerName);
            }
            Game newGame = new Game();

            newGame.SetPlayers(players);
            int whoWon = newGame.PlayGame();

            WriteLine($"{players[whoWon].Name} has won the game!");
            ReadKey();
        }