public Task Handle(RoundFinishedEvent notification, CancellationToken cancellationToken) { var scores = notification.PlayerScores.Select(player => new PlayerDTO { Name = player.Player.Name, Score = player.Score }); var votes = notification.Votes.Select(vote => new VoteDTO { Player = vote.Player.Name, Card = vote.Card.Id }); return(_hubContext.Clients.All.RoundFinished( new RoundFinishedDTO { PlayerUpdates = scores.ToList(), Votes = votes.ToList(), NextStoryTeller = notification.NextStoryTeller.Name, StoryCard = notification.StoryCard.Id })); }
private void MatchFinished(object sender, EventArgs e) { foreach (var item in Rounds[CurrentRound]) { if (!item.Finished) { return; } } if (Rounds[CurrentRound].Length == 1) { TournamentFinishedEvent?.Invoke(this, new EventArgs()); } else { RoundFinishedEvent?.Invoke(this, new EventArgs()); } }
public async Task <Unit> Handle(VoteCardCommand request, CancellationToken cancellationToken) { var lobby = await _lobbyRepository.GetLobbyByCode(request.Code); var card = lobby.GetCard(request.Card); var player = lobby.GetPlayerByName(request.Player); lobby.PlayerVoteCard(player, card); await _mediator.Publish(new CardVotedEvent { Code = request.Code, Player = player, Card = card }); if (lobby.HasAllPlayersVoted()) { var votes = lobby.CurrentVotes; var storyCard = lobby.CurrentStoryCard; var storyTeller = lobby.CurrentStoryTeller; var score = _scoreService.VallyVotes(votes, storyTeller, storyCard); lobby.TallyVotes(score); lobby.NewRound(); var roundFinishedEvent = new RoundFinishedEvent { Code = lobby.Code, PlayerScores = score, Votes = votes.ToList(), NextStoryTeller = lobby.CurrentStoryTeller, StoryCard = storyCard }; var tasks = lobby.ActivePlayers.Select(p => _mediator.Publish(new CardDrawnEvent { Code = request.Code, Player = p, Hand = lobby.Deck.Hand(p) })); await Task.WhenAll(tasks); await _mediator.Publish(roundFinishedEvent); } await _lobbyRepository.SaveLobby(lobby); return(Unit.Value); }
private void Board_OnRoundFinished(object sender, RoundFinishedEvent e) { this.container.moveList.Items.Add(new ListViewItem(new string[] { e.Round.ToString(), e.Move1.ToString(), e.Move2.ToString() })); }
/// <summary> /// Try to move the currently selected piece to the given board tile. /// </summary> /// <param name="tile"></param> /// <returns>Returns true if movement was successfull.</returns> private bool MoveSelectedPieceTo(BoardTile tile, Player player) { if (SelectedTile.CanMoveTo(this, tile)) { // Check if current move is a castling move if (SelectedTile.OccupyingPiece != null && SelectedTile.OccupyingPiece.GetType() == typeof(King) && tile.OccupyingPiece != null && tile.OccupyingPiece.GetType() == typeof(Rook) && tile.OccupyingPiece.IsWhite == SelectedTile.OccupyingPiece.IsWhite) { var rookDestination = ((Rook)tile.OccupyingPiece).GetCastleLocation(this, tile); rookDestination.OccupyingPiece = tile.OccupyingPiece; tile.OccupyingPiece = null; tile = ((King)SelectedTile.OccupyingPiece).GetCastleLocation(this, SelectedTile, tile); } currentRountData.AddMove(new PlayerMove(player, SelectedTile, tile)); latestTiles.Clear(); latestTiles.Add(tile); latestTiles.Add(SelectedTile); if (tile.OccupyingPiece == null && SelectedTile.OccupyingPiece.GetType() != typeof(Pawn)) { movesMadeWithoutProgress++; } else { movesMadeWithoutProgress = 0; } tile.OccupyingPiece = SelectedTile.OccupyingPiece; SelectedTile.OccupyingPiece.PostMovementEvent(tile); SelectedTile.OccupyingPiece = null; if (IsCheckmate(player)) { OnGameFinished?.Invoke(this, new GameFinishedEvent(player, GameFinishedReason.CheckMate)); } else if (!EnoughMaterialOnBoard()) { OnGameFinished?.Invoke(this, new GameFinishedEvent(null, GameFinishedReason.InsufficientMaterial)); } else if (IsStalemate(player.IsWhite)) { OnGameFinished?.Invoke(this, new GameFinishedEvent(null, GameFinishedReason.Stalemate)); } else if (movesMadeWithoutProgress >= 75) { OnGameFinished?.Invoke(this, new GameFinishedEvent(null, GameFinishedReason.Move75)); } if (currentRountData.IsDone) { OnRoundFinished?.Invoke(this, currentRountData); currentRountData = new RoundFinishedEvent(currentRountData.Round + 1); } return(true); } return(false); }