Esempio n. 1
0
 /// <summary>
 /// 离开
 /// </summary>
 /// <param name="client"></param>
 private void leave(ClientPeer client)
 {
     SingleExecute.Instance.Execute(
         delegate()
     {
         int userId = userCache.GetId(client);
         //用户没有匹配 不能退出 非法操作
         if (matchCache.IsMatching(userId) == false)
         {
             //  client.Send(OpCode.MATCH, MatchCode.LEAVE_SRES, -1);
             return;
         }
         MatchRoom room = matchCache.GetRoom(userId);
         if (room.UIdClientDict.Keys.Count > 1)
         {
             //正常离开
             room = matchCache.Leave(userId);
             //广播给房间所有人 有人离开了 参数:离开的用户id
             room.Brocast(OpCode.MATCH, MatchCode.LEAVE_BRO, userId);
         }
         else
         {
             matchCache.Destroy(room);
             client.Send(OpCode.MATCH, MatchCode.BACK_BRO, null);
             return;
         }
         Console.WriteLine("有玩家退出匹配房间");
     });
 }
Esempio n. 2
0
        /// <summary>
        /// 准备
        /// </summary>
        /// <param name="client"></param>
        private void ready(ClientPeer client)
        {
            SingleExecute.Instance.Execute(
                () =>
            {
                if (userCache.IsOnline(client) == false)
                {
                    return;
                }
                int userId = userCache.GetId(client);
                if (matchCache.IsMatching(userId) == false)
                {
                    return;
                }
                //一定要注意安全的验证
                MatchRoom room = matchCache.GetRoom(userId);
                room.Ready(userId);
                //之前忘记了 &&&……%……&¥&¥&%#%#&¥&……%&
                room.Brocast(OpCode.MATCH, MatchCode.READY_BRO, userId);

                //检测:是否所有玩家都准备了
                if (room.IsAllReady())
                {
                    //开始战斗
                    startFight(room.GetUIdList());
                    //通知房间内的玩家  要进行战斗了 给客户端群发消息
                    room.Brocast(OpCode.MATCH, MatchCode.START_BRO, null);
                    //销毁房间
                    matchCache.Destroy(room);
                }
            }
                );
        }
Esempio n. 3
0
 /// <summary>
 /// 准备
 /// </summary>
 /// <param name="client"></param>
 private void Ready(ClientPeer client)
 {
     SingleExecute.Instance.Execute(() =>
     {
         //安全校验
         if (!userCache.IsOnLine(client))
         {
             return;
         }
         int userId = userCache.GetIdByClient(client);
         if (matchCache.IsMatching(userId) == false)
         {
             return;
         }
         //玩家准备list添加
         MatchRoom room = matchCache.GetRoom(userId);
         room.Ready(userId);
         room.Brocast(OpCode.MATCH, MatchCode.READY_BRO, userId);
         //每准备一个 判断一下是否全部准备
         if (room.IsReady())
         {
             //开始进入战斗
             //客户端群发进入战斗
             startFight(room.GetIdList());
             room.Brocast(OpCode.MATCH, MatchCode.START_BRO, null);
             //销毁准备房间
             matchCache.Destroy(room);
         }
     });
 }
Esempio n. 4
0
        /// <summary>
        /// 准备
        /// </summary>
        /// <param name="client"></param>
        private void ready(ClientPeer client)
        {
            SingleExecute.Instance.Execute(() =>
            {
                if (userCache.IsOnline(client) == false)
                {
                    return;
                }
                int userId = userCache.GetId(client);
                if (matchCache.IsMatching(userId) == false)
                {
                    return;
                }
                MatchRoom room = matchCache.GetRoom(userId);
                room.Ready(userId);
                room.Brocast(OpCode.MATCH, MatchCode.READY_BRO, userId);

                //检测: 是否所有玩家都准备了
                if (room.IsAllReady())
                {
                    //开始战斗
                    //TODO
                    //通知房间内玩家 要进行战斗了 给客户端群发消息
                    room.Brocast(OpCode.MATCH, MatchCode.START_BRO, null);
                    //销毁房间
                    matchCache.Destroy(room);
                }
            });
        }
