Ejemplo n.º 1
0
 /// <summary>
 /// Add another stack of cards to the stack.
 /// </summary>
 /// <param name="newCards">The other stack of cards</param>
 public void add(Stack newCards)
 {
     while (!newCards.isEmpty())
     {
         Card newCard = newCards.draw();
         add(newCard);
     }
 }
Ejemplo n.º 2
0
        public void ShuffleCurrentDeck()
        {
            CardClass[] deckArray = deck.ToArray();
            int first, second;
            int length = deckArray.Length;
            CardClass temp;
            for (int i = 0; i < 30; i++)
            {
                first = rand.Next(length);
                second = rand.Next(length);
                temp = deckArray[first];
                deckArray[first] = deckArray[second];
                deckArray[second] = temp;
            }

            deck = new Stack<CardClass>(deckArray);
        }
Ejemplo n.º 3
0
 public Deck(PlayerTurn player)
 {
     deck = new Stack<CardClass>();
     owner = player;
 }
Ejemplo n.º 4
0
        public MapView(string n, GraphicsDevice gd)
            : base(n)
        {
            // This would be where to create the map of whatever size. We are starting with 5 by 5, but the gate is out of that.
            // So we need an extra one on both sides. The other extras will just be marked as filled by something.
            map = new CardClass[7, 7];

            turns.Add(new Turn1(map.GetLength(1), map.GetLength(0)));
            if (type == GameType.Player1)
                turns.Add(new AITurn(map.GetLength(1), map.GetLength(0), this));
            else
                turns.Add(new Turn2(map.GetLength(1), map.GetLength(0)));

            cardTypes = new List<CardType>();

            activeTurn = turns[0];
            winner = 0;

            moveStack = new Stack<MoveList>();
            movementSteps = new Stack<MoveSteps>(3);

            SetCenter(new Vector2((gd.Viewport.Width - CardClass.cardWidth * map.GetLength(1)) / 2, (gd.Viewport.Height - CardClass.cardHeight * map.GetLength(1)) / 2));
        }
Ejemplo n.º 5
0
        private bool RecursiveCardMovement(CardClass card, Vector2 cardLoc, MoveLocation currentLoc, MoveLocation[,] map, int transX, int transY, uint ID, bool place)
        {
            if (transX == 2 && transY == 2)
            {
                return true;
            }

            bool placed = false;

            Stack<MoveLocation> order = new Stack<MoveLocation>(2);
            while (currentLoc.x >= 0 && currentLoc.y >= 0 && !(currentLoc.x == 2 && currentLoc.y == 2))
            {
                order.Push(currentLoc);
                currentLoc = map[currentLoc.x, currentLoc.y];
            }
            order.Push(currentLoc);

            MoveLocation next;
            while (order.Count > 1)
            {
                currentLoc = order.Pop();
                next = order.Peek();
                if (place)
                {
                    placed = PlaceCard(card, (int)cardLoc.X + next.y - 2, (int)cardLoc.Y + next.x - 2, next.y, next.x, ID, place) || placed;
                }
                else
                {
                    placed = PlaceCard(card, (int)cardLoc.X + next.y - 2, (int)cardLoc.Y + next.x - 2, next.y, next.x, ID, place);
                }
                if (!placed)
                    return placed;
            }

            //if (currentLoc.x >= 0 && currentLoc.y >= 0 && !(currentLoc.x == 2 && currentLoc.y == 2))
            //{
            //    if (!RecursiveCardMovement(card, cardLoc, map[currentLoc.x, currentLoc.y], map, currentLoc.y, currentLoc.x))
            //        return recurse;
            //}
            ////PlaceCard(selectedCard, (int)mapLoc.X, (int)mapLoc.Y, moveOption[transY, transX].modifier)

            if (place)
            {
                placed = PlaceCard(card, (int)cardLoc.X + transX - 2, (int)cardLoc.Y + transY - 2, transX, transY, ID, place) || placed;
            }
            else
            {
                placed = PlaceCard(card, (int)cardLoc.X + transX - 2, (int)cardLoc.Y + transY - 2, transX, transY, ID, place);
            }

            return placed;
        }
