Пример #1
0
    void GetAllData()
    {
        XmlDocument xmlDoc = new XmlDocument();                                    // xmlDoc is the new xml document.

        xmlDoc.LoadXml(theXMLFile.text);                                           // load the file.
        XmlNodeList puzzlesList = xmlDoc.GetElementsByTagName("crossword_puzzle"); // array of the level nodes.

        Output += "Total Puzzles inside the file is[" + puzzlesList.Count + "]";
        Output += "\n******************************************";

        foreach (XmlNode puzzleInfo in puzzlesList)
        {
            aPuzzle _tempPuzzle = new aPuzzle();

            _tempPuzzle.number     = puzzleInfo.Attributes["number"].Value;
            _tempPuzzle.difficulty = puzzleInfo.Attributes["difficulty"].Value;
            _tempPuzzle.tag        = puzzleInfo.Attributes["tag"].Value;

            //Debug.Log (puzzleInfo.Attributes["number"].Value);
            //Debug.Log (puzzleInfo.Attributes["difficulty"].Value);
            //Debug.Log (puzzleInfo.Attributes["tag"].Value);
            Output += "\nPuzzle Number[" + _tempPuzzle.number + "]";
            Output += "\nPuzzle Difficulty[" + _tempPuzzle.difficulty + "]";
            Output += "\nPuzzle Tag[" + _tempPuzzle.tag + "]";

            XmlNodeList puzzlecontent = puzzleInfo.ChildNodes;

            foreach (XmlNode puzzleNode in puzzlecontent)
            {
                if (puzzleNode.Name == "title")
                {
                    _tempPuzzle.title = puzzleNode.InnerText;
                    Output           += "\nPuzzle Title[" + _tempPuzzle.title + "]";
                    //Debug.Log (puzzleNode.InnerText);
                }

                if (puzzleNode.Name == "grid")
                {
                    _tempPuzzle.puzzleSize   = puzzleNode.Attributes["size"].Value;
                    _tempPuzzle.puzzleCutout = puzzleNode.Attributes["cutout"].Value;
                    _tempPuzzle.puzzleSolid  = puzzleNode.Attributes["solid"].Value;
                    _tempPuzzle.puzzleData   = puzzleNode.InnerText;

                    //Debug.Log (puzzleNode.Attributes["size"].Value);
                    //Debug.Log (puzzleNode.Attributes["cutout"].Value);
                    //Debug.Log (puzzleNode.Attributes["solid"].Value);
                    //Debug.Log (puzzleNode.InnerText);
                    Output += "\nPuzzle Size[" + _tempPuzzle.puzzleSize + "]";
                    Output += "\nPuzzle Cutout[" + _tempPuzzle.puzzleCutout + "]";
                    Output += "\nPuzzle Solid[" + _tempPuzzle.puzzleSolid + "]";
                    Output += "\nPuzzle Data[" + _tempPuzzle.puzzleData + "]";
                    Output += "\n******************************************";
                }

                //Output += "\n******************************************";
                //Output += "\n***********[ACROSS CLUES]*****************";
                //Output += "\n******************************************";
                if (puzzleNode.Name == "across")
                {
                    XmlNodeList clues = puzzleNode.ChildNodes;
                    foreach (XmlNode clue in clues)
                    {
                        clue _tempClue = new clue();
                        _tempClue.type   = "across";
                        _tempClue.number = clue.Attributes["number"].Value;

                        //Debug.Log ("The across Clue number [" + clue.Attributes["number"].Value + "]");

                        XmlNodeList clueTypes = clue.ChildNodes;
                        foreach (XmlNode clueType in clueTypes)
                        {
                            if (clueType.Name == "primary")
                            {
                                _tempClue.primary = clueType.InnerText;
                                //Debug.Log ("Primary Clue is " + clueType.InnerText);
                            }

                            if (clueType.Name == "alternate")
                            {
                                _tempClue.alternate = clueType.InnerText;
                                //Debug.Log ("Alternate Clue is " + clueType.InnerText);
                            }
                        }
                        _tempPuzzle.acrossClues.Add(_tempClue);
                        //Output += "\n[" + _tempClue.number + "] ---- Primary[" + _tempClue.primary +  "] ---- Alt[" + _tempClue.alternate + "]";
                    }
                }

                //Output += "\n******************************************";
                //Output += "\n***********[DOWN CLUES]*******************";
                //Output += "\n******************************************";
                if (puzzleNode.Name == "down")
                {
                    XmlNodeList clues = puzzleNode.ChildNodes;
                    foreach (XmlNode clue in clues)
                    {
                        clue _tempClue = new clue();
                        _tempClue.type   = "down";
                        _tempClue.number = clue.Attributes["number"].Value;

                        //Debug.Log ("The across Clue number [" + clue.Attributes["number"].Value + "]");

                        XmlNodeList clueTypes = clue.ChildNodes;
                        foreach (XmlNode clueType in clueTypes)
                        {
                            if (clueType.Name == "primary")
                            {
                                _tempClue.primary = clueType.InnerText;
                                //Debug.Log ("Primary Clue is " + clueType.InnerText);
                            }

                            if (clueType.Name == "alternate")
                            {
                                _tempClue.alternate = clueType.InnerText;
                                //Debug.Log ("Alternate Clue is " + clueType.InnerText);
                            }
                        }
                        _tempPuzzle.downClues.Add(_tempClue);
                        //Output += "\n[" + _tempClue.number + "] ---- Primary[" + _tempClue.primary +  "] ---- Alt[" + _tempClue.alternate + "]";
                    }
                }
            }
            puzzles.Add(_tempPuzzle);
        }
        Debug.Log(puzzles.Count);
    }
