Beispiel #1
0
 public UserData(User user)
 {
     role = user.role;
     Id = user.Id;
     Name = user.Name;
     RoomId = user.RoomId;
     Token = user.Token;
 }
Beispiel #2
0
        public void Vote(User user, bool up)
        {
            if(VotedUsers.Contains(user.Id))
                GameException.Throw("Вы не можете голосовать дважды");

            if (up)
                VotesUp++;
            else
                VotesDown++;

            VotedUsers.Add(user.Id);
        }
        public static void AddOnlineUser(User user)
        {
            lock (OnlineUsers)
            {
                if (RoomControll.CheckUser(user.Name))
                {
                    LogoffUser(user);
                }
                OnlineUsers.Add(user);
            }

            // assign user to lobby
            user.RoomId = 0;
            Rooms[0].EnterRoom(user);
        }
        public static void DeleteOnlineUser(User user)
        {
            lock (OnlineUsers)
            {
                //TODO: error handling?
                try
                {
                    OnlineUsers.Remove(user);
                }
                catch (Exception e)
                {
                    LogSaver.Log("Tried to delete user "+user.Id+" but it is not online");
                    //throw;
                }
            }

            Rooms[user.RoomId].LeaveRoom(user);
        }
Beispiel #5
0
        public void AcceptCurrentWordVariant(User user, string word)
        {
            if (user.role != User.Role.None)
            {
                LogSaver.Log("!!! AcceptCurrentWordVariant invoked user "+user.Id+" role "+user.role.ToString());
                GameException.Throw("Вы не можете так делать");
            }

            bool epicWin = false; // угадал primaryWord

            lock (gameState)
            {
                if(gameState.UsedWords.Contains(word))
                    GameException.Throw("Это слово уже использовалось");

                if (!word.StartsWith(gameState.PrimaryWordKnownLetters))
                    GameException.Throw("Слово должно начинаться с открытых букв");

                if (word == gameState.PrimaryWord)
                {
                    epicWin = true;
                }
                else
                {
                    gameState.VarOfCurWord = word;
                    user.role = User.Role.Contacter;
                }

            }

            if (epicWin)
            {
                ResetRoles();
                ChangeState(GameState.State.GameOver);
            }
            else
            {
                BroadcastMessage(GameMessage.UserRoleChangedMessage(user, User.Role.Contacter));
                BroadcastMessage(GameMessage.VarOfCurWordChangedMessage(word));
                ChangeState(GameState.State.HaveCurrentWordVariant);
            }
        }
        public static UserData LoginUser(string name, string password)
        {
            User user;

            lock (syncObject) //добавлено чтобы не путать OperatinContext, хотя не понятно насколько работает
            {
            #if DEBUG
            user = new User(userCnt, name);
            ++userCnt;
            #else
            user = DBAccess.CheckUser(name, password);
            #endif

            if (user.Id != -1)
            RoomControll.AddOnlineUser(user);

            }

            return new UserData(user);
        }
Beispiel #7
0
        public void AcceptChiefWord(User user, string word)
        {
            if (user.role != User.Role.Host)
            {
                LogSaver.Log("!!! AcceptChiefWord invoked user " + user.Id + " role " + user.role.ToString());
                GameException.Throw("Вы не можете так делать");
            }

            lock (gameState)
            {
                if (gameState.UsedWords.Contains(word))
                    GameException.Throw("Это слово уже использовалось");

                if (!word.StartsWith(gameState.PrimaryWordKnownLetters))
                    GameException.Throw("Слово должно начинаться с открытых букв");
                if (word == gameState.PrimaryWord)
                    GameException.Throw("Так ты спалишь загаданное слово!");

                gameState.PrepareForVoting(1);
                gameState.ChiefWord = word;
                BroadcastMessage(GameMessage.WeHaveChiefWord(word));
                ChangeState(GameState.State.VotingForHostWord);
            }
        }
Beispiel #8
0
        public void EnterRoom(User user)
        {
            lock (gameState)
            {
                gameState.Users.Add(user);
            }

            BroadcastMessage(GameMessage.UserJoinedRoomMessage(user));
        }
Beispiel #9
0
        public void LeaveRoom(User user)
        {
            lock (gameState)
            {
                gameState.Users.Remove(user);
            }

            if (user.role == User.Role.Host)
            {
                ChangeState(GameState.State.GameOver);
                ResetRoles();
            }
            else
            {
                if (user.role == User.Role.Qwestioner)
                {
                    ChangeState(GameState.State.HaveNoCurrentWord);
                }
                BroadcastMessage(GameMessage.UserRoleChangedMessage(user, User.Role.None));
            }

            if (gameState.Users.Count < 3 && gameState.state != GameState.State.NotStarted)
            {
                ChangeState(GameState.State.GameOver);
                ResetRoles();
            }

            BroadcastMessage(GameMessage.UserLeftRoomMessage(user));
        }
