public StateEngine(string pathToJson) { JObject jobj = (JObject)JsonConvert.DeserializeObject(File.ReadAllText(pathToJson)); JToken token = jobj.SelectToken("Map"); this.gameMap = token.ToObject <Map>(); JToken round = jobj.SelectToken("RoundNumber"); this.round = round.ToObject <int>(); this.mapMiddleIndex = Convert.ToInt32(Math.Round(((double)this.gameMap.Height / (double)2), 0, MidpointRounding.AwayFromZero)); token = jobj.SelectToken("Players"); PlayerJson[] players = token.ToObject <PlayerJson[]>(); foreach (PlayerJson player in players) { if (player.PlayerNumber == 1) { this.Deity = player; } else { this.otherGuy = player; } } }
public StateEngine(string pathToJson) { JObject jobj = (JObject)JsonConvert.DeserializeObject(File.ReadAllText(pathToJson)); JToken token = jobj.SelectToken("Map"); this.gameMap = token.ToObject<Map>(); JToken round = jobj.SelectToken("RoundNumber"); this.round = round.ToObject<int>(); this.mapMiddleIndex = Convert.ToInt32(Math.Round(((double)this.gameMap.Height / (double)2), 0, MidpointRounding.AwayFromZero)); token = jobj.SelectToken("Players"); PlayerJson[] players = token.ToObject<PlayerJson[]>(); foreach (PlayerJson player in players) { if (player.PlayerNumber == 1) { this.Deity = player; } else { this.otherGuy = player; } } }