/// <summary> /// Checks if the client is in a game. /// If so, the model attemps to fetch his opponent. /// if the opponent exists, a reply is sent to him. /// otherwise the function exists. /// if the game does not exist the function exists. /// </summary> /// <param name="from">the client that sent the command.</param> /// <param name="commandParsed">The parsed command.</param> public override void Execute(object from, string[] commandParsed) { string move = commandParsed[1]; int commandType = 4; object otherClient; PlayAnswer ans = new PlayAnswer(); // retrieve game MultiplayerGame game = model.IsClientInGame(from); if (game == null) { return; } // get the second player from the game game.RetrieveOtherClient(from, out otherClient); // a client tries to play while he's the only one in the game if (otherClient == null) { return; } ans.Name = game.GetName(); ans.Move = move; string reply = new Answer().GetJSONAnswer(commandType, ans); model.CompletedTask(otherClient, new View.MessageEventArgs(reply)); }
/// <summary> /// Checks if a given client is in a game. If so, he is removed, and if the game contains 0 players /// it is removed from the model. /// Otherwise, nothing is done. /// </summary> /// <param name="from">the client that sent the command.</param> /// <param name="commandParsed">The parsed command.</param> public override void Execute(object from, string[] commandParsed) { MultiplayerGame game = model.IsClientInGame(from); if (game == null) { return; } game.RemoveClient(from); // game is empty if (game.Count == 0) { model.RemoveMultiplayerGame(game.GetName()); } }