Пример #2
0
    public void BreakdownXML()
    {
        //xmlFile = (TextAsset)Resources.Load("Sampler", typeof(TextAsset)); //testFile

        XmlDocument xmlDoc = new XmlDocument();                                    // xmlDoc is the new xml document.

        xmlDoc.LoadXml(xmlFile.text);                                              // load the file.
        XmlNodeList puzzlesList = xmlDoc.GetElementsByTagName("crossword_puzzle"); // array of the level nodes.

        //Debug.Log (puzzlesList.Count); // the total amount of puzzles inside the file
        foreach (XmlNode puzzleInfo in puzzlesList)
        {
            aPuzzle _tempPuzzle = new aPuzzle();

            _tempPuzzle.number     = puzzleInfo.Attributes["number"].Value;
            _tempPuzzle.difficulty = puzzleInfo.Attributes["difficulty"].Value;
            _tempPuzzle.tag        = puzzleInfo.Attributes["tag"].Value;

            //Debug.Log (puzzleInfo.Attributes["number"].Value);
            //Debug.Log (puzzleInfo.Attributes["difficulty"].Value);
            //Debug.Log (puzzleInfo.Attributes["tag"].Value);

            XmlNodeList puzzlecontent = puzzleInfo.ChildNodes;

            foreach (XmlNode puzzleNode in puzzlecontent)
            {
                if (puzzleNode.Name == "title")
                {
                    _tempPuzzle.title = puzzleNode.InnerText;
                    //Debug.Log (puzzleNode.InnerText);
                }

                if (puzzleNode.Name == "grid")
                {
                    _tempPuzzle.puzzleSize   = puzzleNode.Attributes["size"].Value;
                    _tempPuzzle.puzzleCutout = puzzleNode.Attributes["cutout"].Value;
                    _tempPuzzle.puzzleSolid  = puzzleNode.Attributes["solid"].Value;
                    _tempPuzzle.puzzleData   = puzzleNode.InnerText;

                    //Debug.Log (puzzleNode.Attributes["size"].Value);
                    //Debug.Log (puzzleNode.Attributes["cutout"].Value);
                    //Debug.Log (puzzleNode.Attributes["solid"].Value);
                    //Debug.Log (puzzleNode.InnerText);
                }

                if (puzzleNode.Name == "across")
                {
                    XmlNodeList clues = puzzleNode.ChildNodes;
                    foreach (XmlNode clue in clues)
                    {
                        clue _tempClue = new clue();
                        _tempClue.type   = "across";
                        _tempClue.number = clue.Attributes["number"].Value;

                        //Debug.Log ("The across Clue number [" + clue.Attributes["number"].Value + "]");

                        XmlNodeList clueTypes = clue.ChildNodes;
                        foreach (XmlNode clueType in clueTypes)
                        {
                            if (clueType.Name == "primary")
                            {
                                _tempClue.primary = clueType.InnerText;
                                //Debug.Log ("Primary Clue is " + clueType.InnerText);
                            }

                            if (clueType.Name == "alternate")
                            {
                                _tempClue.alternate = clueType.InnerText;
                                //Debug.Log ("Alternate Clue is " + clueType.InnerText);
                            }
                        }
                        _tempPuzzle.acrossClues.Add(_tempClue);
                    }
                }

                if (puzzleNode.Name == "down")
                {
                    XmlNodeList clues = puzzleNode.ChildNodes;
                    foreach (XmlNode clue in clues)
                    {
                        clue _tempClue = new clue();
                        _tempClue.type   = "down";
                        _tempClue.number = clue.Attributes["number"].Value;

                        //Debug.Log ("The across Clue number [" + clue.Attributes["number"].Value + "]");

                        XmlNodeList clueTypes = clue.ChildNodes;
                        foreach (XmlNode clueType in clueTypes)
                        {
                            if (clueType.Name == "primary")
                            {
                                _tempClue.primary = clueType.InnerText;
                                //Debug.Log ("Primary Clue is " + clueType.InnerText);
                            }

                            if (clueType.Name == "alternate")
                            {
                                _tempClue.alternate = clueType.InnerText;
                                //Debug.Log ("Alternate Clue is " + clueType.InnerText);
                            }
                        }
                        _tempPuzzle.downClues.Add(_tempClue);
                    }
                }
            }
            puzzles.Add(_tempPuzzle);
        }
        //Debug.Log (puzzles.Count);

        //just for testing
        //GridManager.Instance.currentPuzzle = puzzles[0];
        //GridManager.Instance.BuildTheGrid();
    }