Ejemplo n.º 6
0
        public MapView()
            : base()
        {
            // This would be where to create the map of whatever size. We are starting with 5 by 5, but the gate is out of that.
            // So we need an extra one on both sides. The other extras will just be marked as filled by something.
            map = new CardClass[7,7];

            turns[0] = new Turn1(map.GetLength(0), map.GetLength(1));
            if (type == GameType.Player1)
                turns[1] = new AITurn(map.GetLength(0), map.GetLength(1), this);
            else
                turns[1] = new Turn2(map.GetLength(0), map.GetLength(1));

            cardTypes = new List<CardType>();
            moveStack = new Stack<MoveList>();

            activeTurn = turns[0];
            winner = 0;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// This program will simulate a slightly modified version of the
        /// card game War.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // Create a deck of cards and shuffle it.
            Deck deck = new Deck();
            deck.reset();
            deck.shuffle();

            // Create a stack of cards for each player and allow them
            // to hold a full deck.
            Stack playerStack1 = new Stack(deck.getSize());
            Stack playerStack2 = new Stack(deck.getSize());

            // Divide the deck between the two players.
            while (!deck.isEmpty())
            {
                Card nextCard = deck.draw();
                playerStack1.add(nextCard);

                nextCard = deck.draw();
                playerStack2.add(nextCard);
            }

            // Each player will also have a second stack of cards
            // to hold all the cards won during the round.
            Stack playerWinnings1;
            Stack playerWinnings2;

            // Create a stack of "draw cards" to hold matching cards
            // until a winner is determined.
            Stack drawCards = new Stack(playerStack1.getSize() + playerStack2.getSize());

            int roundsCompleted = 0;
            while (!playerStack1.isEmpty() && !playerStack2.isEmpty())
            {
                // Create a stack for each player's winnings.
                playerWinnings1 = new Stack(playerStack1.getSize() + playerStack2.getSize());
                playerWinnings2 = new Stack(playerStack1.getSize() + playerStack2.getSize());

                // Keep playing the round until someone is out of cards.
                while (!playerStack1.isEmpty() && !playerStack2.isEmpty())
                {
                    // Draw one card from each player's stack.
                    Card playerCard1 = playerStack1.draw();
                    Card playerCard2 = playerStack2.draw();

                    //Console.WriteLine(playerCard1.getDescription() + " vs. " + playerCard2.getDescription());

                    // Compare the ranks of the two cards.
                    int rank1 = playerCard1.getRank();
                    int rank2 = playerCard2.getRank();

                    if (rank1 > rank2)
                    {
                        // Give player 1 both cards and any draw cards.
                        playerWinnings1.add(drawCards);
                        playerWinnings1.add(playerCard1);
                        playerWinnings1.add(playerCard2);
                        //Console.WriteLine("- Player 1 wins!");
                    }
                    else
                    {
                        if (rank2 > rank1)
                        {
                            // Give player 2 both cards and any draw cards.
                            playerWinnings2.add(drawCards);
                            playerWinnings2.add(playerCard2);
                            playerWinnings2.add(playerCard1);
                            //Console.WriteLine("- Player 2 wins!");
                        }
                        else
                        {
                            // Place both players' cards in the draw stack.
                            drawCards.add(playerCard1);
                            drawCards.add(playerCard2);
                            //Console.WriteLine("- It's a draw!");
                        }
                    }

                    //Console.ReadKey();
                }

                // Add any winnings to the end of each player's stack
                // for the next round.
                playerStack1.add(playerWinnings1);
                playerStack2.add(playerWinnings2);

                Console.WriteLine("Player 1 wins " + playerStack1.getSize() + " cards.");
                Console.WriteLine("Player 2 wins " + playerStack2.getSize() + " cards.");
                //Console.ReadKey();

                roundsCompleted += 1;
            }

            Console.WriteLine(roundsCompleted);
            Console.ReadKey();
        }