Esempio n. 1
0
        public WarApp()
        {
            // Create a variable to store a deck and get the deck from the
            // DeckUtility class's CreateDeck method
            List <Card> deck = new List <Card>();

            deck = DeckUtility.CreateDeck();

            // Welcome the user
            // Ask the user for the name of player 1 and player 2. Be sure to validate.
            Console.WriteLine("Welcome!");

            string playerOneName = Validate.IsString("Please enter the name for Player One:");
            string playerTwoName = Validate.IsString("Please enter the name for Player Two:");

            // Create two player objects using the info from the user and store
            // them in the players list you created earlier.
            Player playerOne = new Player(playerOneName);
            Player playerTwo = new Player(playerTwoName);

            _players.Add(playerOne);
            _players.Add(playerTwo);

            // Shuffle Deck
            deck = DeckUtility.ShuffleDeck(deck);

            // Give each player half of the deck using the DivideDeck method
            Dictionary <string, List <Card> > deckHalves = DeckUtility.DivideDeck(deck);

            playerOne.deckHalf = deckHalves["first_half"];
            playerTwo.deckHalf = deckHalves["second_half"];

            Play(_players);
        }
Esempio n. 2
0
        public WarApp()
        {
            // Create a variable to store a deck and get the deck from the
            // DeckUtility class's CreateDeck method

            List <Card> newDeck = new List <Card>();

            newDeck = DeckUtility.CreateDeck();

            // Welcome the user
            // Ask the user for the name of player 1 and player 2. Be sure to validate.
            UI.Header("Welcome to the game of War!");
            Console.Write("Who is player One? ");
            string playerOneName = Console.ReadLine();

            playerOneName = Validation.stringValidation(playerOneName);
            Console.Write("Who is player Two? ");
            string playerTwoName = Console.ReadLine();

            playerTwoName = Validation.stringValidation(playerTwoName);



            // Create two player objects using the info from the user and store
            // them in the players list you created earlier.
            // Give each player half of the deck using the DivideDeck method

            Player playerOne = new Player(playerOneName);
            Player playerTwo = new Player(playerTwoName);

            _playerList.Add(playerOne);
            _playerList.Add(playerTwo);

            Dictionary <string, List <Card> > newestDeck = new Dictionary <string, List <Card> >();

            newestDeck = DeckUtility.DivideDeck(newDeck);


            foreach (KeyValuePair <string, List <Card> > deckOfCards in newestDeck)
            {
                foreach (Card cardInDeck in deckOfCards.Value)
                {
                    if (playerOne.playerHand.Count != 26)
                    {
                        playerOne.playerHand.Add(cardInDeck);
                        playerOne.playerHand = DeckUtility.ShuffleDeck(playerOne.playerHand);
                    }
                    else
                    {
                        playerTwo.playerHand.Add(cardInDeck);
                        playerTwo.playerHand = DeckUtility.ShuffleDeck(playerTwo.playerHand);
                    }
                }
            }

            Play();
        }
Esempio n. 3
0
        public WarApp()
        {
            // Create a variable to store a deck and get the deck from the
            // DeckUtility class's CreateDeck method

            List <Card> newDeck = DeckUtility.CreateDeck();


            // Welcome the user
            Console.WriteLine("Welcome to the Card game of War!");
            // Ask the user for the name of player 1 and player 2. Be sure to validate.
            Console.WriteLine("What is the name of player one?");
            string playerOneName = Console.ReadLine();

            Validation.StringValidation(playerOneName);
            Console.WriteLine("What is the name of player two?");
            string playerTwoName = Console.ReadLine();

            Validation.StringValidation(playerTwoName);

            // Create two player objects using the info from the user
            Player playerOne = new Player(playerOneName);
            Player playerTwo = new Player(playerTwoName);

            // and store them in the players list you created earlier
            _players.Add(playerOne);
            _players.Add(playerTwo);

            //shuffle the deck
            List <Card> shuffledDeck = DeckUtility.ShuffleDeck(newDeck);

            // Give each player half of the deck using the DivideDeck method
            Dictionary <string, List <Card> > playerDeck = DeckUtility.DivideDeck(shuffledDeck);

            playerOne.PlayerHand = playerDeck["first_half"];
            playerTwo.PlayerHand = playerDeck["second_half"];

            Play();
        }