Exemple #1
0
        public void Resolve(int num, string msg)
        {
            switch (num)
            {
            case 0:
            {
                //Grid update
                Console.WriteLine(msg);

                if (!showGameInvoked)
                {
                    Invoke(this.form, () => this.form.ShowGame());
                    showGameInvoked = true;
                }

                Data data = JsonConvert.DeserializeObject <Data>(msg);
                ClientManager.Instance.SetGridFromServer(data.Grid, data.DeadPlayers);
                ClientManager.Instance.isAlive = data.Alive;

                // Console.WriteLine(data.Grid);
                break;
            }

            case 1:
            {
                //Handshake successful.
                var id = JsonConvert.DeserializeObject <int>(msg);

                if (!ClientManager.Instance.IDIsSet())
                {
                    ClientManager.Instance.SetPlayerID(id);
                }

                Invoke(this.form, () => this.form.HandshakeSuccessful = true);
                break;
            }

            case 2:
            {
                //Lobby operations
                LobbyData lobbyData = JsonConvert.DeserializeObject <LobbyData>(msg);
                //Dictionary<string, object> lobbyData = JsonConvert.DeserializeObject<Dictionary<string, object>>(msg);
                Invoke(this.form, () => this.form.UpdateLobby(lobbyData));
                break;
            }
            }
        }
Exemple #2
0
 public void UpdateLobby(LobbyData lobbyData)
 {
     lobbyData.playerData.AsEnumerable().ToList().ForEach(x => this.form.showPlayerLobby(int.Parse(x.Key), true, (bool)x.Value, "Igor" + int.Parse(x.Key)));
 }