Exemplo n.º 1
0
    public void LoadStageData(int levelNum)
    {
        _config = new ConfigOperator("Level" + levelNum);
        _config.Read();
		
        int targetInt = 0;
        _config.GetIntValue("Target", out targetInt);
        Target = (GameTarget)targetInt;
        _config.GetIntValue("StepLimit", out StepLimit);
        _config.GetIntValue("TimeLimit", out TimeLimit);
        _config.GetIntValue("ColorCount", out ColorCount);
        _config.GetIntValue("Nut1Count", out Nut1Count);
        _config.GetIntValue("Nut2Count", out Nut2Count);
        _config.GetIntValue("NutInitCount", out NutInitCount);
        _config.GetIntValue("NutMaxCount", out NutMaxCount);
        _config.GetIntValue("NutMinCount", out NutMinCount);
        _config.GetIntValue("NutStep", out NutStep);
        _config.GetIntValue("PlusInitCount", out PlusInitCount);
        _config.GetIntValue("PlusMaxCount", out PlusMaxCount);
        _config.GetIntValue("PlusStartTime", out PlusStartTime);
        if (!_config.GetIntValue("PlusStepMin", out PlusStepMin))
        {
            PlusStepMin = 5;
        }
        if (!_config.GetIntValue("PlusStepMax", out PlusStepMax))
        {
            PlusStepMax = 10;
        }
        _config.GetIntValue("Seed", out Seed);

        if (ColorCount == 0)
        {
            ColorCount = 7;
        }

        string temp;
        _config.GetStringValue("StarScore", out temp);
        string [] scoreTokens = temp.Split(',');
        for (int i = 0; i < 3; ++i)
        {
            StarScore[i] = (int)System.Convert.ChangeType(scoreTokens[i], typeof(int));
        }

        if (_config.GetStringValue("CollectCount", out temp))
        {
            string[] collectCountTokens = temp.Split(',');
            for (int i = 0; i < 3; ++i)
            {
                CollectCount[i] = System.Convert.ToInt32(collectCountTokens[i]);
            }
        }

        if (_config.GetStringValue("CollectColors", out temp))
        {
            string[] collectColorTokens = temp.Split(',');
            for (int i = 0; i < 3; ++i)
            {
                CollectColors[i] = (TBlockColor)System.Convert.ToInt32(collectColorTokens[i]);
            }
        }

        if (_config.GetStringValue("CollectSpecial", out temp))
        {
            string[] collectSpecialTokens = temp.Split(',');
            for (int i = 0; i < 3; ++i)
            {
                CollectSpecial[i] = (TSpecialBlock)System.Convert.ToInt32(collectSpecialTokens[i]);
            }
        }

        //GridData

        _config.GetStringValue("GridDataArray", out temp);

        string[] gridDataTokens = temp.Split(',');
        for (int i = 0; i < GameLogic.BlockCountX; ++i )
        {
            for (int j = 0; j < GameLogic.BlockCountY; ++j )
            {
                int number = (int)System.Convert.ChangeType(gridDataTokens[j * GameLogic.BlockCountX + i], typeof(int));
                if ((number & (int)GridFlag.Chocolate) > 0)
                {
                    ++ChocolateCount;
                }
                if ((number & (int)GridFlag.Stone) > 0)
                {
                    ++StoneCount;
                }
                if ((number & (int)GridFlag.Iron) > 0)
                {
                    ++StoneCount;
                }
                GridData[i, j] = number;
            }
        }

        PortalToMap.Clear();
        PortalFromMap.Clear();
        //Portals
        _config.GetStringValue("PortalArray", out temp);
        if (temp != null)
        {
            string[] portalDataTokens = temp.Split(',');
            for (int i = 0; i < portalDataTokens.Length - 4; i += 5)
            {
                Portal portal = new Portal();
                portal.from = new Position((int)System.Convert.ChangeType(portalDataTokens[i], typeof(int)), (int)System.Convert.ChangeType(portalDataTokens[i + 1], typeof(int)));
                portal.to = new Position((int)System.Convert.ChangeType(portalDataTokens[i + 2], typeof(int)), (int)System.Convert.ChangeType(portalDataTokens[i + 3], typeof(int)));
                portal.flag = (int)System.Convert.ChangeType(portalDataTokens[i + 4], typeof(int));
                PortalToMap.Add(portal.to.ToInt(), portal);
                PortalFromMap.Add(portal.from.ToInt(), portal);
            }
        }

        SpecialBlock.Clear();           //清理已有内容
        //Portals
        _config.GetStringValue("SpecialArray", out temp);
        if (temp != null)
        {
            string[] specialDataTokens = temp.Split(',');
            for (int i = 0; i < specialDataTokens.Length - 2; i += 3)
            {
                Position pos = new Position((int)System.Convert.ChangeType(specialDataTokens[i], typeof(int)), (int)System.Convert.ChangeType(specialDataTokens[i + 1], typeof(int)));
                int special = (int)System.Convert.ChangeType(specialDataTokens[i + 2], typeof(int));
                SpecialBlock.Add(pos.ToInt(), special);
            }
        }

        Debug.Log("Level " + levelNum + " Loaded");

        FTUEMap.Clear();

        string ftue = ResourceManager.Singleton.LoadTextFile("FTUE" + levelNum);
        if (ftue != string.Empty)
        {
            List<FTUEData> curFTUEGroup = new List<FTUEData>();
            int step = -1;
            StringReader sr = new StringReader(ftue);
            string line = sr.ReadLine();
            while (line != null)
            {
                if (line.Contains("//"))
                {
                    line = sr.ReadLine();
                    continue;
                }
                if (string.IsNullOrEmpty(line))
                {
                    line = sr.ReadLine();
                    continue;
                }
                string[] values = line.Split(new string[] { "\t", " " }, System.StringSplitOptions.RemoveEmptyEntries);
                if (values.Length > 0)
                {
                    int num = System.Convert.ToInt32(values[0]);

                    if (step == -1)
                    {
                        step = num;
                        FTUEMap.Add(step, curFTUEGroup);                               //添加一个组
                    }
                    else if(num != step)
                    {
                        curFTUEGroup = new List<FTUEData>();
                        step = num;
                        FTUEMap.Add(step, curFTUEGroup);                               //添加一个组
                    }
                    

                    FTUEData data = new FTUEData();
                    data.highLightPosList = new List<Position>();
                    data.headImage = values[1];
                    data.dialog = values[2];
                    string[] posArray;
                    if (values[3] != "None")
                    {
                        posArray = values[3].Split(',');
                        data.from.x = System.Convert.ToInt32(posArray[0]);
                        data.from.y = System.Convert.ToInt32(posArray[1]);
                    }
                    else
                    {
                        data.from.MakeItUnAvailable();
                    }


                    if (values[4] != "None")
                    {
                        posArray = values[4].Split(',');
                        data.to.x = System.Convert.ToInt32(posArray[0]);
                        data.to.y = System.Convert.ToInt32(posArray[1]);
                    }
                    else
                    {
                        data.to.MakeItUnAvailable();
                    }

                    if (values[5] != "None")
                    {
                        posArray = values[5].Split(',');
                        for (int i = 0; i < posArray.Length / 2; ++i)
                        {
                            int x = System.Convert.ToInt32(posArray[i * 2]);
                            int y = System.Convert.ToInt32(posArray[i * 2 + 1]);
                            data.highLightPosList.Add(new Position(x, y));
                        }
                    }

                    if (values.Length > 6)
                    {
                        data.pic = values[6];
                    }
                    else
                    {
                        data.pic = "None";
                    }

                    if (values.Length > 7)
                    {
                        if (System.Convert.ToInt32(values[7]) == 1)
                        {
                            data.bHighLightBackground = true;
                            data.bHighLightBlock = false;
                        }
                        else if (System.Convert.ToInt32(values[7]) == 2)
                        {
                            data.bHighLightBackground = true;
                            data.bHighLightBlock = true;
                        }
						else if (System.Convert.ToInt32(values[7]) == 0)
						{
							data.bHighLightBackground = false;
                        	data.bHighLightBlock = true;
						}
                    }
                    else
                    {
                        data.bHighLightBackground = false;
                        data.bHighLightBlock = true;
                    }

                    if (values.Length > 8)
                    {
                        posArray = values[8].Split(',');

                        data.dialogPos = System.Convert.ToInt32(posArray[0]);
                        data.picturePos = System.Convert.ToInt32(posArray[1]);
                    }

                    curFTUEGroup.Add(data);                               //添加对话数据
                }

                line = sr.ReadLine();
            }
            sr.Close();
        }
    }