Exemplo n.º 1
0
        private FieldChecked CreateFieldCheckedEvent(int gameId, int fieldId, CurrentFieldState state)
        {
            FieldChecked fieldChecked = new FieldChecked();

            fieldChecked.FieldId = fieldId;
            fieldChecked.GameId  = gameId;
            fieldChecked.Checked = true;
            fieldChecked.Type    = state.Type;
            if (state.Type == FieldType.Team)
            {
                fieldChecked.TeamId = state.TeamId.Value;
            }

            return(fieldChecked);
        }
Exemplo n.º 2
0
        private async Task ProcesCheckedField(int gameId, CurrentGameState gameState, FieldChecked fieldChecked)
        {
            if (fieldChecked.Type == FieldType.Team && fieldChecked.TeamId == gameState.CurrentTeamId)
            {
                await gameTeamRepository.DecrementRemainingFieldCount(fieldChecked.TeamId);
            }
            else
            {
                if (fieldChecked.Type == FieldType.Team)
                {
                    await gameTeamRepository.DecrementRemainingFieldCount(fieldChecked.TeamId);
                }

                var nextTeam = await nextTeamProvider.GetNextTeam(gameId, gameState.EndMode);

                var newStatus = await gameStatusRepository.UpdateCurrentStatus(gameId, nextTeam.Id, Status.Ongoing);

                var teamChanged = CreateTeamChangedEvent(gameId, gameState.CurrentTeamId, nextTeam.Id, Base.Enums.Events.TeamChangeReason.WrongGuess);
                eventBroadcaster.TeamChanged(teamChanged);
            }
        }
Exemplo n.º 3
0
        private async Task ProcessEndGame(int gameId, int currentTeamId, int winningTeamId, FieldChecked fieldChecked)
        {
            await gameRepository.EndGame(gameId, winningTeamId);

            if (fieldChecked.Type == FieldType.Team)
            {
                await gameTeamRepository.DecrementRemainingFieldCount(winningTeamId);
            }
            if (winningTeamId != currentTeamId)
            {
                var teamChanged = CreateTeamChangedEvent(gameId, currentTeamId, winningTeamId, Base.Enums.Events.TeamChangeReason.WonGame);
                eventBroadcaster.TeamChanged(teamChanged);
            }

            eventBroadcaster.EndGame(new GameEnded()
            {
                GameId        = gameId,
                WinningTeamId = winningTeamId
            });
        }
Exemplo n.º 4
0
        private async Task <EndGameCheckResult> VerifySuddenDeathEndGame(CurrentGameState gameState, FieldChecked fieldChecked)
        {
            var result = new EndGameCheckResult();

            if (fieldChecked.Type == Base.Enums.Game.FieldType.Trap)
            {
                result.GameEnded = true;
                var winningTeam = await nextTeamProvider.GetNextTeam(gameState.GameId, gameState.EndMode);

                result.WinningTeamId = winningTeam.Id;
            }
            else if (fieldChecked.Type == Base.Enums.Game.FieldType.Team)
            {
                var remainingFieldCount = await teamRepository.GetRemainingFieldCount(fieldChecked.TeamId);

                if (remainingFieldCount == 1)
                {
                    result.GameEnded     = true;
                    result.WinningTeamId = fieldChecked.TeamId;
                }
            }

            return(result);
        }
Exemplo n.º 5
0
        public async Task <EndGameCheckResult> VerifyEndGame(CurrentGameState gameState, FieldChecked fieldChecked)
        {
            if (gameState.EndMode == Base.Enums.Game.EndMode.SuddenDeath)
            {
                return(await VerifySuddenDeathEndGame(gameState, fieldChecked));
            }

            throw new NotImplementedException("NOT IMPLEMEMTED END MODE");
        }
Exemplo n.º 6
0
 public void FieldChecked(FieldChecked args)
 {
     HubContext.Clients.Group(args.GameId.ToString()).FieldChecked(args);
 }