/// <summary> /// set level from startData, doesn matter if it for expample/screen or for game /// </summary> /// <param name="startData"></param> public void SetLevel(LondonToweGameStartWinData startData) { foreach (LondonToweSphereScript sphere in spheres) { Destroy(sphere.gameObject); } spheres.Clear(); foreach (LondonTowePoleScript pole in poles) { if (pole.id == 1) { pole.SetCapacity(startData.Pole1Size); } else if (pole.id == 2) { pole.SetCapacity(startData.Pole2Size); } else if (pole.id == 3) { pole.SetCapacity(startData.Pole3Size); } } int counter = startData.pole1.Count; foreach (string s in startData.pole1) { counter--; LondonToweSphereScript createdSphere = (LondonToweSphereScript)Instantiate(spherePrefab, new Vector3(0, 0.5f + counter* 1.5f, 0), new Quaternion()); spheres.Add(createdSphere); createdSphere.start = true; createdSphere.orderOnPole = startData.Pole1Size - counter; createdSphere.gameManager = this; createdSphere.setIdColor(s, spheresIDColor[s]); } counter = startData.pole2.Count; foreach (string s in startData.pole2) { counter--; LondonToweSphereScript createdSphere = (LondonToweSphereScript)Instantiate(spherePrefab, new Vector3(4, 0.5f + counter* 1.5f, 0), new Quaternion()); spheres.Add(createdSphere); createdSphere.start = true; createdSphere.orderOnPole = startData.Pole2Size - counter; createdSphere.gameManager = this; createdSphere.setIdColor(s, spheresIDColor[s]); } counter = startData.pole3.Count; foreach (string s in startData.pole3) { counter--; LondonToweSphereScript createdSphere = (LondonToweSphereScript)Instantiate(spherePrefab, new Vector3(8, 0.5f + counter* 1.5f, 0), new Quaternion()); spheres.Add(createdSphere); createdSphere.start = true; createdSphere.orderOnPole = startData.Pole3Size - counter; createdSphere.gameManager = this; createdSphere.setIdColor(s, spheresIDColor[s]); } foreach (LondonToweSphereScript sp in spheres) { sp.GetComponent<Rigidbody>().useGravity = true; } minimap.SetActive(true); string path = "GoalsPictures/" + startGame.GameID; Texture minimapSprite = (Resources.Load<Texture>(path) as Texture); if (minimapSprite == null) { Debug.Log("cannot load"); } minimap.GetComponent<Renderer>().material.mainTexture = minimapSprite; }
/// <summary> /// call at level start, create all necessary steps to load level, take screen etc /// </summary> public void StartGame() { MGC.Instance.getMinigameStates().SetPlayed(MGC.Instance.selectedMiniGameName, MGC.Instance.selectedMiniGameDiff); LondonToweXMLGameLoader loader = new LondonToweXMLGameLoader(); foreach (TextAsset gameData in xmlLevels) { data.AddRange(loader.ParseXmlTextAsset(gameData)); } // numbers 0, 1,2 ; 0 easier - only 3 spheres on poles int numberOfSpehre = MGC.Instance.selectedMiniGameDiff + 3; List<LondonToweGameStartWinData> filteredDificulty = new List<LondonToweGameStartWinData>(); foreach (LondonToweGameStartWinData game in data) { if ((game.pole1.Count + game.pole2.Count + game.pole3.Count) == numberOfSpehre) { filteredDificulty.Add(game); } } levelSet = filteredDificulty[Random.Range(0, filteredDificulty.Count - 1)].GameID; foreach (LondonToweGameStartWinData level in data) { if (level.GameID == levelSet) { if (level.IsStart()) { startGame = level; } else { endGame = level; } } } poles = new List<LondonTowePoleScript>(FindObjectsOfType<LondonTowePoleScript>()); SetLevel(startGame); foreach (LondonToweSphereScript sphere in spheres) { sphere.gameManager = this; } foreach (LondonTowePoleScript pole in poles) { pole.gameManager = this; } state = LondonTowerGameState.game; }
private List<LondonToweGameStartWinData> ParseXml(XmlReader xr) { int idGame; int rodeCount = 0; bool start = true; while (xr.Read()) { if (xr.NodeType == XmlNodeType.Element) { if (xr.Name == "level") { idGame = int.Parse(xr.GetAttribute("lid")); pokus1 = new LondonToweGameStartWinData(true, idGame); pokus2 = new LondonToweGameStartWinData(false, idGame); start = true; rodeCount = 0; } else if (xr.Name == "rod") { start = true; rodeCount++; int size = int.Parse(xr.GetAttribute("height")); if (rodeCount == 1) { pokus1.Pole1Size = size; pokus2.Pole1Size = size; } else if (rodeCount == 2) { pokus1.Pole2Size = size; pokus2.Pole2Size = size; } else if (rodeCount == 3) { pokus1.Pole3Size = size; pokus2.Pole3Size = size; } } else if (xr.Name == "solution") { start = false; } else if (xr.Name == "sphere") { if (start) { if (rodeCount == 1) { pokus1.pole1.Add(xr.GetAttribute("color")); } else if (rodeCount == 2) { pokus1.pole2.Add(xr.GetAttribute("color")); } else if (rodeCount == 3) { pokus1.pole3.Add(xr.GetAttribute("color")); } } else { if (rodeCount == 1) { pokus2.pole1.Add(xr.GetAttribute("color")); } else if (rodeCount == 2) { pokus2.pole2.Add(xr.GetAttribute("color")); } else if (rodeCount == 3) { pokus2.pole3.Add(xr.GetAttribute("color")); } } } } // loading element vaue else if ((xr.NodeType == XmlNodeType.EndElement) && (xr.Name == "level")) { if (pokus1 != null && pokus2 != null) { data.Add(pokus1); data.Add(pokus2); } } } return data; }