예제 #1
0
파일: Program.cs 프로젝트: sev-it/asp.net
 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 
         { 
             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++)
     { 
         Console.WriteLine("Player {0}, enter your name:", p + 1); 
         string playerName = Console.ReadLine(); 
         players[p] = new Player(playerName); 
     }  
     Game newGame = new Game(); 
     newGame.SetPlayers(players); 
     int whoWon = newGame.PlayGame();  
     Console.WriteLine ("{0} has won the game!", players[whoWon].Name);
     Console.ReadKey();
 }
예제 #2
0
        static void Main(string[] args)
        {
            // Display introduction.
            WriteLine("BenjaminCards: a new and exciting version of Rummy.");
            WriteLine("To win you must have 2 sets of cards - a set of 3 and a set of 4.");
            WriteLine("There are 2 types of sets:");
            WriteLine("a) A set of 3 or 4 cards of the same rank (such as 2H, 2D, 2S)");
            WriteLine("b) A sequence of 3 or 4 cards of the same suit (such as 3H, 4H, 5H, 6H)");
            WriteLine();

            // Prompt for number of players.
            bool inputOK = false;
            int  choice  = -1;

            do
            {
                WriteLine("How many players (2-7)?");
                string input = 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++)
            {
                WriteLine($"Player {p + 1}, enter your name:");
                string playerName = ReadLine();
                players[p] = new Player(playerName);
            }

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

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

            // Display winning player.
            WriteLine($"{players[whoWon].Name} has won the game!");

            ReadKey();
        }
예제 #3
0
        static void Main(string[] args)
        {
            // Display introduction.
            // wwwww
            WriteLine("BenjaminCards: a new and exciting card game.");
            WriteLine("To win you must have 7 cards of the game suit in your hand.");
            WriteLine();
            // Prompt for number of players.
            bool inputOK = false;
            int  choice  = -1;

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

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

            // Display winning player.
            WriteLine($"{players[whoWon].Name} has won the game!");
            ReadKey();
        }
예제 #4
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
                {
                    choice = Convert.ToInt32(input);
                    if (choice >= 2 && choice <= 7)
                    {
                        inputOK = true;
                    }
                }
                catch
                {
                    //Ignore failed conversions, just continue prompting
                }
            } while (inputOK == false);

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

            Game newGame = new Game();

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

            Console.WriteLine($"{players[whoWon].Name} has won the game!");
            Console.ReadKey();
        }
예제 #5
0
파일: Program.cs 프로젝트: ktjones/BVCS2012
        static void Main(string[] args)
        {
            // Code for custom exception section.
             //Deck deck1 = new Deck();
             //try
             //{
             //   Card myCard = deck1.GetCard(60);
             //}
             //catch (CardOutOfRangeException e)
             //{
             //   Console.WriteLine(e.Message);
             //   Console.WriteLine(e.DeckContents[0]);
             //}
             //Console.ReadKey();

             // Code for card game client.
                  // 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 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);

             Console.ReadKey();
        }
        static void Main(string[] args)
        {
            #region Code for section "Adding Custom Exceptions to CardLib"
            //Deck deck1 = new Deck();
            //try
            //{
            //    Card myCard = deck1.GetCard(60);
            //}
            //catch (CardOutOfRangeException e)
            //{
            //    Console.WriteLine(e.Message);
            //    Console.WriteLine(e.DeckContents[0]);
            //}
            //Console.ReadKey();
            #endregion

            #region Code for section "A Card Game Client for CardLib"
            // 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 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);
            #endregion
        }