Exemple #1
0
        //METHODS
        //called when deck is initialized
        public void ShuffleDeck()
        {
            String allDescriptions = Resources.CardDescriptions;
            int cardIDMod = 0; //used to assign correct cardIDs
            UI ui = new UI();
            if (this.DeckType == DeckType.CommunityChest)
            {
                Cards = new Card[17]; //wipe deck
                allDescriptions = allDescriptions.Substring(16, allDescriptions.IndexOf("Chance")); //+14 for 'communitychest', +2 for cr and lf
                ui.UIDebug("Community Chest Deck initializing...");
            } else {
                Cards = new Card[16];
                cardIDMod = 17;
                allDescriptions = allDescriptions.Substring(allDescriptions.IndexOf("Chance") + 8); //+6 for 'chance', + 2 for cr and lf
                ui.UIDebug("Chance Deck initializing...");
            }

            String[] cardDescriptions = new String[Cards.Length];
            Card[] orderedCards = new Card[Cards.Length];

            StringReader reader = new StringReader(allDescriptions);

            for(int i = 0; i <= (Cards.Length - 1); i++)
            {
                String line = reader.ReadLine();
                orderedCards[i] = new Card(i + cardIDMod, line);
            }//foreach
            reader.Close();
            ui.UIDebug("Deck is now in proper order. Shuffling...");

            //Begin Fisher-Yates shuffling algorithm
            Random rand = new Random();
            int n = orderedCards.Length;
            for(int i = 0; i <= n - 1; i++)
            {
                int j = rand.Next(i, n);
                Card tempCard = orderedCards[i];
                orderedCards[i] = orderedCards[j];
                orderedCards[j] = tempCard;
            }//for

            this.Cards = orderedCards;
            this.TopCardIndex = 0;
            ui.UIDebug("Deck has been shuffled.");
        }
Exemple #2
0
        public void CardDrawn(Card card)
        {
            String deck;
            if (card.CardID > 16) { deck = "Chance"; }//if
            else { deck = "Community Chest"; }

            Display("You draw a " + deck + " card.");

            String cap = String.Format("Player {0}: {1}", Game.GetActivePlayer().GameID, deck);
            String msg = "You drew a card. " + Environment.NewLine + "It says: " + card.Description;
            DisplayPopup(msg, cap);
        }
        public void TestRRUtilCards()
        {
            //create two players, p1 advances to nearest railroad and buys it
            //p2 advances to nearest rr and must pay doubles
            //reset state
            //p1 advances to nearest utility and buys it
            //p2 advances to nearest utility and must pay 10X roll

            Player player1 = ActiveGame.Players[0];
            Player player2 = ActiveGame.Players[1];
            Card testRRCard = new Card(20, "Advance to RR");
            Card testUtilCard = new Card(19, "Advance to Util");

            ActiveGame.ActivePlayerID = 0;
            CardLogic.HandleCard(testRRCard, 0);
            ActiveGame.ActivePlayerID = 1;
            CardLogic.HandleCard(testRRCard, 1);
            DebugPlayerInfo(player1, player2);

            ActiveGame.SetState(); //reset state
            player1 = ActiveGame.Players[0];
            player2 = ActiveGame.Players[1];

            ActiveGame.ActivePlayerID = 0;
            CardLogic.HandleCard(testUtilCard, 0);
            ActiveGame.ActivePlayerID = 1;
            CardLogic.HandleCard(testUtilCard, 1);
            DebugPlayerInfo(player1, player2);

            //TODO: Test currently fails. Think it has something to do with the ActivePlayer position at the start of the game.
        }
