/// <summary> /// Method to receive player data /// </summary> /// <param name="playerReceived">The data player</param> public void PlayerReceived(ServicePlayer playerReceived) { player = playerReceived; lName.Content = player.NamePlayer; lLastName.Content = player.LastName; lNickname.Content = player.NickName; }
/// <inheritdoc/> public void NotifyCardWasUncoveredd(PlayerMovementDto playerMovementDto) { string host = playerMovementDto.Host; ServiceMatch gameMatch = GetMatch(host); ServicePlayer player = gameMatch.GetPlayer(playerMovementDto.Username); if (playerMovementDto.HasFormedAPair) { player.AddUncoveredCard(playerMovementDto.CardIndex); gameMatch.TotalPairs++; } else { if (playerMovementDto.MovementsLeft == 0) { player.RemoveUncoveredCard(); } else { player.AddUncoveredCard(playerMovementDto.CardIndex); } } IList <ServicePlayer> playersInMatch = gameMatch.GetPlayersConnectedToMatch(); foreach (var playerInMatch in playersInMatch) { playerInMatch.MatchServiceConnection.UncoverCardd(playerMovementDto.CardIndex); } }
/// <inheritdoc/> public void EndTurn(string host, string username, CardPairDto cardPairDto) { ServiceMatch gameMatch = GetMatch(host); ServicePlayer player = gameMatch.GetPlayer(username); int indexOfPlayerWithCurrentTurn = gameMatch.GetPlayersConnectedToMatch().IndexOf(player); if (cardPairDto.BothCardsAreEqual) { player.Score += 100; } else { indexOfPlayerWithCurrentTurn = ChangeTurn(gameMatch, indexOfPlayerWithCurrentTurn); } ServicePlayer nextPlayer = gameMatch.GetPlayersConnectedToMatch()[indexOfPlayerWithCurrentTurn]; player.HasActiveTurn = false; nextPlayer.HasActiveTurn = true; IList <ServicePlayer> playersInMatch = gameMatch.GetPlayersConnectedToMatch(); foreach (var playerInMatch in playersInMatch) { playerInMatch.MatchServiceConnection.NotifyTurnHasEnded(nextPlayer.Username, cardPairDto); } if (gameMatch.TotalPairs == gameMatch.ServiceCardDeck.NumberOfPairs) { this.NotifyMatchHasEnded(host); } }
/// <inheritdoc/> public void NotifyMatchHasEnded(string host) { ServiceMatch gameMatch = GetMatch(host); if (host != null) { ServicePlayer playerWithBestScore = gameMatch.GetPlayerWithBestScore(); string usernameOfPlayerWithBestScore = playerWithBestScore.Username; IList <ServicePlayer> playersConnectedToMatch = gameMatch.GetPlayersConnectedToMatch(); foreach (var playerConnected in playersConnectedToMatch) { var channel = playerConnected.MatchServiceConnection; channel.ShowWinners(usernameOfPlayerWithBestScore); channel.MatchHasEnded(); } UnitOfWork unitOfWork = new UnitOfWork(new MemoryGameContext()); try { foreach (var playerInMatch in gameMatch.GetPlayersConnectedToMatch()) { unitOfWork.Players.UpdateScoreOfPlayersAfterMatch(playerInMatch.Username, playerInMatch.Score); } Player winner = unitOfWork.Players.FindPlayerByUsername(usernameOfPlayerWithBestScore); CardDeck cardDeck = unitOfWork.CardDecks.Get(gameMatch.ServiceCardDeck.CardDeckId); Match matchToBeSaved = new Match() { CardDeck = cardDeck, Winner = winner, Date = DateTime.Now }; unitOfWork.Matches.Add(matchToBeSaved); unitOfWork.Complete(); } catch (SqlException sqlException) { _logger.Fatal("MatchService.cs: An exception was thrown while trying " + "to update the score of the players or while trying to register " + " the match. The transaction could not be completed. " + "Method NotifyMatchHasEnded, line 181", sqlException); throw; } catch (EntityException entityException) { _logger.Fatal("MatchService.cs: An exception was thrown while trying to access the " + " database. It is possible that the database is corrupted or that it does not exist. " + "Method NotifyMatchHasEnded, line 181", entityException); throw; } finally { unitOfWork.Dispose(); } _matches.Remove(gameMatch); } }
static void Main(string[] args) { var service = new ServicePlayer(); AuthenticatePlayerRequest request = new AuthenticatePlayerRequest(); service.Authenticate(request); }
/// <inheritdoc/> public IList <string> GetPlayersVoted(string host, string username) { ServiceMatch gameMatch = GetMatch(host); ServicePlayer player = gameMatch.GetPlayer(username); IList <string> playersVoted = player.GetPlayersVoted(); return(playersVoted); }
void Start() { servicePlayer = GetComponent <ServicePlayer>(); controllerPulo = GameObject.Find("pulo").GetComponent <ControllerPulo> (); controllerPuloLadoE = GameObject.Find("puloLado_E").GetComponent <ControllerPuloLadoE> (); controllerPuloLadoD = GameObject.Find("puloLado_D").GetComponent <ControllerPuloLadoD> (); rb2d = GetComponent <Rigidbody2D> (); cdwPulo = 0; }
/// <summary> /// Gets the player with the best score in the match. /// </summary> /// <returns>A PlayerInMatch object.</returns> public ServicePlayer GetPlayerWithBestScore() { ServicePlayer playerWithBestScore = _players[0]; for (int currentIndex = 0; currentIndex < _players.Count - 1; currentIndex++) { if (playerWithBestScore.Score < _players[currentIndex + 1].Score) { playerWithBestScore = _players[currentIndex + 1]; } } return(playerWithBestScore); }
/// <summary> /// Gets a specific player connected in the match by the username given. /// </summary> /// <param name="username">Username of the player to get.</param> /// <returns>A PlayerInMatch object.</returns> public ServicePlayer GetPlayer(string username) { ServicePlayer playerRetrieved = null; foreach (var player in _players) { if (player.Username.Equals(username)) { return(player); } } return(playerRetrieved); }
/// <inheritdoc/> public void ExpelPlayer(ExpelVoteDto expelVote) { string host = expelVote.Host; ServiceMatch gameMatch = GetMatch(host); string usernameOfExpelPlayer = expelVote.UsernameOfExpelPlayer; int playerExpelVotes = gameMatch.AddExpelVote(usernameOfExpelPlayer); ServicePlayer voterPlayer = gameMatch.GetPlayer(expelVote.UsernameOfVoterPlayer); voterPlayer.AddPlayerVoted(usernameOfExpelPlayer); IList <ServicePlayer> playersInMatch = gameMatch.GetPlayersConnectedToMatch(); int numOfPlayers = playersInMatch.Count; if (playerExpelVotes > (numOfPlayers / 2)) { ServicePlayer playerWithActiveTurn = gameMatch.GetPlyerWithActiveTurn(); ServicePlayer expelPlayer = gameMatch.GetPlayer(usernameOfExpelPlayer); if (playerWithActiveTurn.Username.Equals(usernameOfExpelPlayer)) { expelPlayer = playerWithActiveTurn; int indexOfPlayerWithCurrentTurn = gameMatch.GetPlayersConnectedToMatch().IndexOf(playerWithActiveTurn); indexOfPlayerWithCurrentTurn = ChangeTurn(gameMatch, indexOfPlayerWithCurrentTurn); ServicePlayer nextPlayer = gameMatch.GetPlayersConnectedToMatch()[indexOfPlayerWithCurrentTurn]; playerWithActiveTurn.HasActiveTurn = false; nextPlayer.HasActiveTurn = true; foreach (var playerInMatch in playersInMatch) { playerInMatch.MatchServiceConnection.EndTurnOfExpelPlayer(nextPlayer.Username); } } IList <int> cardsUncovered = expelPlayer.GetUncoveredCards(); foreach (var playerConnected in playersInMatch) { var channel = playerConnected.MatchServiceConnection; channel.NotifyPlayerWasExpel(usernameOfExpelPlayer, cardsUncovered); } RemovePairs(gameMatch, cardsUncovered); gameMatch.RemovePlayer(usernameOfExpelPlayer); if (playersInMatch.Count == 1) { this.NotifyMatchHasEnded(host); } } }
/// <summary> /// Get the playuer with the active turn in the match form the list of connected players. /// </summary> /// <returns>A PlayerInMatch Object</returns> public ServicePlayer GetPlyerWithActiveTurn() { ServicePlayer playerWithActiveTurn = null; foreach (var player in _players) { if (player.HasActiveTurn) { playerWithActiveTurn = player; } } return(playerWithActiveTurn); }
static void Main(string[] args) { System.Console.WriteLine("Strart"); var service = new ServicePlayer(); // var addPlayerResponse = service.AddPlayer(); var request = new AuthenticatePlayerRequest { Email = new Email { Address = "*****@*****.**" }, Password = "" }; var s = service.AuthenticatePlayer(request); System.Console.WriteLine("End"); System.Console.ReadKey(); }
/// <inheritdoc/> public void LeaveMatch(string host, string username) { ServiceMatch gameMatch = GetMatch(host); IList <ServicePlayer> playersInMatch = gameMatch.GetPlayersConnectedToMatch(); ServicePlayer playerWithActiveTurn = gameMatch.GetPlyerWithActiveTurn(); ServicePlayer leavePlayer = gameMatch.GetPlayer(username); if (playerWithActiveTurn.Username.Equals(username)) { leavePlayer = playerWithActiveTurn; int indexOfPlayerWithCurrentTurn = gameMatch.GetPlayersConnectedToMatch().IndexOf(playerWithActiveTurn); indexOfPlayerWithCurrentTurn = ChangeTurn(gameMatch, indexOfPlayerWithCurrentTurn); ServicePlayer nextPlayer = gameMatch.GetPlayersConnectedToMatch()[indexOfPlayerWithCurrentTurn]; playerWithActiveTurn.HasActiveTurn = false; nextPlayer.HasActiveTurn = true; foreach (var playerInMatch in playersInMatch) { playerInMatch.MatchServiceConnection.EndTurnOfExpelPlayer(nextPlayer.Username); } } IList <int> cardsUncovered = leavePlayer.GetUncoveredCards(); foreach (var playerConnected in playersInMatch) { var channel = playerConnected.MatchServiceConnection; channel.NotifyPlayerLeaveMatch(username, cardsUncovered); } RemovePairs(gameMatch, cardsUncovered); gameMatch.RemovePlayer(username); if (playersInMatch.Count == 1) { this.NotifyMatchHasEnded(host); } }
/// <inheritdoc/> public void EnterMatch(string host, string username) { ServiceMatch gameMatch = GetMatch(host); bool hasActiveTurn = false; if (host.Equals(username)) { hasActiveTurn = true; } ServicePlayer player = new ServicePlayer() { Username = username, Score = 0, HasActiveTurn = hasActiveTurn, MatchServiceConnection = OperationContext.Current.GetCallbackChannel <IMatchServiceCallback>(), ExpulsionVotes = 0 }; gameMatch.AddPlayer(player); }
/// <summary> /// Method to receive player data /// </summary> /// <param name="playerReceived">The data player</param> public void PlayerReceived(ServicePlayer playerReceived) { accountPlayer = new ServicePlayer(); accountPlayer = playerReceived; }
/// <summary> /// Adds a player to the list of players connected to the match. /// </summary> /// <param name="player">Contains the player information.</param> public void AddPlayer(ServicePlayer player) { _players.Add(player); }
/// <summary> /// Removes a player from the list of connected players in the match. /// </summary> /// <param name="playerUsername">Username of the player to remove.</param> public void RemovePlayer(string playerUsername) { ServicePlayer playerToRemove = this.GetPlayer(playerUsername); _players.Remove(playerToRemove); }
private void Modify(object sender, RoutedEventArgs routedEventArgs) { playerEdit = new ServicePlayer(); emailEdit = account.Email; ValidateDataAccount(); if (isUpdateData || !emailEdit.Equals(emailAccount)) { if (isValidData) { try { InstanceContext instanceContext = new InstanceContext(this); PlayerManagerClient playerManager = new PlayerManagerClient(instanceContext); bool isValidRepeatEmail = false; if (isUpdateEmail) { playerManager.SearchRepeatEmailAccount(emailEdit, account.IdAccount); isValidRepeatEmail = responseBoolean; } bool updateEmail = false; if (isUpdateEmail && !isValidRepeatEmail) { playerManager.UpdateEmail(emailEdit, account.IdAccount); updateEmail = responseBoolean; } bool updatePlayer = false; if (isUpdateData) { playerManager.UpdatePlayer(player.NickName, playerEdit); updatePlayer = responseBoolean; } if (updatePlayer || updateEmail) { OpenMessageBox(Properties.Resources.ModifyAccountMessage, Properties.Resources.ModifyAccountMessageTitle, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Information); } else { OpenMessageBox(Properties.Resources.NoModifyAccountMessage, Properties.Resources.ModifyAccountMessageTitle, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Error); } Lobby lobby = new Lobby(); if (isUpdateEmail) { lobby.EmailReceived(emailEdit); } lobby.ColocateBestScores(); lobby.ColocatePersonalInformation(); lobby.Show(); this.Close(); } catch (EndpointNotFoundException exception) { TelegramBot.SendToTelegram(exception); LogException.Log(this, exception); LogException.ErrorConnectionService(); } } else { OpenMessageBox(Properties.Resources.IncorrectDataMessage, Properties.Resources.IncorrectCodeMessageTitle, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Warning); isUpdateData = false; } } else { OpenMessageBox(Properties.Resources.ModifyLeastDataMessage, Properties.Resources.ModifyLeastDataMessageTile, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Warning); } }
/// <summary> /// IAccountManager response method /// </summary> /// <param name="servicePlayer">The service player </param> public void AccountResponsePlayer(ServicePlayer servicePlayer) { player = servicePlayer; }
/// <summary> /// This method saves the callback response from IInformationPlayerManagerCallback /// </summary> /// <param name="response">The response obtained when calling the server method.</param> public void PlayerResponseInformation(ServicePlayer response) { nickname = response.NickName; score = response.ScoreObtained; }
private void RegisterPlayer(object sender, RoutedEventArgs routedEventArgs) { bool isValidData = ValidateDataPlaye(); if (isValidData) { string name = tbName.Text; string lastName = tbLastName.Text; string nickname = tbNickname.Text; string email = tbEmail.Text; string password = Security.Encrypt(pbPassword.Password); int codeConfirmation = ValidationData.GenerateConfirmationCode(); ServiceAccount account = new ServiceAccount(); account.PasswordAccount = password; account.Email = email; account.ConfirmationCode = codeConfirmation; ServicePlayer accountPlayer = new ServicePlayer(); accountPlayer.NickName = nickname; accountPlayer.NamePlayer = ValidationData.DeleteSpaceWord(name); accountPlayer.LastName = ValidationData.DeleteSpaceWord(lastName); accountPlayer.StatusPlayer = "Active"; accountPlayer.ScoreObtained = 0; try { InstanceContext instanceContext = new InstanceContext(this); PlayerManagerClient validatePlayer = new PlayerManagerClient(instanceContext); validatePlayer.SearchNicknamePlayer(nickname); bool isValidRepeatNickname = responseBoolean; validatePlayer.SearchEmailPlayer(email); bool isValidRepeatEmail = responseBoolean; if (isValidRepeatEmail && isValidRepeatNickname) { OpenMessageBox(Properties.Resources.RegisteredEmailNicknameMessage, Properties.Resources.RepeatedDataMessageTitle, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Warning); } else { if (isValidRepeatEmail) { OpenMessageBox(Properties.Resources.RegisteredEmailMessage, Properties.Resources.RepeatedDataMessageTitle, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Warning); } else { if (isValidRepeatNickname) { OpenMessageBox(Properties.Resources.RegisteredNicknameMessage, Properties.Resources.RepeatedDataMessageTitle, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Warning); } else { EmailConfirmation emailConfirmation = new EmailConfirmation(); emailConfirmation.AccountReceived(account); emailConfirmation.PlayerReceived(accountPlayer); emailConfirmation.SendConfirmationCodePlayer(); emailConfirmation.Show(); this.Close(); } } } } catch (EndpointNotFoundException exception) { TelegramBot.SendToTelegram(exception); LogException.Log(this, exception); LogException.ErrorConnectionService(); } } else { OpenMessageBox(Properties.Resources.IncorrectDataMessage, Properties.Resources.IncorrectDataMessageTitle, (MessageBoxImage)System.Windows.Forms.MessageBoxIcon.Warning); } }