예제 #1
0
        public void playerQuits(string id)
        {
            UserVoter tmpvoter;

            if (Program.ConnIDtoUser.TryGetValue(id, out tmpvoter))
            {
                WaitingRoom.RemoveFromWaitingR(id);
                Clients.Client(id).showNextGame(false, tmpvoter.userID, tmpvoter.TotalScore, tmpvoter.mTurkToken);
                Program.ConnIDtoUser.Remove(Context.ConnectionId);
                Console.WriteLine("[{0}] Quitter: {1} ({2}) decided to quit.. his score: {3}", DateTime.Now.ToString("HH:mm:ss"), tmpvoter.userID, tmpvoter.mTurkID != "" ? tmpvoter.mTurkID : tmpvoter.connectionID, tmpvoter.TotalScore);
                waitingRoomStats();
                WaitingRoom.checkToStartGame();
            }
        }
예제 #2
0
        public override Task OnDisconnected(bool stopCalled)
        {
            Game      theGame      = Program.getplayersGame(Context.ConnectionId);
            UserVoter removedVoter = null;
            int       playerIndex  = -1;
            var       sb           = new StringBuilder();

            if (Program.ConnIDtoUser.TryGetValue(Context.ConnectionId, out removedVoter))
            {
                playerIndex = removedVoter.inGameIndex;
                sb.AppendFormat("[{0}] Disconnected: Player {1} ({2}). ", DateTime.Now.ToString("HH:mm:ss"), removedVoter.userID,
                                removedVoter.mTurkID != "" ? removedVoter.mTurkID : Context.ConnectionId);
                if (removedVoter.CurrGame != null)
                {
                    sb.AppendFormat("Left game {0}.", removedVoter.CurrGame.gameID);
                }
                Console.WriteLine(sb);
                WaitingRoom.RemoveFromWaitingR(Context.ConnectionId);
                Program.ConnIDtoUser.Remove(Context.ConnectionId);
            }
            waitingRoomStats();

            if (Program.PlayingGames.Count > 0)
            {
                if (theGame != null && !theGame.gameOver)
                {
                    theGame.replacePlayer(playerIndex, removedVoter);
                    theGame.deletePlayerID(Context.ConnectionId);
                    if (theGame.turn == playerIndex)
                    {
                        theGame.GameOver();
                        sendGameOver(theGame);
                    }
                    else
                    {
                        theGame.endNextVote = true;
                    }
                    if (false)
                    {
                        if (theGame.playersID.Count == 0)
                        {
                            theGame.endGame();
                        }
                        else if (theGame.playersID.Count > 0 && theGame.turn == playerIndex)
                        {
                            int next = theGame.getNextTurn();
                            if (next != -1 && theGame.playersID.Count > 0)
                            {
                                if (theGame.playersID.Count > 0)
                                {
                                    if (theGame.playersID.Count - 1 == theGame.humanTurn ||
                                        theGame.playersID.Count <= theGame.humanTurn)
                                    {
                                        theGame.humanTurn = 0;
                                        updateOtherPlayers(theGame, Context.ConnectionId, playerIndex, next);
                                        UpdatePlayer(theGame, Context.ConnectionId, playerIndex, next);
                                    }
                                    else
                                    {
                                        updateOtherPlayers(theGame, Context.ConnectionId, playerIndex, next);
                                        UpdatePlayer(theGame, Context.ConnectionId, playerIndex, next);
                                    }
                                }
                            }
                            else
                            {
                                sendGameOver(theGame);
                            }
                        }
                        else
                        {
                            if (theGame.playersID.Count <= theGame.humanTurn)
                            {
                                theGame.humanTurn = 0;
                            }
                        }
                    }
                }
            }
            WaitingRoom.checkToStartGame();
            return(null);
        }