Esempio n. 5
0
        /// <summary>
        /// player ready
        /// </summary>
        /// <param name="client"></param>
        private void ready(ClientPeer client)
        {
            SingleExecute.Instance.Execute(() =>
            {
                if (userCache.IsOnline(client) == false)
                {
                    return;
                }
                int userId = userCache.GetId(client);
                if (matchCache.IsMatching(userId) == false)
                {
                    return;
                }

                MatchRoom room = matchCache.GetRoom(userId);
                room.Ready(userId);
                room.Broadcast(OpCode.MATCH, MatchCode.READY_BROADCAST, userId);

                //check:all player is ready
                if (room.IsAllReady())
                {
                    //start play card,deal cards
                    startFight(room.GetUIdList);
                    //send all player start play cards
                    room.Broadcast(OpCode.MATCH, MatchCode.START_BROADCAST, null);
                    //destroy room
                    matchCache.Destroy(room);
                }
            });
        }
Esempio n. 6
0
        /// <summary>
        /// 准备
        /// </summary>
        /// <param name="client"></param>
        private void Ready(ClientPeer client)
        {
            socketMsg.State   = MatchCode.Success;
            socketMsg.OpCode  = MsgType.Match;
            socketMsg.SubCode = MatchCode.Ready_Broadcast_Result;
            SingleExecute.Instance.Execute(() =>
            {
                if (!userCache.IsOnline(client))
                {
                    return;
                }
                int userId = userCache.GetClientUserId(client);
                if (!matchCache.IsMatching(userId))
                {
                    return;
                }
                //准备
                MatchRoom room = matchCache.GetRoom(userId);
                if (room.ReadyUIdList.Where(w => w == userId).ToList().Count > 0)
                {
                    return;
                }
                room.Ready(userId);
                socketMsg.value = userId;
                room.Brocast(socketMsg);

                //检测是否所有玩家都准备了
                if (room.IsAllReady())
                {
                    //开始游戏
                    startFight(room.ReadyUIdList);
                    //广播通知所有玩家游戏开始
                    socketMsg.SubCode = MatchCode.Start_Broadcast_Requst;
                    room.Brocast(socketMsg);
                    //销毁房间
                    matchCache.Destroy(room);
                }
            });
        }
        /// <summary>
        /// 用户准备
        /// </summary>
        /// <param name="client"></param>
        private void Ready(ClientPeer client)
        {
            SingleExecute.Instance.Execute(() => {
                if (!user.IsOnLine(client))
                {
                    //不在线
                    return;
                }

                int userId = user.GetId(client);
                if (!match.IsMatching(userId))
                {
                    return;//非法操作 不能准备
                }
                MatchRoom room = match.GetRoom(userId);
                room.Ready(userId);

                //广播消息  准备了 为什么要给自己发,确保服务器收到准备请求 回复消息后 将准备按钮隐藏
                room.Brocast(OpCode.MATCHROOM, MatchRoomCode.READY_BRO, userId);

                Console.WriteLine(string.Format("玩家 : {0}  在房间 :{1} 准备了", user.GetModelByClient(client).name, room.id));

                //是否所有玩家都准备了
                if (room.IsAllUserReady())
                {
                    Console.WriteLine(String.Format("房间 :{0} 开始了战斗。。。", room.id));
                    //开始战斗  调用FightHandler 的开始方法 委托
                    if (FightDelegate != null)
                    {
                        FightDelegate.Invoke(room.uidList);
                    }
                    //通知房间内的玩家 要进行战斗了 群发消息
                    room.Brocast(OpCode.MATCHROOM, MatchRoomCode.START_BRO, null);
                    match.Destroy(room);
                }
            });
        }