//method, which assign if player is ready to start the game public static bool ChangeReadinessToPlay(PlayerIsReadyToPlayGameRequest request) { bool assigned = false; try { //check if player with received ID is in the room PlayerData playerData = CurrentPlayersData.Single(p => p.PlayerID == request.PlayerID); if (playerData.PlayerID == request.PlayerID) { //assign readiness status change to proper player foreach (PlayerData item in CurrentPlayersData) { if (item.PlayerID == request.PlayerID) { item.ReadyToPlay = request.IsReadyToPlay; assigned = true; //assignation successful break; } } } } catch (Exception ex) { var logger = NLog.LogManager.GetCurrentClassLogger(); logger.Error("Changing players readiness to start game. Could'n obtain player with matching number." + ex.Message); } return(assigned); }
//with this method player sends info about the fact, that he is ready to play bool IMakaoGameHostService.ChangePlayerReadinessToPlay(PlayerIsReadyToPlayGameRequest request) { //try to assign the readiness status bool assigned = MakaoEngineHostDataPlaceholders.ChangeReadinessToPlay(request); if (assigned) { //after changing readiness to play of specific player, send info to clients //about changes in current players list InfoSenderClass Sender = new InfoSenderClass(); Sender.SendInfoToClientsAboutChangeOfReadiness(ObtainPlayersReadinessData()); //and check if all players confirmed readiness to play if yes, start //procedure of starting the game Task.Run(() => MakaoEngineHostDataPlaceholders.FireUpStartingNewGameAlgorithm(synchCont)); } return(assigned); }
//algorithm method private void StartGameReadinessHandlingMethod(Uri endpoint) { //create factory channel StartNewFactoryChannel(endpoint); //creating the request PlayerIsReadyToPlayGameRequest request = new PlayerIsReadyToPlayGameRequest() { IsReadyToPlay = true, PlayerID = MainWindow.PlayerID, PlayerNumber = MainWindow.PlayerNumber, }; //building proxy and obtaining the response IMakaoGameHostService proxy = factory.CreateChannel(); bool response = proxy.ChangePlayerReadinessToPlay(request); //if response is true, deactivate the button if (response) { SynchCont.Post(_ => ReadyToPlayButton.IsEnabled = false, null); } }