Esempio n. 1
0
        public List <Figure> CreateMazeFromTextFile(string filePath)
        {
            if (filePath.Equals(""))
            {
                filePath = @"E:\StandardFile.txt";
            }
            figureList = new List <Figure>();
            TextFileParser parser      = new TextFileParser();
            bool           isFirstLine = true;

            Dictionary <int, string[]> dict = parser.CreateStringDictionary(filePath);

            if (dict == null)
            {
                return(null);
            }

            for (int i = 0; i < dict.Count; i++)
            {
                if (isFirstLine == true)
                {
                    maze          = mazeTypeConverter[dict[0].First()];
                    factoryObject = mazeList[maze].getInstance();
                    isFirstLine   = false;
                    continue;
                }
                else
                {
                    string[] param = dict[i];
                    if (param[0].Equals("Room"))
                    {
                        factoryObject.AddRoom(param, figureList);
                    }
                    else if (param[0].Equals("Corritage"))
                    {
                        factoryObject.AddCorritage(param, figureList);
                    }
                    else if (param[0].Equals("Key") && maze == MazeType.MAGIC)
                    {
                        KeyCounter++;
                        factoryObject.AddKey(param, figureList);
                    }
                    else if (param[0].Equals("MagicRoom") && maze == MazeType.MAGIC)
                    {
                        factoryObject.AddRoom(param, figureList);
                    }
                }
            }
            return(figureList);
        }