private void ManageMessage(Object sender, NewMessageEvent newMessage) { if (newMessage.Message == "ERROR") { _error = true; ReceiveDone.Set(); } string[] decompostion = newMessage.Message.Split(' '); string type = decompostion[0]; switch (type) { case "GAMEMODE": _idGameMode = int.Parse(decompostion[1].Split('=')[1]); ReceiveDone.Set(); break; case "PLAYER": _idPlayer = int.Parse(decompostion[1].Split('=')[1]); ReceiveDone.Set(); break; case "GAMES": _gameModes = new List <CurrentGameMode>(); foreach (var info in decompostion) { if (info == "GAMES") { continue; } if (info == "") { continue; } _gameModes.Add(DecryptGame(info)); } ReceiveDone.Set(); break; case "NEWPLAYER": bool ready = bool.Parse(decompostion[1].Split('=')[1]); if (ready) { StartGame?.Invoke(this, new StartGameEvent()); } else { NewPlayer?.Invoke(this, new NewPlayerEvent { Player = DecryptPlayer(decompostion[2]) }); } break; case "ADDPLAYER": _isReady = bool.Parse(decompostion[1].Split('=')[1]); ReceiveDone.Set(); break; case "PLAYERSGAME": _players = new List <Player>(); foreach (var info in decompostion) { if (info == "PLAYERSGAME") { continue; } if (info == "") { continue; } _players.Add(DecryptPlayer(info)); } ReceiveDone.Set(); break; case "ERRORGAME": ErrorGames?.Invoke(this, new ErrorGamesEvent()); break; case "DELPLAYER": DeletePLayer?.Invoke(this, new DeletePlayerEvent(int.Parse(decompostion[1].Split('=')[1]))); break; case "SWITCH": SwitchCell?.Invoke(this, new SwitchCellEvent(int.Parse(decompostion[1].Split('=')[1]), int.Parse(decompostion[2].Split('=')[1]), int.Parse(decompostion[3].Split('=')[1]))); break; case "STARTGEN": StartGenEv?.Invoke(this, new StartGenEvent()); break; case "DIFFGEN": _cells = new List <Cell>(); if (decompostion[1] == "FIN") { _cells = null; ReceiveDone.Set(); break; } foreach (var info in decompostion) { if (info == "DIFFGEN") { continue; } if (info == "") { continue; } _cells.Add(DecryptCell(info)); } ReceiveDone.Set(); break; case "GETZONE": _zone = new List <Cell>(); foreach (var info in decompostion) { if (info == "DIFFGEN") { continue; } if (info == "") { continue; } _zone.Add(DecryptCell(info)); } ReceiveDone.Set(); break; } }