Exemple #1
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>
        /// <returns></returns>
        public Entities.ActionResponses.RoundComplete Execute(Int32 gameID, List <Int32> cardIDs, Int32 userId)
        {
            Entities.ActionResponses.RoundComplete response = new Entities.ActionResponses.RoundComplete();

            Entities.GameRound currentRound = _selectGameRound.Execute(gameID, true);

            //Validate that the user trying to complete the round is in fact the commander
            if (currentRound.IsCommander(userId))
            {
                //Validate that select cards were actually played during the round
                List <Int32> invalidWinners = currentRound.ValidateWinnerSelection(cardIDs);

                if (invalidWinners.Count == 0)
                {
                    Entities.User newCommander = currentRound.Winner();

                    //Update cards as winners
                    Entities.Filters.GameRoundCard.UpdateWinner cardfilter = new Entities.Filters.GameRoundCard.UpdateWinner();
                    cardfilter.CardIDs = cardIDs;
                    cardfilter.GameID  = gameID;

                    Boolean autoPlayed = _updateGameRoundCard.Execute(cardfilter);

                    if (!autoPlayed)
                    {
                        //Update player points
                        Entities.Filters.GamePlayer.UpdatePoints playerFilter = new Entities.Filters.GamePlayer.UpdatePoints();
                        playerFilter.GameID = gameID;
                        playerFilter.UserId = newCommander.UserId;

                        _updateGamePlayer.Execute(playerFilter);
                    }

                    //Start round
                    Entities.Filters.Game.Select gameFilter = new Entities.Filters.Game.Select();
                    gameFilter.GameID       = gameID;
                    gameFilter.DataToSelect = Entities.Enums.Game.Select.GamePlayerCards;

                    Entities.Game game = _selectGame.Execute(gameFilter);

                    response.NewRoundCreated = _startGameRoud.Execute(game, game.NextCommander(newCommander));

                    response.CompletedRound = currentRound;
                    response.Game           = game;

                    if (!response.NewRoundCreated)
                    {
                        response.Game.Rounds.Add(currentRound);
                    }
                }
            }

            return(response);
        }
Exemple #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>
        /// <returns></returns>
        public Entities.ActionResponses.RoundComplete Execute(Int32 gameID, List<Int32> cardIDs, Int32 userId)
        {
            Entities.ActionResponses.RoundComplete response = new Entities.ActionResponses.RoundComplete();

            Entities.GameRound currentRound = _selectGameRound.Execute(gameID, true);

            //Validate that the user trying to complete the round is in fact the commander
            if (currentRound.IsCommander(userId))
            {
                //Validate that select cards were actually played during the round
                List<Int32> invalidWinners = currentRound.ValidateWinnerSelection(cardIDs);

                if (invalidWinners.Count == 0)
                {
                    Entities.User newCommander = currentRound.Winner();

                    //Update cards as winners
                    Entities.Filters.GameRoundCard.UpdateWinner cardfilter = new Entities.Filters.GameRoundCard.UpdateWinner();
                    cardfilter.CardIDs = cardIDs;
                    cardfilter.GameID = gameID;

                    Boolean autoPlayed = _updateGameRoundCard.Execute(cardfilter);

                    if (!autoPlayed)
                    {
                        //Update player points
                        Entities.Filters.GamePlayer.UpdatePoints playerFilter = new Entities.Filters.GamePlayer.UpdatePoints();
                        playerFilter.GameID = gameID;
                        playerFilter.UserId = newCommander.UserId;

                        _updateGamePlayer.Execute(playerFilter);
                    }

                    //Start round
                    Entities.Filters.Game.Select gameFilter = new Entities.Filters.Game.Select();
                    gameFilter.GameID = gameID;
                    gameFilter.DataToSelect = Entities.Enums.Game.Select.GamePlayerCards;

                    Entities.Game game = _selectGame.Execute(gameFilter);

                    response.NewRoundCreated = _startGameRoud.Execute(game, game.NextCommander(newCommander));

                    response.CompletedRound = currentRound;
                    response.Game = game;

                    if(!response.NewRoundCreated)
                    {
                        response.Game.Rounds.Add(currentRound);
                    }
                }
            }

            return response;
        }
Exemple #3
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);
            }
        }