private static void LoadGameData(dynamic data) { _state = (int)data.State; //init players when the game switched //or players not inited yet //or players num changes (parse players first, and compare number ) List <Player> players = new List <Player>(); if (data != null) { foreach (var item in data.Players) { Player player = new Player(item.Name.ToString(), Convert.ToInt32(item.Index), Convert.ToInt32(item.Color)); players.Add(player); } } if (data.Id.ToString() != _game.id.ToString() || Players == null || Players.Count != players.Count) { Players = new Dictionary <int, Player>(); foreach (var player in players) { Players.Add(player.Index, player); } } //load cells data foreach (var row in data.Cells) { foreach (var item in row) { Cell cell = _map.Locate(Convert.ToInt32(item.X), Convert.ToInt32(item.Y)); cell.Type = Convert.ToInt32(item.Type); cell.State = Convert.ToInt32(item.State); cell.OwnerIndex = Convert.ToInt32(item.Owner); } } }