Beispiel #1
0
        public void InitializeCards(DeckOfCards chanceCards, DeckOfCards communityChestCards)
        {
            // XML Reading Variables
            XmlReader xmlReader;

            xmlReader = XmlReader.Create("GameData/ChanceCards.xml");      // Set the XML file to read Chance Cards

            string currentDescription      = "";
            int    currentMoneyAdded       = 0;
            int    currentMoneySubtracted  = 0;
            int    currentPositionModifier = 0;
            int    currentPositionMover    = 0;
            bool   currentPerPlayer        = false;
            string currentSpecial          = "";

            int chanceCardInfoCounter = 0;

            // Read in XML data for Chance Cards
            while (xmlReader.Read())
            {
                XmlNodeType nodeType = xmlReader.NodeType;
                if (nodeType == XmlNodeType.Element)
                {
                    switch (xmlReader.Name)
                    {
                    case "Description":
                        currentDescription = ReadStringFromCurrentNode(xmlReader, ref chanceCardInfoCounter);
                        break;

                    case "MoneyAdded":
                        currentMoneyAdded = Convert.ToUInt16(ReadStringFromCurrentNode(xmlReader, ref chanceCardInfoCounter));
                        break;

                    case "MoneySubtracted":
                        currentMoneySubtracted = Convert.ToUInt16(ReadStringFromCurrentNode(xmlReader, ref chanceCardInfoCounter));
                        break;

                    case "PositionModifier":
                        currentPositionModifier = Convert.ToInt16(ReadStringFromCurrentNode(xmlReader, ref chanceCardInfoCounter));
                        break;

                    case "PositionMover":
                        currentPositionMover = Convert.ToInt16(ReadStringFromCurrentNode(xmlReader, ref chanceCardInfoCounter));
                        break;

                    case "PerPlayer":

                        string boolCheck = ReadStringFromCurrentNode(xmlReader, ref chanceCardInfoCounter);

                        if (boolCheck == "true")
                        {
                            currentPerPlayer = true;
                        }
                        else if (boolCheck == "false")
                        {
                            currentPerPlayer = false;
                        }
                        else
                        {
                            Console.WriteLine("Warning! Invalid value in Chance Card XML file for PerPlayer");
                        }
                        break;

                    case "Special":
                        currentSpecial = ReadStringFromCurrentNode(xmlReader, ref chanceCardInfoCounter);

                        if (chanceCardInfoCounter == 7)
                        {
                            // Create the Card and add it to the list of Chance Cards
                            chanceCards.AddCard(
                                new Card(
                                    currentDescription,
                                    currentPositionModifier,
                                    currentPositionMover,
                                    currentMoneyAdded,
                                    currentMoneySubtracted,
                                    currentPerPlayer,
                                    currentSpecial));

                            // Reset the Card Counter
                            chanceCardInfoCounter = 0;
                        }
                        else
                        {
                            Console.Error.WriteLine("ERROR! Chance Card is missing data!");
                        }
                        break;
                    }
                }
            }

            int communityChestCardInfoCounter = 0;

            xmlReader.Close();
            xmlReader = XmlReader.Create("GameData/CommunityChestCards.xml");        // Set the XML reader to read Community Chest Cards XML

            // Read in XML data for Community Chest Cards
            while (xmlReader.Read())
            {
                XmlNodeType nodeType = xmlReader.NodeType;
                if (nodeType == XmlNodeType.Element)
                {
                    switch (xmlReader.Name)
                    {
                    case "Description":
                        currentDescription = ReadStringFromCurrentNode(xmlReader, ref communityChestCardInfoCounter);
                        break;

                    case "MoneyAdded":
                        currentMoneyAdded = Convert.ToUInt16(ReadStringFromCurrentNode(xmlReader, ref communityChestCardInfoCounter));
                        break;

                    case "MoneySubtracted":
                        currentMoneySubtracted = Convert.ToUInt16(ReadStringFromCurrentNode(xmlReader, ref communityChestCardInfoCounter));
                        break;

                    case "PositionModifier":
                        currentPositionModifier = Convert.ToInt16(ReadStringFromCurrentNode(xmlReader, ref communityChestCardInfoCounter));
                        break;

                    case "PositionMover":
                        currentPositionMover = Convert.ToInt16(ReadStringFromCurrentNode(xmlReader, ref communityChestCardInfoCounter));
                        break;

                    case "PerPlayer":

                        string boolCheck = ReadStringFromCurrentNode(xmlReader, ref communityChestCardInfoCounter);

                        if (boolCheck == "true")
                        {
                            currentPerPlayer = true;
                        }
                        else if (boolCheck == "false")
                        {
                            currentPerPlayer = false;
                        }
                        else
                        {
                            Console.WriteLine("Warning! Invalid value in Chance Card XML file for PerPlayer");
                        }
                        break;

                    case "Special":
                        currentSpecial = ReadStringFromCurrentNode(xmlReader, ref communityChestCardInfoCounter);

                        if (communityChestCardInfoCounter == 7)
                        {
                            // Create the Card and add it to the list of Chance Cards
                            communityChestCards.AddCard(
                                new Card(
                                    currentDescription,
                                    currentPositionModifier,
                                    currentPositionMover,
                                    currentMoneyAdded,
                                    currentMoneySubtracted,
                                    currentPerPlayer,
                                    currentSpecial));

                            // Reset the Card Counter
                            communityChestCardInfoCounter = 0;
                        }
                        else
                        {
                            Console.Error.WriteLine("ERROR! Community Chest Card is missing data!");
                        }
                        break;
                    }
                }
            }

            // Shuffle both decks of cards
            chanceCards.ShuffleDeck();
            communityChestCards.ShuffleDeck();
        }
