Exemplo n.º 1
0
        /// <summary>
        /// Starts a round if certain requirements are met
        /// </summary>
        /// <param name="game">The game to start a new round for</param>
        /// <param name="commander">The new round's commander</param>
        /// <returns>If a round was successfully started</returns>
        public Boolean Execute(Entities.Game game, Entities.User commander)
        {
            Boolean started = _startRound.Execute(game, commander);

            if (started && game.SecondsToPlay > 0)
            {
                String jobId = BackgroundJob.Schedule <AppServices.GameRound.Base.ITimerExpired>(x => x.Execute(game.GameID), TimeSpan.FromSeconds(15 + game.SecondsToPlay));

                MemoryCache.Default.Set(game.RoundTimerKey, jobId, new CacheItemPolicy {
                    SlidingExpiration = TimeSpan.FromMinutes(5)
                });
            }

            _updateGame.Execute(game.GameID, DateTime.UtcNow, null);

            return(started);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Complete the current round
        /// </summary>
        /// <param name="gameID">The ID of the game that contains the round</param>
        /// <param name="cardIDs">The IDs of the winning cards</param>
        /// <param name="userId">The user Id trying to complete the round</param>
        public void Execute(Int32 gameID, List <Int32> cardIDs, Int32 userId)
        {
            Entities.ActionResponses.RoundComplete response = _completeGameRound.Execute(gameID, cardIDs, userId);

            if (response.CompletedRound != null && response.Game != null)
            {
                _sendMessage.SendWinnerSelected(response.Game, response.CompletedRound, true);

                DateTime playedLast = DateTime.UtcNow;
                DateTime?gameOver   = null;

                if (response.Game.HasWinner())
                {
                    gameOver = playedLast;
                }

                _updateGame.Execute(gameID, playedLast, gameOver);
            }
        }