コード例 #1
0
        /// <summary>
        /// Play a list of cards from a user's hand
        /// </summary>
        /// <param name="cardIDs">The card IDs the user has selected </param>
        /// <param name="gameID">The game ID in which the user wants to play the card</param>
        /// <param name="userId">The user Id</param>
        /// <param name="autoPlayed">Were these cards auto played</param>
        /// <returns>PlayCard action result containing any errors and the round the card was played.</returns>
        public Entities.ActionResponses.PlayCard Execute(List <Int32> cardIDs, Int32 gameID, Int32 userId, Boolean autoPlayed = false)
        {
            Entities.ActionResponses.PlayCard response = _playCard.Execute(cardIDs, gameID, userId, autoPlayed);

            if (response.ResponseCode == Entities.ActionResponses.Enums.PlayCardResponseCode.Success)
            {
                Entities.Filters.Game.Select filter = new Entities.Filters.Game.Select();
                filter.DataToSelect = Entities.Enums.Game.Select.GamePlayerCards;
                filter.GameID       = gameID;

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

                game.Rounds.Add(response.CurrentRound);

                if (response.CurrentRound.AllPlayersAnswered() && game.SecondsToPlay > 0)
                {
                    var cachedJobId = MemoryCache.Default.Get(game.RoundTimerKey);

                    BackgroundJob.Delete(cachedJobId as String);
                }

                _sendMessage.CardPlayed(game, true);
                _updateGame.Execute(game.GameID, DateTime.UtcNow, null);
            }

            return(response);
        }
コード例 #2
0
        /// <summary>
        /// Play a list of cards from a user's hand
        /// </summary>
        /// <param name="cardIDs">The card IDs the user has selected </param>
        /// <param name="gameID">The game ID in which the user wants to play the card</param>
        /// <param name="userId">The user Id</param>
        /// <param name="autoPlayed">Were these cards auto played</param>
        /// <returns>PlayCard action result containing any errors and the round the card was played.</returns>
        public Entities.ActionResponses.PlayCard Execute(List <Int32> cardIDs, Int32 gameID, Int32 userId, Boolean autoPlayed)
        {
            Entities.ActionResponses.PlayCard playResponse = new Entities.ActionResponses.PlayCard();

            List <Entities.GamePlayerCard> cards = _selectGamePlayerCard.Execute(gameID, userId);

            //Check that the user did not play cards they do not have
            List <Int32> missedIds = CheckHand(cards, cardIDs);

            if (missedIds.Count == 0)
            {
                Entities.GameRound round = _selectGameRound.Execute(gameID, true);

                //Validate the user isn't trying to answer multiple times
                if (round.HasAnswer(userId) == false)
                {
                    //Validate the correct number of cards were played
                    if (round.ValidateCardPlayedCount(cardIDs.Count))
                    {
                        //Create GameRoundCards for played cards
                        List <Entities.GameRoundCard> playedCards = CreateRoundCards(cardIDs, userId, round.GameRoundID, gameID, autoPlayed);

                        //Insert playedCards
                        _insertGameRoundCard.Execute(playedCards);

                        if (autoPlayed)
                        {
                            playResponse.AutoPlayedSuccess = true;
                        }

                        //Select round with game cards
                        round = _selectGameRound.Execute(gameID, true);

                        //Remove cards from player's hand
                        _deleteGamePlayerCard.Execute(cardIDs, gameID, userId);

                        playResponse.CurrentRound = round;
                        playResponse.ResponseCode = Entities.ActionResponses.Enums.PlayCardResponseCode.Success;
                    }
                    else
                    {
                        playResponse.ResponseCode = Entities.ActionResponses.Enums.PlayCardResponseCode.InvalidNumberOfCardsPlayed;
                    }
                }
                else
                {
                    playResponse.CurrentRound = round;
                    playResponse.ResponseCode = Entities.ActionResponses.Enums.PlayCardResponseCode.Success;
                }
            }
            else
            {
                playResponse.ResponseCode = Entities.ActionResponses.Enums.PlayCardResponseCode.InvalidCardPlayed;
            }

            return(playResponse);
        }