Beispiel #10
0
        public void AcceptQuestion(User user, string question, string word)
        {
            if (user.role != User.Role.None)
            {
                LogSaver.Log("!!! AcceptQuestion invoked user " + user.Id + " role " + user.role.ToString());
                GameException.Throw("Вы не можете этого делать!");
            }

            bool epicWin = false; //угадал primaryWord

            lock (gameState)
            {
                gameState.Question = question;

                if (!word.StartsWith(gameState.PrimaryWordKnownLetters))
                    GameException.Throw("Слово должно начинаться с открытых букв");

                if (word == gameState.PrimaryWord)
                {
                    epicWin = true;
                }
                else
                {
                    gameState.CurrentWord = word;
                    user.role = User.Role.Qwestioner;
                }
            }

            if (epicWin)
            {
                ResetRoles();
                ChangeState(GameState.State.GameOver);
            }
            else
            {
                BroadcastMessage(GameMessage.QuestionAsked(question, word));
                BroadcastMessage(GameMessage.UserRoleChangedMessage(user, User.Role.Qwestioner));
                ChangeState(GameState.State.HaveCurrentWord);
            }
        }
Beispiel #11
0
 /*
 *   If user argument is null then the type of the message is system.
 */
 public void BroadcastChatMessage(string message, User user = null)
 {
     BroadcastMessage(GameMessage.ChatMessage(user != null ? user.Name : null, message));
 }
Beispiel #12
0
 public static void UserLeaveRoom(User user)
 {
     DeleteOnlineUser(user);
     AddOnlineUser(user);
 }
Beispiel #13
0
        public void AcceptPrimaryWord(User user, string primaryWord)
        {
            if(user.role != User.Role.Host)
            {
                LogSaver.Log("!!! AcceptPrimaryWord invoked user " + user.Id + " role " + user.role.ToString());
                GameException.Throw("Вы не можете этого делать!");
            }

            lock (gameState)
            {
                gameState.PrimaryWord = primaryWord.ToLower();
                BroadcastMessage(GameMessage.PrimaryWordGiven(gameState.PrimaryWord));
                ChangeState(GameState.State.HaveNoCurrentWord);
            }
        }
Beispiel #14
0
 public static void GiveChiefWord(User user, string word)
 {
     Rooms[user.RoomId].AcceptChiefWord(user, word);
 }
Beispiel #15
0
        public void VoteForPlayerWord(User user, int wordId, bool up)
        {
            lock (gameState)
            {
               if(user.role != User.Role.None)
                   GameException.Throw("Вы не можете голосовать");

                gameState.votings[wordId].Vote(user, up);
            }
        }
Beispiel #16
0
 public static void AskQuestion(User user, string question, string word)
 {
     Rooms[user.RoomId].AcceptQuestion(user, question, word);
 }
Beispiel #17
0
 public static void BroadcastChatMessageToRoom(User user, string message)
 {
     Rooms[user.RoomId].BroadcastChatMessage(message, user);
 }
Beispiel #18
0
 public static void GiveCurrentWordVariant(User user, string word)
 {
     Rooms[user.RoomId].AcceptCurrentWordVariant(user, word);
 }
Beispiel #19
0
 public static void VoteForPlayerWord(User user, int wordId, bool up)
 {
     Rooms[user.RoomId].VoteForPlayerWord(user, wordId, up);
 }
Beispiel #20
0
 public static void VoteForChifWord(User user, bool up)
 {
     Rooms[user.RoomId].VoteForChiefWord(user, up);
 }
Beispiel #21
0
 public void StartGame(User user)
 {
     //TODO: start with normal state
     ChangeState(GameState.State.HaveNoPrimaryWord);
     BroadcastMessage(GameMessage.UserRoleChangedMessage(user, User.Role.Host));
 }
Beispiel #22
0
 public static void SetPrimaryWord(User user, string primaryWord)
 {
     Rooms[user.RoomId].AcceptPrimaryWord(user, primaryWord);
 }
Beispiel #23
0
        public void VoteForChiefWord(User user, bool up)
        {
            lock (gameState)
            {
                if (user.role == User.Role.Host)
                    GameException.Throw("Вы не можете голосовать");

                gameState.votings[0].Vote(user, up);
            }
        }
Beispiel #24
0
 public static void LogoffUser(User user)
 {
     User us = RoomControll.GetUserByName(user.Name);
     GameMessage msg = new GameMessage();
     msg = GameMessage.LogoffUser();
     DeleteOnlineUser(us);
     try { us.Callback.Notify(msg); }
     catch { }
 }
Beispiel #25
0
 public static GameMessage UserRoleChangedMessage(User user, User.Role role)
 {
     return new GameMessage { actionType = ActionType.UserRoleChanged, actionAgrument  = new Tuple<User, User.Role>(user, role) };
 }
Beispiel #26
0
 public static void StartGame(User user)
 {
     Rooms[user.RoomId].StartGame(user);
 }
Beispiel #27
0
 public static GameState GetState(User user)
 {
     return Rooms[user.RoomId].GetState();
 }
Beispiel #28
0
        public static void GotoRoom(User user, int roomId)
        {
            if (!Rooms.ContainsKey(roomId))
            {
                LogSaver.Log("!?! Trying to go to nonexistent room "+roomId+" userId="+user.Id);
                GameException.Throw("Комнаты с таким номером нет");
            }

            if (roomId == user.RoomId) return;

            Rooms[user.RoomId].LeaveRoom(user);
            user.RoomId = roomId;
            Rooms[roomId].EnterRoom(user);
        }
Beispiel #29
0
 public static List<Room> GetRoomsList(User user)
 {
     return Rooms.Values.ToList();
 }
Beispiel #30
0
 public static GameMessage UserLeftRoomMessage(User user)
 {
     return new GameMessage {actionType = ActionType.UserLeftRoom, actionAgrument = user};
 }