/// <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); } }
private async void FlipBothCardsAgain(CardPairDto cardPairDto) { await Task.Delay(1000); _imageCards[cardPairDto.IndexOfCard1].Source = _imageCards[cardPairDto.IndexOfCard1].BackImage; _imageCards[cardPairDto.IndexOfCard2].Source = _imageCards[cardPairDto.IndexOfCard2].BackImage; }
/// <summary> /// Notifies the client that the turn of the previous player has ended. /// </summary> /// <param name="username">The username of the player that had the previous turn.</param> /// <param name="cardPairDto">The pair of cards of the previous player.</param> public void NotifyTurnHasEnded(string username, CardPairDto cardPairDto) { TurnLabel.Content = Properties.Langs.Resources.TurnMessage + ": " + username; if (Sesion.GetSesion.Username.Equals(username)) { _numberOfMovementsAllowed = 2; } if (!cardPairDto.BothCardsAreEqual) { FlipBothCardsAgain(cardPairDto); } }
private void EndMovement() { try { if (_numberOfMovementsAllowed == 0) { if (HasFormedAPair()) { _numberOfMovementsAllowed = 2; _playerHasFormedAPair = true; } CardPairDto cardPairDto = new CardPairDto() { IndexOfCard1 = _imageCards.IndexOf(_cardsFlippedInCurrentTurn[0]), IndexOfCard2 = _imageCards.IndexOf(_cardsFlippedInCurrentTurn[1]), BothCardsAreEqual = _playerHasFormedAPair }; _matchServiceClient.EndTurn(MatchHost, Sesion.GetSesion.Username, cardPairDto); _playerHasFormedAPair = false; _cardsFlippedInCurrentTurn.Clear(); } } catch (EndpointNotFoundException) { MessageBox.Show(Properties.Langs.Resources.ServerConnectionLost); } catch (TimeoutException) { MessageBox.Show(Properties.Langs.Resources.ServerTimeoutError); } catch (CommunicationException) { MessageBox.Show(Properties.Langs.Resources.CommunicationInterrupted); } }