/// <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); }
/// <summary> /// 玩家获得一张牌 /// </summary> /// <param name="playerId_">玩家Id</param> /// <returns>获得的牌</returns> public ABCard PlayerGetOnePoker(int playerId) { var seat = InningeGame.GetSeatByPlayerId(playerId); var player = seat.IPlayer; var opponentId = GetOpponentId(playerId); var opponentSeat = InningeGame.GetSeatByPlayerId(opponentId); if (player.AccountNotEnough(ChipInAmount)) { Notify?.Invoke(WebscoketSendObjs.Alert(player.Id, "账户余额不足")); } if (seat.GameDateObj["getPokers"].Count > 0) { return(null); } player.DecutMoney(ChipInAmount); if (Poker.RemaindCount > 0) { var card = Poker.TackOut(1)[0]; seat.GameDateObj["getPokers"].Add(card); seat.GameDateObj["compareResult"].Clear(); Notify?.Invoke(WebscoketSendObjs.FreshGameFace(player.Id)); return(card); } InningeGame.GameOver();//触发游戏结束事件 return(null); }
public ABCard PlayerGetOnePoker(int playerId) { Seat seat = GetSeatByPlayerId(playerId); var player = seat.IPlayer; int opponentId = GetOpponentId(playerId); Seat opponentSeat = GetSeatByPlayerId(opponentId); if (player.AccountNotEnough(ChipInAmount)) { NotifySinglePlayer(WebscoketSendObjs.Alert(player.Id, "账户余额不足"), player.Id); } if (null == seat.PlayOutPokers && null != seat.GetPoker) { return(null); } player.DecutMoney(ChipInAmount); lock (Locker) { if (Poker.RemaindCount > 0) { if (null == seat.PlayOutPokers) { var card = Poker.TackOut(1)[0]; seat.GetPoker = card; seat.CompareResult = null; NotifySinglePlayer(WebscoketSendObjs.FreshGameFace(player.Id), player.Id); return(card); } return(null); } InningeGame.GameOver();//触发游戏结束事件 return(null); } }
/// <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)); }
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, "发牌完毕,庄家开始下注")); }
/// <summary> /// 游戏异常中断 /// </summary> /// <param name="inningeGame">本局游戏</param> /// <param name="e"></param> public override void Stoped(object inningeGame, EventArgs e) { var myE = (GameStopedEventArgs)e; // Notify?.Invoke(WebscoketSendObjs.Stoped(0,myE.Message)); NotifyRoomPlayers(WebscoketSendObjs.Stoped(0, myE.Message)); }
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)); } }
public override void GameStart(object inngineGame, EventArgs e) { InningeGame = (IInningeGame)inngineGame; MaJiangManager.Riffile(); NotifyRoomPlayers(new FreshGameFace(0)); NotifyRoomPlayers(WebscoketSendObjs.RoomMessage(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); }
/// <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); }
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); }
private void RemoveCurrentPlayer() { var id = CurrentSeat.IPlayer.Id; NotifySinglePlayer(WebscoketSendObjs.LeaveRoom(id), id); var room = InningeGame.IRoom; room.RemovePlayerById(id); }
public void KickPlayer(int playerId) { if (player.Id != _room.RoomManager.Id) { return; } // _room.RemovePlayerById(playerId); ClientWebsocketsManager.Send(WebscoketSendObjs.LeaveRoom(playerId)); }
/// <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); return(false); } return(true); }
/// <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); }
/// <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); }
/// <summary> /// 出牌或出牌后比较大小 /// </summary> /// <param name="playerId">玩家Id</param> /// <param name="card_">一张牌</param> /// <returns>获胜玩家座位</returns> public void PlayerPlayOutOnePoker(int playerId) { var meSeat = InningeGame.GetSeatByPlayerId(playerId); var opponentId = GetOpponentId(playerId); var opponentSeat = InningeGame.GetSeatByPlayerId(opponentId); var opponentPayOut = opponentSeat.GameDateObj["playOutPokers"]; var opponentCompareResult = opponentSeat.GameDateObj["compareResult"]; object card = null; //var card = CheckCardExist(playerId, card_); if (meSeat.GameDateObj["getPokers"].Count == 0) { return; } var mePoker = meSeat.GameDateObj["getPokers"]; card = mePoker[0]; var mePayOut = meSeat.GameDateObj["playOutPokers"]; var meCompareResult = meSeat.GameDateObj["compareResult"]; ISeat winPlayer = null; if (card != null) { mePoker.Remove(card); mePayOut.Add(card); if (opponentPayOut.Count > 0) { if (((ABCard)mePayOut[0]).ComparedValue > ((ABCard)opponentPayOut[0]).ComparedValue) { winPlayer = meSeat; } else { winPlayer = opponentSeat; } mePayOut.Remove(card); meCompareResult.Add(card); opponentCompareResult.Add(opponentPayOut[0]); opponentPayOut.Clear(); winPlayer.IPlayer.DecutMoney(-ChipInAmount); foreach (var item in InningeGame.NotEmptySeats())//通知全部客户端刷新 { // Notify?.Invoke(item.IPlayer.Id, "FreshGameFace"); Notify?.Invoke(WebscoketSendObjs.FreshGameFace(item.IPlayer.Id)); }// ClearPayOut(opponentPayOut, mePayOut); } Notify?.Invoke(WebscoketSendObjs.FreshGameFace(playerId)); return; } return; }
public void PlayerPlayOutOnePoker(int playerId) { Seat meSeat = GetSeatByPlayerId(playerId); int opponentId = GetOpponentId(playerId); Seat opponentSeat = GetSeatByPlayerId(opponentId); var opponentPayOut = opponentSeat.PlayOutPokers; var opponentCompareResult = opponentSeat.CompareResult; ABCard card = null; if (null == meSeat.GetPoker) { return; } card = meSeat.GetPoker; var meCompareResult = meSeat.CompareResult; ISeat winPlayer = null; if (card != null) { lock (Locker) { meSeat.GetPoker = null; meSeat.PlayOutPokers = card; if (opponentPayOut != null) { if (meSeat.PlayOutPokers.ComparedValue > opponentSeat.PlayOutPokers.ComparedValue) { winPlayer = meSeat; } else { winPlayer = opponentSeat; } meSeat.PlayOutPokers = null; meSeat.CompareResult = card; opponentSeat.CompareResult = opponentSeat.PlayOutPokers; opponentSeat.PlayOutPokers = null; winPlayer.IPlayer.DecutMoney(-ChipInAmount); foreach (var item in InningeGame.NotEmptySeats())//通知全部客户端刷新 { NotifySinglePlayer(WebscoketSendObjs.FreshGameFace(item.IPlayer.Id), item.IPlayer.Id); } } NotifySinglePlayer(WebscoketSendObjs.FreshGameFace(playerId), playerId); return; } } return; }
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, "新一局开始!开始押底!")); }
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); }
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, "游戏开始了!请开始押底!")); }
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, "人数不足,不能开始")); } }
/// <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);//触发游戏结束事件 }
public override void GameOver(object inningeGame, EventArgs e) { CheckDateTime = DateTime.Now; NotifyRoomPlayers(WebscoketSendObjs.RoomMessage(0, "本局结束!等待庄家开启新的一局")); }
public override void ResetGame(object inningeGame, EventArgs e) { NotifyRoomPlayers(new FreshGameFace(0)); NotifyRoomPlayers(WebscoketSendObjs.RoomMessage(0, "新一局开始!开始押底!")); }
/// 重启游戏 /// </summary> /// <param name="inningeGame"></param> /// <param name="e"></param> public override void ResetGame(object inningeGame, EventArgs e) { NotifyRoomPlayers(WebscoketSendObjs.ResetGame(0)); }
/// <summary> /// 游戏正常结束 /// </summary> /// <param name="inningeGame">本局游戏</param> /// <param name="e"></param> public override void GameOver(object inningeGame, EventArgs e) { NotifyRoomPlayers(WebscoketSendObjs.GameOver(0)); }
/// <summary> /// 重置游戏后事件 /// </summary> /// <param name="inningeGame"></param> /// <param name="e"></param> public override void ResetGame(object inningeGame, EventArgs e) { Notify?.Invoke(WebscoketSendObjs.ResetGame(0)); }
/// <summary> /// 游戏正常结束 /// </summary> /// <param name="inningeGame">本局游戏</param> /// <param name="e"></param> public override void GameOver(object inningeGame, EventArgs e) { Notify?.Invoke(WebscoketSendObjs.GameOver(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); }