Beispiel #2
0
        public void InitializeCards(DeckOfCards chanceCards, DeckOfCards communityChestCards)
        {
            // XML Reading Variables
            XmlReader xmlReader;
            xmlReader = XmlReader.Create("GameData/ChanceCards.xml");      // Set the XML file to read Chance Cards

            string currentDescription = "";
            int currentMoneyAdded = 0;
            int currentMoneySubtracted = 0;
            int currentPositionModifier = 0;
            int currentPositionMover = 0;
            bool currentPerPlayer = false;
            string currentSpecial = "";

            int chanceCardInfoCounter = 0;

            // Read in XML data for Chance Cards
            while (xmlReader.Read())
            {
                XmlNodeType nodeType = xmlReader.NodeType;
                if (nodeType == XmlNodeType.Element)
                {
                    switch (xmlReader.Name)
                    {
                        case "Description":
                            currentDescription = ReadStringFromCurrentNode(xmlReader, ref chanceCardInfoCounter);
                            break;
                        case "MoneyAdded":
                            currentMoneyAdded = Convert.ToUInt16(ReadStringFromCurrentNode(xmlReader, ref chanceCardInfoCounter));
                            break;
                        case "MoneySubtracted":
                            currentMoneySubtracted = Convert.ToUInt16(ReadStringFromCurrentNode(xmlReader, ref chanceCardInfoCounter));
                            break;
                        case "PositionModifier":
                            currentPositionModifier = Convert.ToInt16(ReadStringFromCurrentNode(xmlReader, ref chanceCardInfoCounter));
                            break;
                        case "PositionMover":
                            currentPositionMover = Convert.ToInt16(ReadStringFromCurrentNode(xmlReader, ref chanceCardInfoCounter));
                            break;
                        case "PerPlayer":

                            string boolCheck = ReadStringFromCurrentNode(xmlReader, ref chanceCardInfoCounter);

                            if (boolCheck == "true")
                                currentPerPlayer = true;
                            else if (boolCheck == "false")
                                currentPerPlayer = false;
                            else
                                Console.WriteLine("Warning! Invalid value in Chance Card XML file for PerPlayer");
                            break;
                        case "Special":
                            currentSpecial = ReadStringFromCurrentNode(xmlReader, ref chanceCardInfoCounter);

                            if (chanceCardInfoCounter == 7)
                            {
                                // Create the Card and add it to the list of Chance Cards
                                chanceCards.AddCard(
                                    new Card(
                                        currentDescription,
                                        currentPositionModifier,
                                        currentPositionMover,
                                        currentMoneyAdded,
                                        currentMoneySubtracted,
                                        currentPerPlayer,
                                        currentSpecial));

                                // Reset the Card Counter
                                chanceCardInfoCounter = 0;
                            }
                        else
                            Console.Error.WriteLine("ERROR! Chance Card is missing data!");
                        break;
                    }

                }
            }

            int communityChestCardInfoCounter = 0;

            xmlReader.Close();
            xmlReader = XmlReader.Create("GameData/CommunityChestCards.xml");        // Set the XML reader to read Community Chest Cards XML

            // Read in XML data for Community Chest Cards
            while (xmlReader.Read())
            {
                XmlNodeType nodeType = xmlReader.NodeType;
                if (nodeType == XmlNodeType.Element)
                {
                    switch (xmlReader.Name)
                    {
                        case "Description":
                            currentDescription = ReadStringFromCurrentNode(xmlReader, ref communityChestCardInfoCounter);
                            break;
                        case "MoneyAdded":
                            currentMoneyAdded = Convert.ToUInt16(ReadStringFromCurrentNode(xmlReader, ref communityChestCardInfoCounter));
                            break;
                        case "MoneySubtracted":
                            currentMoneySubtracted = Convert.ToUInt16(ReadStringFromCurrentNode(xmlReader, ref communityChestCardInfoCounter));
                            break;
                        case "PositionModifier":
                            currentPositionModifier = Convert.ToInt16(ReadStringFromCurrentNode(xmlReader, ref communityChestCardInfoCounter));
                            break;
                        case "PositionMover":
                            currentPositionMover = Convert.ToInt16(ReadStringFromCurrentNode(xmlReader, ref communityChestCardInfoCounter));
                            break;
                        case "PerPlayer":

                            string boolCheck = ReadStringFromCurrentNode(xmlReader, ref communityChestCardInfoCounter);

                            if (boolCheck == "true")
                                currentPerPlayer = true;
                            else if (boolCheck == "false")
                                currentPerPlayer = false;
                            else
                                Console.WriteLine("Warning! Invalid value in Chance Card XML file for PerPlayer");
                            break;
                        case "Special":
                            currentSpecial = ReadStringFromCurrentNode(xmlReader, ref communityChestCardInfoCounter);

                            if (communityChestCardInfoCounter == 7)
                            {
                                // Create the Card and add it to the list of Chance Cards
                                communityChestCards.AddCard(
                                    new Card(
                                        currentDescription,
                                        currentPositionModifier,
                                        currentPositionMover,
                                        currentMoneyAdded,
                                        currentMoneySubtracted,
                                        currentPerPlayer,
                                        currentSpecial));

                                // Reset the Card Counter
                                communityChestCardInfoCounter = 0;
                            }
                            else
                                Console.Error.WriteLine("ERROR! Community Chest Card is missing data!");
                            break;
                    }

                }
            }

            // Shuffle both decks of cards
            chanceCards.ShuffleDeck();
            communityChestCards.ShuffleDeck();
        }