コード例 #1
0
        /// <summary>用户退出</summary>
        public void Logout(string userName)
        {
            User logoutUser = CC.GetUser(userName);

            foreach (var user in CC.Users)
            {
                //不需要发给退出用户
                if (user.UserName != logoutUser.UserName)
                {
                    user.callback.ShowLogout(userName);
                }
            }
            CC.Users.Remove(logoutUser);
            logoutUser = null; //将其设置为null后,WCF会自动关闭该客户端
            SendRoomsInfoToAllUsers();
        }
コード例 #2
0
        /// <summary>用户入座,参数:用户名,桌号,座位号</summary>
        public void SitDown(string userName, int index, int side)
        {
            User p = CC.GetUser(userName);

            p.Index = index;
            p.Side  = side;
            CC.Rooms[index].players[side] = p;
            //告诉入座玩家入座信息
            p.callback.ShowSitDown(userName, side);

            int  anotherSide = (side + 1) % 2; //同一桌的另一个玩家
            User p1          = CC.Rooms[index].players[anotherSide];

            if (p1 != null)
            {
                //告诉入座玩家另一个玩家是谁
                p.callback.ShowSitDown(p1.UserName, anotherSide);
                //告诉另一个玩家入座玩家是谁
                p1.callback.ShowSitDown(p.UserName, side);
            }
            //重新将游戏室各桌情况发送给所有用户
            SendRoomsInfoToAllUsers();
        }