Beispiel #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);
        }
Beispiel #2
0
        private void AsPlayer(Entities.Game game, Entities.User user, String passphrase, Entities.JoinResponse response, Boolean wasWaiting)
        {
            if (game.IsCurrentPlayer(user.UserId) == false)
            {
                if (_validatePassphrase.Execute(game, passphrase) == false)
                {
                    response.Result |= Entities.Enums.Game.JoinResponseCode.BadPassphrase;
                }
                else if (game.IsFull())
                {
                    response.Result |= Entities.Enums.Game.JoinResponseCode.FullGame;
                }
                else
                {
                    Boolean successful = _joinGame.Execute(game, user, Entities.Enums.GamePlayerType.Player);

                    if (successful == false)
                    {
                        response.Result |= Entities.Enums.Game.JoinResponseCode.FullGame;
                    }
                    else
                    {
                        if (wasWaiting && !game.IsWaiting())
                        {
                            Entities.User newCommander = game.NextCommander(null);

                            if (newCommander != null)
                            {
                                if (_startRound.Execute(game, game.NextCommander(null)) == true)
                                {
                                    response.Result |= Entities.Enums.Game.JoinResponseCode.NewRoundStart;
                                }
                            }
                            else
                            {
                                response.Result |= Entities.Enums.Game.JoinResponseCode.WaitingOnWinnerSelection;
                            }
                        }
                    }
                }
            }
            else
            {
                response.Result |= Entities.Enums.Game.JoinResponseCode.SuccessfulAlreadyPlayer;
            }

            if (response.Result.HasFlag(Entities.Enums.Game.JoinResponseCode.BadPassphrase) == false &&
                response.Result.HasFlag(Entities.Enums.Game.JoinResponseCode.FullGame) == false)
            {
                response.Game = game;
            }
        }