Пример #1
0
        /// <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);
                }
            });
        }