//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."); }
//called by Monopoly, used to make sure all logic objects //are created, since both CardLogic and GameLogic need //references to each other //INITIALIZATION public void Initialize() { this.Game = this.Monopoly.ActiveGame; this.Players = this.Monopoly.ActiveGame.Players; this.GameLogic = this.Monopoly.GameLogic; this.MoneyLogic = this.Monopoly.MoneyLogic; this.UI = this.Monopoly.UI; this.IsInitialized = true; }