public override void ProcessEndOfTurn() { if (GameController.instance.GetTreeCount() <= 0) { return; } // get the first grown tree tile TreesTile tl = null; foreach (var t in GameController.instance.GetTiles(typeof(TreesTile))) { if (((TreesTile)t).CanBeCut()) { tl = (TreesTile)t; } } if (tl == null) { return; } tl.Cut(false); GameController.worldResources["wood"] += 2; }
public void LoadTilesFromJson(string json) { var tiles = TileListFromJson(json); // remove all existing tiles GetAllTiles(); foreach (var t in allTiles) { Destroy(t.gameObject); } foreach (var tile in tiles) { BaseTile newTile = null; string typeName = ""; if (tile.ContainsKey("type")) { typeName = tile["type"].ToString(); // grab any variation of this tile BaseTile t = GetTileVariation(typeName); if (t != null) { newTile = Instantiate(t); } } if (newTile == null) { newTile = Instantiate(GetTileVariation("Grass")); } if (typeName.Length > 0) { switch (typeName) { case "Forest": TreesTile t = (TreesTile)newTile; try { t.growth1 = int.Parse(tile["g1"].ToString()); t.growth2 = int.Parse(tile["g2"].ToString()); t.growth3 = int.Parse(tile["g3"].ToString()); t.growthTurns = int.Parse(tile["growth"].ToString()); } catch (System.Exception) { } t.UpdateTrees(); break; case "Crop": CropTile ct = (CropTile)newTile; ct.growthState = int.Parse(tile["state"].ToString()); ct.growthProgress = int.Parse(tile["growth"].ToString()); ct.UpdatePlants(); break; case "Hut": HutTile ht = (HutTile)newTile; ht.SetHutCount(int.Parse(tile["huts"].ToString())); break; } } // get position Vector3 tilePos = SerializationHelper.JsonToVector(tile["pos"].ToString()); newTile.transform.position = tilePos; } GetAllTiles(); }