コード例 #3
0
ファイル: Play.cs プロジェクト: kwmcrell/ArmedCards
        /// <summary>
        /// Play a list of cards from a user's hand
        /// </summary>
        /// <param name="cardIDs">The card IDs the user has selected </param>
        /// <param name="gameID">The game ID in which the user wants to play the card</param>
        /// <param name="userId">The user Id</param>
        /// <param name="autoPlayed">Were these cards auto played</param>
        /// <returns>PlayCard action result containing any errors and the round the card was played.</returns>
        public Entities.ActionResponses.PlayCard Execute(List<Int32> cardIDs, Int32 gameID, Int32 userId, Boolean autoPlayed)
        {
            Entities.ActionResponses.PlayCard playResponse = new Entities.ActionResponses.PlayCard();

            List<Entities.GamePlayerCard> cards = _selectGamePlayerCard.Execute(gameID, userId);

            //Check that the user did not play cards they do not have
            List<Int32> missedIds = CheckHand(cards, cardIDs);

            if (missedIds.Count == 0)
            {
                Entities.GameRound round = _selectGameRound.Execute(gameID, true);

                //Validate the user isn't trying to answer multiple times
                if (round.HasAnswer(userId) == false)
                {
                    //Validate the correct number of cards were played
                    if (round.ValidateCardPlayedCount(cardIDs.Count))
                    {
                        //Create GameRoundCards for played cards
                        List<Entities.GameRoundCard> playedCards = CreateRoundCards(cardIDs, userId, round.GameRoundID, gameID, autoPlayed);

                        //Insert playedCards
                        _insertGameRoundCard.Execute(playedCards);

                        if (autoPlayed)
                        {
                            playResponse.AutoPlayedSuccess = true;
                        }

                        //Select round with game cards
                        round = _selectGameRound.Execute(gameID, true);

                        //Remove cards from player's hand
                        _deleteGamePlayerCard.Execute(cardIDs, gameID, userId);

                        playResponse.CurrentRound = round;
                        playResponse.ResponseCode = Entities.ActionResponses.Enums.PlayCardResponseCode.Success;
                    }
                    else
                    {
                        playResponse.ResponseCode = Entities.ActionResponses.Enums.PlayCardResponseCode.InvalidNumberOfCardsPlayed;
                    }
                }
                else
                {
                    playResponse.CurrentRound = round;
                    playResponse.ResponseCode = Entities.ActionResponses.Enums.PlayCardResponseCode.Success;
                }
            }
            else
            {
                playResponse.ResponseCode = Entities.ActionResponses.Enums.PlayCardResponseCode.InvalidCardPlayed;
            }

            return playResponse;
        }
コード例 #4
0
        /// <summary>
        /// Play cards for all players that have yet to play
        /// </summary>
        /// <param name="gameID">The game ID</param>
        public void Execute(int gameID)
        {
            Entities.Filters.Game.Select gameFilter = new Entities.Filters.Game.Select();
            gameFilter.DataToSelect = Entities.Enums.Game.Select.GamePlayerCards | Entities.Enums.Game.Select.Rounds;
            gameFilter.GameID       = gameID;

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

            Entities.GameRound round = game.CurrentRound();

            List <Entities.GamePlayer> players = game.Players.Where(x => !round.HasAnswer(x.User.UserId) &&
                                                                    game.IsCurrentPlayer(x.User.UserId) &&
                                                                    !game.IsCurrentCommander(x.User.UserId))
                                                 .Select(x => x).ToList();

            Int32 selectCount = 1 + (Int32)round.Question.Instructions;

            Random rdm = new Random();

            List <Int32> cardIDs = null;

            Entities.ActionResponses.PlayCard response = null;

            foreach (Entities.GamePlayer player in players)
            {
                cardIDs  = player.Hand.OrderBy(x => rdm.Next()).Take(selectCount).Select(x => x.CardID).ToList();
                response = _playCard.Execute(cardIDs, gameID, player.User.UserId, true);

                if (response.AutoPlayedSuccess)
                {
                    if (player.IdlePlayCount + 1 == 3)
                    {
                        //Player is forced to leave game now
                        UnityConfig.Container.Resolve <AppServices.Game.Base.ILeave>().Execute(gameID, player.User, Entities.Enums.GamePlayerType.Player, true);
                    }
                    else
                    {
                        Entities.Filters.GamePlayer.UpdateIdlePlayCount idlePlayCount =
                            new Entities.Filters.GamePlayer.UpdateIdlePlayCount
                        {
                            GameID = gameID,
                            UserId = player.User.UserId
                        };

                        _updateGamePlayer.Execute(idlePlayCount);
                    }
                }
            }
        }
コード例 #5
0
        public void PlayCard(Entities.Models.Hub.Messages.PlayCard message)
        {
            AS.GamePlayerCard.Base.IPlay _playCard = BusinessLogic.UnityConfig.Container.Resolve <AS.GamePlayerCard.Base.IPlay>();

            Entities.ActionResponses.PlayCard response = _playCard.Execute(message.CardIDs, message.GameID, Authentication.Security.CurrentUserId);
        }