예제 #1
0
파일: Join.cs 프로젝트: kwmcrell/ArmedCards
        /// <summary>
        /// Join a game
        /// </summary>
        /// <param name="gameID">The game to join</param>
        /// <param name="user">The current user</param>
        /// <param name="passphrase">The passphrase for the game</param>
        /// <param name="playerType">Type of player joining</param>
        /// <returns>The response to a join request</returns>
        public Entities.JoinResponse Execute(Entities.Game game, Entities.User user, String passphrase, Entities.Enums.GamePlayerType playerType)
        {
            Entities.JoinResponse response = new Entities.JoinResponse();

            Boolean wasWaiting = game.IsWaiting();

            if (game.GameOver.HasValue)
            {
                response.Result = Entities.Enums.Game.JoinResponseCode.GameOver;
            }
            else
            {
                if (playerType == Entities.Enums.GamePlayerType.Spectator)
                {
                    AsSpectator(game, user, passphrase, response);
                }
                else
                {
                    AsPlayer(game, user, passphrase, response, wasWaiting);
                }
            }

            return response;
        }
예제 #2
0
파일: Join.cs 프로젝트: kwmcrell/ArmedCards
        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;
            }
        }
예제 #3
0
        /// <summary>
        /// Alert the users that the round has been lost because the commander has left
        /// </summary>
        /// <param name="game">The game</param>
        /// <param name="commanderName">The commander's name</param>
        public void CommanderLeft(Entities.Game game, String commanderName)
        {
            Entities.Filters.ActiveConnection.SelectAll filter = new Entities.Filters.ActiveConnection.SelectAll();
            filter.GroupName = String.Format("Game_{0}", game.GameID);

            List<Entities.ActiveConnection> connections = _selectActiveConnection.Execute(filter);

            Entities.GamePlayer sendToPlayer = null;

            foreach (Entities.ActiveConnection connection in connections)
            {
                sendToPlayer = game.Players.FirstOrDefault(player => player.User.UserId == connection.User_UserId);

                if (sendToPlayer != null)
                {
                    Entities.Models.Game.Board.GameBoard model = GetGameBoardModal(connection, game);

                    _hub.Clients.Client(connection.ActiveConnectionID)
                                       .CommanderLeft(model, GetGameLobbyViewModel(connection, game), commanderName, game.IsWaiting());
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="game"></param>
        /// <param name="userId"></param>
        /// <param name="hand"></param>
        /// <param name="playerType"></param>
        /// <param name="voteToKickList"></param>
        /// <param name="completedRounds"></param>
        public GameBoard(Entities.Game game, Int32 userId, Entities.Enums.GamePlayerType playerType,
                         List<Models.Game.Board.VoteToKick> voteToKickList = null,
                         List<Entities.GameRound> completedRounds = null)
        {
            Game = game;
            UserId = userId;

            Hand = new List<GamePlayerCard>();

            if (playerType == Enums.GamePlayerType.Player)
            {
                Entities.GamePlayer player = Game.Players.FirstOrDefault(x => x.User.UserId == userId);

                if(player != null && player.Hand != null)
                {
                    Hand = player.Hand;
                }
            }

            Hand = playerType == Enums.GamePlayerType.Player ? Game.Players.First(x => x.User.UserId == userId).Hand : new List<GamePlayerCard>();
            ActivePlayer = Hand.Count > 0;
            PlayerType = playerType;

            Entities.GameRound round = Game.CurrentRound();

            if (Game.HasRounds() && round != null)
            {
                Answered = round.HasAnswer(UserId);
                ShowAnswers = round.PlayedCount >= round.CurrentPlayerCount && round.Answers.Count > 0;
                RoundHasWinner = round.Winner() != null;
                GroupedAnswers = round.GroupedAnswers();
                IsCommander = Game.IsCurrentCommander(UserId) && PlayerType == Entities.Enums.GamePlayerType.Player;
            }
            else
            {
                Answered = false;
                ShowAnswers = false;
                RoundHasWinner = false;
                IsCommander = false;
            }

            ShowHand = ActivePlayer && !Answered && !IsCommander && PlayerType == Entities.Enums.GamePlayerType.Player;

            ShowWaiting = (round == null || RoundHasWinner) && Game.IsWaiting();

            WaitingOnAllAnswersOrWinner = !RoundHasWinner && !ShowAnswers;

            ShowBoard = !ShowWaiting && !Game.HasWinner();

            if (ShowBoard && round != null)
            {
                Question = round.Question;
            }
            else
            {
                Question = null;
            }

            AnswersViewModel = new Answers(RoundHasWinner, IsCommander, WaitingOnAllAnswersOrWinner, ShowAnswers, ShowHand, ShowBoard, GroupedAnswers);
            GameOverViewModel = new GameOver(Game.HasWinner(), Game.GameID, Game.Players);
            HandViewModel = new Board.Hand(ShowHand, Hand, ShowBoard);
            LobbyViewModel = new Lobby(PlayerType, Game.Players, Game.MaxNumberOfSpectators > 0, Game.Spectators);
            RoundQuestionViewModel = new RoundQuestion(round, ShowBoard);
            WaitingViewModel = new Waiting(ShowWaiting);
            VotesToKickViewModel = new VotesToKick(voteToKickList ?? new List<Models.Game.Board.VoteToKick>());
            AllRoundsViewModel = new AllRounds(completedRounds ?? new List<GameRound>());

            HeaderViewModel = new Shared.Header();

            if (Game.HasWinner())
            {
                HeaderViewModel.SubHeaderText = "Game Over, man!";
            }
            else if (ShowWaiting)
            {
                HeaderViewModel.SubHeaderText = ArmedCards.Entities.Models.Helpers.WaitingHeader.Build(Game, UserId, PlayerType);
            }
            else
            {
                HeaderViewModel.SubHeaderText = String.Format("{0} is the Card Commander", Game.DetermineCommander().DisplayName);
            }
        }
예제 #5
0
        private void SendWinnerSelected(Entities.Game game, Entities.GameRound round,
                                            IEnumerable<Entities.ActiveConnection> connections,
                                            List<Entities.GamePlayer> users)
        {
            Entities.GamePlayer sendToPlayer = null;

            foreach (Entities.ActiveConnection connection in connections)
            {
                sendToPlayer = users.FirstOrDefault(player => player.User.UserId == connection.User_UserId);

                if (sendToPlayer != null)
                {

                    Entities.Models.Game.Board.GameBoard model = GetGameBoardModal(connection, game);

                    Entities.Models.Game.Board.Answers answersModel = new Entities.Models.Game.Board.Answers(true, model.IsCommander, false,
                                                                                               false, false, true, round.GroupedAnswers());

                    //The round history tab repurposed this to be the winner of the round when the page is loaded
                    //so setting this here so that when pushed into the observable array it will look correct
                    round.CardCommander = round.Winner();

                    _hub.Clients.Client(connection.ActiveConnectionID)
                                       .WinnerSelected(answersModel, model, game.IsWaiting(), game.HasWinner(), round);
                }
            }
        }