Exemple #4
0
        //Contains cases for handling all cards
        //METHODS
        public void HandleCard(Card card, int playerID)
        {
            UI.CardDrawn(card);

            switch (card.CardID)
            {
                case 0://Advance to Go
                    GameLogic.AdvancePlayerToPosition(playerID, 1);
                    break;
                case 1://Collect 75$
                    MoneyLogic.CollectFromBank(playerID, 75);
                    break;
                case 2://Pay $50
                    MoneyLogic.CollectFromBank(playerID, -50);
                    break;
                case 3://Get out of jail free
                    Players[playerID].JailFreeCards++;
                    break;
                case 4://Go to jail
                    GameLogic.SendToJail(playerID);
                    break;
                case 5: //collect 10 from each player
                    MoneyLogic.CollectFromOtherPlayers(playerID, 10);
                    break;
                case 6://colect $50 from each player
                    MoneyLogic.CollectFromOtherPlayers(playerID, 50);
                    break;
                case 7://collect $20
                    MoneyLogic.CollectFromBank(playerID, 20);
                    break;
                case 8://collect 100
                    MoneyLogic.CollectFromBank(playerID, 100);
                    break;
                case 9: //pay 100
                    MoneyLogic.CollectFromBank(playerID, -100);
                    break;
                case 10://pay 50
                    MoneyLogic.CollectFromBank(playerID, -50);
                    break;
                case 11://collect 25
                    MoneyLogic.CollectFromBank(playerID, 25);
                    break;
                case 12://Street repairs, see method
                    Repairs(playerID, 40, 115);
                    break;
                case 13://collect 10
                    MoneyLogic.CollectFromBank(playerID, 10);
                    break;
                case 14://collect 100
                    MoneyLogic.CollectFromBank(playerID, 100);
                    break;
                case 15://collect 50
                    MoneyLogic.CollectFromBank(playerID, 50);
                    break;
                case 16://Collect 100;
                    MoneyLogic.CollectFromBank(playerID, 100);
                    break;
                case 17://Advance To Go
                    GameLogic.AdvancePlayerToPosition(playerID, 1);
                    break;
                case 18: //Advance To Illinois
                    GameLogic.AdvancePlayerToPosition(playerID, 25);
                    break;
                case 19://Advance To Utility (13 and 29), pay 10x dice roll
                    AdvanceToUtility(playerID);
                    break;
                case 20: //Advance to nearest railroad, pay double
                    this.AdvanceToRailroad(playerID);
                    break;
                case 21: //Advance To St Charles Place (12)
                    GameLogic.AdvancePlayerToPosition(playerID, 12);
                    break;
                case 22: //collect 50
                    MoneyLogic.CollectFromBank(playerID, 50);
                    break;
                case 23://Get out of Jail Free
                    Players[playerID].JailFreeCards++;
                    break;
                case 24://Go back three spaces
                    GameLogic.AdvancePlayer(playerID, -3);
                    break;
                case 25: //GoToJail
                    GameLogic.SendToJail(playerID);
                    break;
                case 26: //General repairs, see method
                    Repairs(playerID, 25, 100);
                    break;
                case 27: //Pay 15
                    MoneyLogic.CollectFromBank(playerID, -15);
                    break;
                case 28: //go to reading railroad
                    GameLogic.AdvancePlayerToPosition(playerID, 6);
                    break;
                case 29://Go to boardwalk
                    GameLogic.AdvancePlayerToPosition(playerID, 40);
                    break;
                case 30: //pay each player 50
                    MoneyLogic.CollectFromOtherPlayers(playerID, -50);
                    break;
                case 31://collect 150
                    MoneyLogic.CollectFromBank(playerID, 150);
                    break;
                case 32: //collect 100
                    MoneyLogic.CollectFromBank(playerID, 100);
                    break;
            }//switch
        }
 public void TestJailCard()
 {
     ActiveGame.ActivePlayerID = 0;
     Player activePlayer = ActiveGame.GetActivePlayer();
     Card jailFreeCard = new Card(23, "Get out of Jail Free");
     Card jailCard = new Card(25, "Go to Jail");
     CardLogic.HandleCard(jailFreeCard, 0);
     CardLogic.HandleCard(jailCard, 0);
     GameLogic.Turn(GameLogic.RollDice());
 }