Exemplo n.º 1
0
        /// <summary>
        /// 玩家离开座位后事件处理
        /// </summary>
        /// <param name="inningeGame"></param>
        /// <param name="e"></param>
        public override void AfterPlayerLeave(object inningeGame, EventArgs e)
        {
            string playerId    = ((PlayerEventArgs)e).Player.Id.ToString();
            var    roomMessage = WebscoketSendObjs.RoomMessage(0, "玩家" + playerId + "离开了");

            Notify?.Invoke(roomMessage);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 玩家坐下后事件处理
        /// </summary>
        /// <param name="inningeGame"></param>
        /// <param name="e"></param>
        public override void AfterSitDown(object inningeGame, EventArgs e)
        {
            var roomMessage = WebscoketSendObjs.RoomMessage(0, "有玩家进入");

            NotifyRoomPlayers(roomMessage);
            // Notify?.Invoke(roomMessage);
        }
Exemplo n.º 3
0
 public override void GameStart(object inngineGame, EventArgs e)
 {
     InningeGame = (IInningeGame)inngineGame;
     MaJiangManager.Riffile();
     NotifyRoomPlayers(new FreshGameFace(0));
     NotifyRoomPlayers(WebscoketSendObjs.RoomMessage(0, "游戏开始了!请准备!"));
 }
Exemplo n.º 4
0
 public void Deal(int playerId)
 {
     // if (IsChipinClose) {
     if (CurrentStage != EStage.CanChipIning)
     {
         NotifySinglePlayer(WebscoketSendObjs.RoomMessage(playerId, "不是押底阶段,不能发牌!"), playerId);
         return;
     }
     // if (JoinSeats.Count() != InningeGame.NotEmptySeats().Count()) {
     if (JoinSeats.Count() < 2)
     {
         NotifyRoomPlayers(WebscoketSendObjs.RoomMessage(0, "押底人数不足2人,不能发牌"));
         return;
     }
     CheckDateTime = DateTime.Now;
     //  IsChipinClose = true;//?
     PokerManager.Riffile();
     lock (this) {
         for (int i = 0; i < JoinSeats.Count(); i++)
         {
             ThreeCards threeCards = new ThreeCards(PokerManager.TackOut(3));
             JoinSeats[i].Pokers      = threeCards;
             JoinSeats[i].PreChipType = EChipinType.PlayerChipIn;
         }
         CurrentStage = EStage.Running;
     }
     CheckDateTime = DateTime.Now;
     NotifyRoomPlayers(new FreshGameFace(0));
     NotifyRoomPlayers(WebscoketSendObjs.RoomMessage(0, "发牌完毕,庄家开始下注"));
 }
Exemplo n.º 5
0
        /// <summary>
        /// 检查玩家是否超时
        /// </summary>
        /// <param name="obj"></param>
        private void CheckPlayOverTime(object obj)
        {
            //超时62秒
            int overSeconds = 63;

            do
            {
                overSeconds = Math.Abs(overSeconds);
                Thread.Sleep(TimeSpan.FromSeconds(overSeconds));
                overSeconds = OverTimeSpan(overSeconds);
                //if (0<=overSeconds&&overSeconds<5) {
                //    overSeconds = 5;
                //}
            } while (overSeconds < 2);
            if (InningeGame.NotEmptySeats().Count > 1 && !(CurrentSeat.IPlayer is null))
            {
                int currentPlayerId = CurrentSeat.IPlayer.Id;
                do
                {
                    NotifyRoomPlayers(WebscoketSendObjs.RoomMessage(0, "有玩家超时,将被自动踢出"));
                    RemoveCurrentPlayer();
                } while (currentPlayerId == CurrentSeat.IPlayer.Id);
            }
            CheckPlayOverTime(obj);
        }
Exemplo n.º 6
0
        public void PlayerChipin(int playerId)
        {
            //  if (IsChipinClose) {
            if (CurrentStage != EStage.CanChipIning && CurrentStage != EStage.Computed)
            {
                NotifySinglePlayer(WebscoketSendObjs.RoomMessage(0, "未开局或结束,不能押底!"), playerId);
                return;
            }
            Seat seat = GetRoomSeatByPlayerId(playerId);

            if (seat.IsChipIned)
            {
                NotifySinglePlayer(WebscoketSendObjs.RoomMessage(0, "已经押底!"), playerId);
                NotifyRoomPlayers(new FreshGameFace(0));
                return;
            }
            if (InningeGame.NotEmptySeats().Count < 2)
            {
                NotifySinglePlayer(WebscoketSendObjs.RoomMessage(0, "房间人数少于两人,不能押底"), playerId);
                NotifyRoomPlayers(new FreshGameFace(0));
                return;
            }
            lock (seat) {
                if (seat.PlayerChipin(ChipInAmount, IsDecutMoneySuccess))
                {
                    AddPlaySeat(seat);
                    AddCurrentTotal(ChipInAmount);
                }
            }
            CheckDateTime = DateTime.Now;
            NotifyRoomPlayers(new FreshGameFace(0));
            NotifySinglePlayer(WebscoketSendObjs.RoomMessage(0, "已押底,等待庄家发牌!"), playerId);
        }
Exemplo n.º 7
0
        public override void AfterPlayerLeave(object inningeGame, EventArgs e)
        {
            var notEmptySeatsCount = ((IInningeGame)inningeGame).NotEmptySeats().Count();

            if (notEmptySeatsCount > 0)
            {
                if (CurrentStage == EStage.Running && JoinSeats.Count() == 1)
                {
                    CompareAll();
                    NotifyRoomPlayers(WebscoketSendObjs.RoomMessage(0, "有玩家要离开,人数不足,自动结算"));
                }
                else if (notEmptySeatsCount == 1)
                {
                    CurrentStage = EStage.CanChipIning;
                    if (JoinSeats.Count() == 1)
                    {
                        var onlySeat = JoinSeats[0];
                        if (onlySeat.IsChipIned)
                        {
                            onlySeat.IsChipIned = false;
                            IsDecutMoneySuccess(onlySeat.IPlayer, -onlySeat.ChipinAmount);
                        }
                        onlySeat.IsGaveUp = false;
                        onlySeat.IsLooked = false;
                        NotifyRoomPlayers(WebscoketSendObjs.RoomMessage(0, "有玩家要离开,人数不足,退还你的押底"));
                    }
                    NotifyRoomPlayers(WebscoketSendObjs.RoomMessage(0, "有玩家要离开,人数不足,取消押底"));
                }
                base.AfterPlayerLeave(inningeGame, e);
                NotifyRoomPlayers(new FreshGameFace(0));
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// 轮到下一个玩家表态
 /// </summary>
 private void MoveToNextSeat(decimal amount, bool isLook, int playerId, EChipinType chipinType = EChipinType.Nothing)
 {
     lock (this) {
         PreSeatAmount = amount;
         if (chipinType != EChipinType.GaveUp)
         {
             CurrentSeat.PreChipInAmount = amount;
             CurrentSeat.PreChipType     = chipinType;
             AddCurrentTotal(amount);
         }
         Seat tempSeat = CurrentSeat;
         do
         {
             tempSeat = GetNextJoinSeat(tempSeat);
         } while (tempSeat.IsGaveUp);
         CurrentSeat   = tempSeat;
         PreSeatIsLook = isLook;
         if (CurrentSeat == FirstSeat)
         {
             CurrentTurn++;
         }
         if (CurrentTurn > DefaultTurnCount)
         {
             NotifyRoomPlayers(WebscoketSendObjs.RoomMessage(0, "超过最大轮次,自动比牌"));
             CompareAll();
         }
         if (JoinSeats.Where(s => s.IsGaveUp == false).Count() == 1)
         {
             CompareAll();
         }
     }
     CheckDateTime = DateTime.Now;
     NotifyRoomPlayers(new ChipinAnimation(0, amount, playerId, chipinType));
     NotifyRoomPlayers(new FreshGameFace(0));
 }
Exemplo n.º 9
0
 /// <summary>
 /// 账户是否够
 /// </summary>
 /// <param name="player"></param>
 /// <param name="amount"></param>
 /// <returns></returns>
 private bool IsAccountEnougth(IPlayerJoinRoom player, decimal amount)
 {
     if (player.AccountNotEnough(amount))
     {
         NotifySinglePlayer(WebscoketSendObjs.Alert(player.Id, "账户余额不足"), player.Id);
         NotifySinglePlayer(WebscoketSendObjs.RoomMessage(WinnerSeat.IPlayer.Id, "账户余额不足"), WinnerSeat.IPlayer.Id);
         return(false);
     }
     return(true);
 }
Exemplo n.º 10
0
 /// <summary>
 /// 扣款成功
 /// </summary>
 /// <param name="player"></param>
 /// <param name="amount"></param>
 /// <returns></returns>
 private bool IsDecutMoneySuccess(IPlayerJoinRoom player, decimal amount)
 {
     if (IsAccountEnougth(player, amount))
     {
         player.DecutMoney(amount);
         return(true);
     }
     NotifySinglePlayer(new Alert(player.Id, "账户余额不足"), player.Id);
     NotifySinglePlayer(WebscoketSendObjs.RoomMessage(player.Id, "账户余额不足"), player.Id);
     return(false);
 }
Exemplo n.º 11
0
        /// <summary>
        /// 检查能不能开始
        /// </summary>
        /// <param name="innineGame_">本局游戏</param>
        /// <returns>YN</returns>
        public override bool CheckStart(IInningeGame innineGame_)
        {
            int playerOnSeatCopunt = innineGame_.NotEmptySeats().Count;

            if (playerOnSeatCopunt < innineGame_.IGameProject.PlayerCountLeast || playerOnSeatCopunt > PlayerCountLimit)
            {
                Notify?.Invoke(WebscoketSendObjs.RoomMessage(0, "人数不足,不能启动游戏"));
                return(false);
            }
            return(true);
        }
Exemplo n.º 12
0
 public override void ResetGame(object inningeGame, EventArgs e)
 {
     InitPublicInfo();
     if (FirstSeat is null)
     {
         FirstSeat   = GetRoomSeatByPlayerId(InningeGame.IRoom.RoomManager.Id);
         CurrentSeat = FirstSeat;
     }
     if (CurrentSeat is null)
     {
         CurrentSeat = FirstSeat;
     }
     NotifyRoomPlayers(new FreshGameFace(0));
     NotifyRoomPlayers(WebscoketSendObjs.RoomMessage(0, "新一局开始!开始押底!"));
 }
Exemplo n.º 13
0
        public void Look(int playerId)
        {
            Seat seat = GetJionSeatByPlayerId(playerId);

            if (seat is null)
            {
                NotifySinglePlayer(WebscoketSendObjs.RoomMessage(playerId, "没有加入本局,自己无牌!"), playerId);
                return;
            }
            if (seat.Pokers is null || seat.Pokers.Cards.Count != 3)
            {
                NotifySinglePlayer(WebscoketSendObjs.RoomMessage(playerId, "还未发牌,不能查看!"), playerId);
                return;
            }
            seat.LookOneCard();
            NotifySinglePlayer(new FreshGameFace(playerId), playerId);
        }
Exemplo n.º 14
0
 public override void GameStart(object inngineGame, EventArgs e)
 {
     InningeGame  = (IInningeGame)inngineGame;
     PokerManager = new PokersWithoutKingManger();
     if (CurrentStage == EStage.Reading)
     {
         CheckThead = new Thread(CheckPlayOverTime);
         CheckThead.Start();
     }
     InitPublicInfo();
     if (FirstSeat is null)
     {
         FirstSeat   = GetRoomSeatByPlayerId(InningeGame.IRoom.RoomManager.Id);
         CurrentSeat = FirstSeat;
     }
     if (CurrentSeat is null)
     {
         CurrentSeat = FirstSeat;
     }
     NotifyRoomPlayers(new FreshGameFace(0));
     NotifyRoomPlayers(WebscoketSendObjs.RoomMessage(0, "游戏开始了!请开始押底!"));
 }
Exemplo n.º 15
0
 public override void ResetGame(object inningeGame, EventArgs e)
 {
     CheckDateTime = DateTime.Now;
     InitPublicInfo();
     if (FirstSeat is null)
     {
         FirstSeat   = GetRoomSeatByPlayerId(InningeGame.IRoom.RoomManager.Id);
         CurrentSeat = FirstSeat;
     }
     if (CurrentSeat is null)
     {
         CurrentSeat = FirstSeat;
     }
     NotifyRoomPlayers(new FreshGameFace(0));
     if (InningeGame.IRoom.Players.Count > 1)
     {
         NotifyRoomPlayers(WebscoketSendObjs.RoomMessage(0, "新一局开始!开始押底!"));
     }
     else
     {
         NotifyRoomPlayers(WebscoketSendObjs.RoomMessage(0, "人数不足,不能开始"));
     }
 }
Exemplo n.º 16
0
        /// <summary>
        /// 满足最大轮次等条件时自动开牌
        /// </summary>
        private void CompareAll()
        {
            if (CurrentStage != EStage.Running)
            {
                return;
            }
            CheckDateTime = DateTime.Now;
            List <Seat> notGaveupSeats = new List <Seat>();

            if (JoinSeats.Count != 0)
            {
                CheckDateTime = DateTime.Now;
                for (int i = 0; i < JoinSeats.Count; i++)
                {
                    if (JoinSeats[i].IsGaveUp)
                    {
                        continue;
                    }
                    notGaveupSeats.Add(JoinSeats[i]);
                }
                WinnerSeat = (notGaveupSeats.OrderByDescending(s => s.Pokers).ToList())[0];
            }
            decimal playerWinAmount = 0;

            playerWinAmount = SystemTax(playerWinAmount);
            WinnerSeat.IPlayer.DecutMoney(-playerWinAmount);
            FirstSeat    = WinnerSeat;//新庄家
            CurrentSeat  = WinnerSeat;
            CurrentStage = EStage.Computed;
            NotifyRoomPlayers(WebscoketSendObjs.RoomMessage(0, "自动开牌"));
            NotifyRoomPlayers(new FreshGameFace(0));
            NotifySinglePlayer(WebscoketSendObjs.RoomMessage(0, "你赢了"), WinnerSeat.IPlayer.Id);
            NotifySinglePlayer(WebscoketSendObjs.RoomMessage(0, playerWinAmount + "分"), WinnerSeat.IPlayer.Id);
            NotifyRoomPlayersExcept(WebscoketSendObjs.RoomMessage(0, "你输了"), WinnerSeat.IPlayer.Id);
            CheckDateTime = DateTime.Now;
            InningeGame.GameOver(false, false);//触发游戏结束事件
        }
Exemplo n.º 17
0
        public void Compare(int playerId)
        {
            CheckDateTime = DateTime.Now;
            if (CurrentStage != EStage.Running)
            {
                return;
            }
            Seat seat = GetJionSeatByPlayerId(playerId);

            if (IsNotPassedCheck(seat))
            {
                return;
            }
            bool iHadLook    = seat.IsLooked;
            Seat opponetSeat = GetOnlyOpponentSeat(playerId);

            if (null == opponetSeat)
            {
                return;
            }
            CheckDateTime = DateTime.Now;
            decimal chipInAmount = PreSeatAmount;

            if (iHadLook != PreSeatIsLook)
            {
                if (PreSeatIsLook)
                {
                    chipInAmount = chipInAmount / 2;
                }
                else
                {
                    chipInAmount = chipInAmount * 2;
                }
            }
            if (chipInAmount > LimitAmount)
            {
                chipInAmount = LimitAmount;
            }
            if (!IsDecutMoneySuccess(seat.IPlayer, chipInAmount))
            {
                return;
            }
            AddCurrentTotal(chipInAmount);
            seat.PreChipInAmount = chipInAmount;
            seat.PreChipType     = EChipinType.Compare;
            WinnerSeat           = GetWinner(seat, opponetSeat);
            decimal playerWinAmount = 0;

            playerWinAmount = SystemTax(playerWinAmount);
            WinnerSeat.IPlayer.DecutMoney(-playerWinAmount);
            FirstSeat    = WinnerSeat;//新庄家
            CurrentSeat  = WinnerSeat;
            CurrentStage = EStage.Computed;
            NotifyRoomPlayers(WebscoketSendObjs.RoomMessage(0, "开牌"));
            NotifyRoomPlayers(new ChipinAnimation(0, chipInAmount, playerId, EChipinType.Compare));
            NotifyRoomPlayers(new FreshGameFace(0));
            NotifySinglePlayer(WebscoketSendObjs.RoomMessage(0, "你赢了"), WinnerSeat.IPlayer.Id);
            NotifySinglePlayer(WebscoketSendObjs.RoomMessage(0, playerWinAmount + "分"), WinnerSeat.IPlayer.Id);
            NotifyRoomPlayersExcept(WebscoketSendObjs.RoomMessage(0, "你输了"), WinnerSeat.IPlayer.Id);
            InningeGame.GameOver(false, false);
        }
Exemplo n.º 18
0
 public override void GameOver(object inningeGame, EventArgs e)
 {
     CheckDateTime = DateTime.Now;
     NotifyRoomPlayers(WebscoketSendObjs.RoomMessage(0, "本局结束!等待庄家开启新的一局"));
 }
Exemplo n.º 19
0
 public override void ResetGame(object inningeGame, EventArgs e)
 {
     NotifyRoomPlayers(new FreshGameFace(0));
     NotifyRoomPlayers(WebscoketSendObjs.RoomMessage(0, "新一局开始!开始押底!"));
 }