Esempio n. 1
0
        //Pre: must pass references to each of the players' piles and playing areas. Player Piles should have only 2 elements (library and discard)
        //Post: none
        //Description: this method resets the game. it clears all piles and playing areas, shuffles the deck, and deals 26 cards to each player.
        public static void ResetGame(ref Pile[] player1Piles, ref Pile[] player2Piles, ref List <Card> p1PlayArea, ref List <Card> p2PlayArea)
        {
            //Clearing the playing area
            p1PlayArea.Clear();
            p2PlayArea.Clear();

            //Clears all piles
            player1Piles[0].ClearPile();
            player1Piles[1].ClearPile();
            player2Piles[0].ClearPile();
            player2Piles[1].ClearPile();

            //Define a new pile that will store all cards
            Pile pile = new Pile(NUM_CARDS_IN_DECK);

            //Add all 52 cards to the deck
            for (int i = 0; i < NUM_CARDS_IN_DECK; i++)
            {
                // i%13 ensures cards only have ranks between 0 and 12. i/13 ensures that there is exactly one card of each rank per suit.
                //The first 13 cards will be of suit 0 (casting to Suit makes it Spades), the next 13 will be of suit 1, and so on.
                pile.Push(new Card(i % NUM_CARDS_IN_SUIT, (Suit)(i / NUM_CARDS_IN_SUIT)));
            }

            //Shuffling the deck
            pile.Shuffle();

            //Deal 26 cards to each player.
            for (int i = 0; i < 26; i++)
            {
                player1Piles[0].Push(pile.Pop());
                player2Piles[0].Push(pile.Pop());
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            //Defining 2 piles per player
            //0 is the library, 1 is the discard pile, and 2 is the playing area
            Pile[] player1Piles = new Pile[2];
            Pile[] player2Piles = new Pile[2];
            //Defining the playing areas of each player
            List <Card> p1PlayArea = new List <Card>();
            List <Card> p2PlayArea = new List <Card>();

            //Initializing the piles of each player
            for (int i = 0; i < 2; i++)
            {
                //The maximum number of cards a pile could contain is set to 52.
                player1Piles[i] = new Pile(NUM_CARDS_IN_DECK);
                player2Piles[i] = new Pile(NUM_CARDS_IN_DECK);
            }

            PlayGame(ref player1Piles, ref player2Piles, ref p1PlayArea, ref p2PlayArea);
        }