Пример #1
0
        /// <summary>
        /// 轮换下注
        /// </summary>
        /// <param name="client"></param>
        private void Turn(ClientPeer client, int turnUserId = -1)
        {
            // 清空计时器任务
            TimerManager.Instance.Clear();
            if (fightCache.IsFighting(client.Id) == false)
            {
                return;
            }
            FightRoom room   = fightCache.GetFightRoomByUserId(client.Id);
            int       nextID = room.Turn();

            if (room.IsGiveUpCard(nextID) || room.IsLeaveRoom(nextID) || (turnUserId != -1 && nextID != turnUserId))
            {
                // 如果下一位玩家离开或弃牌了,就继续轮换下注,直到改玩家不离开也不弃牌为止
                Turn(client, turnUserId);
            }
            else
            {
                timerClient = DatabaseManager.GetClientPeerByUserId(nextID);
                // 添加计时器任务
                TimerManager.Instance.AddTimerEvent(60, TimerDelegate);
                Console.WriteLine("当前下注者" + client.UserName);
                room.Broadcast(OpCode.Fight, FightCode.StartStakes_BRO, nextID);
            }
        }
Пример #2
0
        /// <summary>
        /// 游戏结束
        /// </summary>
        /// <param name="room"></param>
        private void GameOver(FightRoom room)
        {
            PlayerDto        winPlayer = null;
            List <PlayerDto> loseList  = new List <PlayerDto>();

            foreach (var player in room.playerList)
            {
                // 胜利的玩家
                if (!room.IsGiveUpCard(player.id) && !room.IsLeaveRoom(player.id))
                {
                    winPlayer = player;
                }
                // 失败的玩家们
                else
                {
                    loseList.Add(player);
                }
            }
            DatabaseManager.UpdateCoin(winPlayer.id, room.stakesSum);
            gameOverDto.Change(winPlayer, loseList, room.stakesSum);
            room.Broadcast(OpCode.Fight, FightCode.GameOver_BRO, gameOverDto);
            //销毁房间
            fightCache.DesRoom(room);
            //清空定时任务
            TimerManager.Instance.Clear();
        }