public TextTable() { if (Singleton == null) { Singleton = this; _textConfig = new ConfigOperator(); } else { throw new System.Exception(); //if singleton exist, throw a Exception } }
public CapsConfig() { if (Instance == null) { _config = new ConfigOperator("GameConfig"); Instance = this; InitData(); GameObject obj = GameObject.Find("GlobalObject"); CurAudioList = obj.GetComponent<AudioList>(); } else { throw new Exception("重复的实例"); } }
public void SaveStageData(int levelNum) //保存关卡数据到一个文件 { _config = new ConfigOperator("Level" + levelNum); _config.Write("Target", (int)Target); _config.Write("StepLimit", StepLimit); _config.Write("TimeLimit", TimeLimit); _config.Write("ColorCount", ColorCount); _config.Write("Nut1Count", Nut1Count); _config.Write("Nut2Count", Nut2Count); _config.Write("NutInitCount", NutInitCount); _config.Write("NutMaxCount", NutMaxCount); _config.Write("NutMinCount", NutMinCount); _config.Write("NutStep", NutStep); _config.Write("PlusInitCount", PlusInitCount); _config.Write("PlusMaxCount", PlusMaxCount); _config.Write("PlusStartTime", PlusStartTime); _config.Write("PlusStepMin", PlusStepMin); _config.Write("PlusStepMax", PlusStepMax); _config.Write("Seed", Seed); _config.Write("NewFormat", 1); //新格式标记 string temp = string.Empty; for (int i = 0; i < 3; ++i ) { temp = temp + StarScore[i] + ","; } _config.Write("StarScore", temp); temp = string.Empty; for (int i = 0; i < 3; ++i) { temp = temp + (int)CollectColors[i] + ","; } _config.Write("CollectColors", temp); temp = string.Empty; for (int i = 0; i < 3; ++i) { temp = temp + (int)CollectSpecial[i] + ","; } _config.Write("CollectSpecial", temp); temp = string.Empty; for (int i = 0; i < 3; ++i) { temp = temp + CollectCount[i] + ","; } _config.Write("CollectCount", temp); temp = string.Empty; for (int j = 0; j < GameLogic.BlockCountY; ++j) { for (int i = 0; i < GameLogic.BlockCountX; ++i) { temp = temp + GridData[i, j] + ","; } } _config.Write("GridDataArray", temp); temp = string.Empty; foreach(KeyValuePair<int, Portal> pair in PortalToMap) { temp = temp + pair.Value.from.x + ","; temp = temp + pair.Value.from.y + ","; temp = temp + pair.Value.to.x + ","; temp = temp + pair.Value.to.y + ","; temp = temp + pair.Value.flag + ","; } _config.Write("PortalArray", temp); //保存画面上的特殊块 temp = string.Empty; for (int j = 0; j < GameLogic.BlockCountY; ++j) { for (int i = 0; i < GameLogic.BlockCountX; ++i) { CapBlock block = GameLogic.Singleton.GetBlock(new Position(i, j)); if (block != null && block.special != TSpecialBlock.ESpecial_Normal) { temp = temp + i + ","; temp = temp + j + ","; temp = temp + (int)block.special+ ","; } } } _config.Write("SpecialArray", temp); _config.Save(); Debug.Log("Level " + levelNum + " Saved"); }
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(); } }
public void SaveStageData(int levelNum) //保存关卡数据到一个文件 { _config = new ConfigOperator("Level" + levelNum); _config.Write("Target", (int)Target); _config.Write("StepLimit", StepLimit); _config.Write("TimeLimit", TimeLimit); _config.Write("ColorCount", ColorCount); _config.Write("Nut1Count", Nut1Count); _config.Write("Nut2Count", Nut2Count); _config.Write("NutInitCount", NutInitCount); _config.Write("NutMaxCount", NutMaxCount); _config.Write("NutStep", NutStep); _config.Write("PlusInitCount", PlusInitCount); _config.Write("PlusMaxCount", PlusMaxCount); _config.Write("PlusStartTime", PlusStartTime); _config.Write("PlusStep", PlusStep); _config.Write("Seed", Seed); _config.Write("NewFormat", 1); //新格式标记 string temp = string.Empty; for (int i = 0; i < 3; ++i ) { temp = temp + StarScore[i] + ","; } _config.Write("StarScore", temp); temp = string.Empty; for (int j = 0; j < GameLogic.BlockCountY; ++j) { for (int i = 0; i < GameLogic.BlockCountX; ++i) { temp = temp + GridData[i, j] + ","; } } _config.Write("GridDataArray", temp); temp = string.Empty; foreach(KeyValuePair<int, Portal> pair in PortalToMap) { temp = temp + pair.Value.from.x + ","; temp = temp + pair.Value.from.y + ","; temp = temp + pair.Value.to.x + ","; temp = temp + pair.Value.to.y + ","; temp = temp + pair.Value.flag + ","; } _config.Write("PortalArray", temp); _config.Save(); Debug.Log("Level " + levelNum + " Saved"); }
public void LoadStageData(int levelNum) { _config = new ConfigOperator("Level" + levelNum); _config.Read(); int targetInt = 0; _config.GetValue<int>("Target", out targetInt); Target = (GameTarget)targetInt; _config.GetValue<int>("StepLimit", out StepLimit); _config.GetValue<int>("TimeLimit", out TimeLimit); _config.GetValue<int>("ColorCount", out ColorCount); _config.GetValue<int>("Nut1Count", out Nut1Count); _config.GetValue<int>("Nut2Count", out Nut2Count); _config.GetValue<int>("NutInitCount", out NutInitCount); _config.GetValue<int>("NutMaxCount", out NutMaxCount); _config.GetValue<int>("NutStep", out NutStep); _config.GetValue<int>("PlusInitCount", out PlusInitCount); _config.GetValue<int>("PlusMaxCount", out PlusMaxCount); _config.GetValue<int>("PlusStartTime", out PlusStartTime); _config.GetValue<int>("PlusStep", out PlusStep); _config.GetValue<int>("Seed", out Seed); if (ColorCount == 0) { ColorCount = 7; } string temp; _config.GetValue<string>("StarScore", out temp); string [] scoreTokens = temp.Split(','); for (int i = 0; i < 3; ++i) { StarScore[i] = (int)System.Convert.ChangeType(scoreTokens[i], typeof(int)); } //GridData _config.GetValue<string>("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)); GridData[i, j] = number; } } PortalToMap.Clear(); PortalFromMap.Clear(); //Portals _config.GetValue<string>("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); } } Debug.Log("Level " + levelNum + " Loaded"); }