コード例 #1
0
ファイル: GameController.cs プロジェクト: innerjoin/dog2go
        private bool AddParticipantToTable(int tableId)
        {
            List <GameTable> gameTableList = GameRepository.Instance.Get();
            GameTable        gameTable     = gameTableList?.Find(table => table.Identifier.Equals(tableId));

            if (ParticipationService.IsAlreadyParticipating(gameTable, User.Identity.Name))
            {
                return(true);
            }
            return(ParticipationService.AddParticipation(gameTable, User.Identity.Name));
        }
コード例 #2
0
ファイル: GameHub.cs プロジェクト: innerjoin/dog2go
        public GameTable ConnectToTable(int gameTableId)
        {
            lock (Locker)
            {
                GameTable       table   = GameTableService.GetTable(Games, gameTableId);
                string          curUser = Context.User.Identity.Name;
                List <HandCard> cards   = null;

                if (GameTableService.AlreadyConnected(table, curUser))
                {
                    Participation participation = ParticipationService.GetParticipation(table, curUser);

                    if (table.Participations.Count == GlobalDefinitions.NofParticipantsPerTable && !table.IsInitialized)
                    {
                        AllConnected(table);
                        Clients.Client(Context.ConnectionId).createGameTable(table, table.Identifier);
                    }
                    else
                    {
                        cards = table.CardServiceData?.GetActualHandCards(participation.Participant, table);
                        Task task = Clients.Client(Context.ConnectionId).backToGame(table, cards, table.Identifier);
                        task.Wait();
                    }
                    if (table.ActualParticipation == participation)
                    {
                        NotifyActualPlayer(participation.Participant, cards, table.Identifier);
                    }
                }
                else
                {
                    ParticipationService.AddParticipation(table, curUser);
                    Clients.Client(Context.ConnectionId).createGameTable(table);
                }
                return(table);
            }
        }