/// <summary> /// 新房间 /// </summary> /// <param name="roomManager_">房主</param> /// <param name="config_">房间配置</param> public Room(IPlayerJoinRoom roomManager_, IRoomConfig config_) : this() { Id = Id + roomManager_.Id; Name = config_.Name; IsFull = config_.IsFull; Timelimit = config_.Timelimit; IsOpening = config_.IsOpening; SecretKey = config_.SecretKey; TicketPrice = config_.TicketPrice; InningGame = config_.InningGame; InningGame.IRoom = this; if (InningGame.IGameProject.PlayerCountLeast <= config_.PlayerCountTopLimit && config_.PlayerCountTopLimit <= InningGame.IGameProject.PlayerCountLimit) { PlayerCountTopLimit = config_.PlayerCountTopLimit; } else { PlayerCountTopLimit = InningGame.IGameProject.PlayerCountLimit; } if (PlayerCountTopLimit == 1) { IsFull = true; } RoomManager = roomManager_; Affiche = config_.Affiche; IsRandom = config_.IsRandom; Players.Add(roomManager_); InningGame.PlaySitDown(roomManager_); }
public Room( DateTime timelimit_ , int playerCountTopLimit_ , IInningeGame inningGame_ , IPlayerJoinRoom roomManager_ , string name_ = "" , string affiche_ = "" , string secretKey_ = "" , decimal ticketPrice_ = 0 , bool isRandom_ = true) : this() { TicketPrice = ticketPrice_; IsFull = false; IsOpening = true; // Players = new List<IPlayerJoinRoom>(); InningGame = inningGame_; RoomManager = roomManager_; Players.Add(roomManager_); if (inningGame_.IGameProject.PlayerCountLeast <= playerCountTopLimit_ && playerCountTopLimit_ <= inningGame_.IGameProject.PlayerCountLimit) { PlayerCountTopLimit = playerCountTopLimit_; } else { PlayerCountTopLimit = inningGame_.IGameProject.PlayerCountLimit; } }
public override void BeforPlayerLeave(object inningeGame, EventArgs e) { IPlayerJoinRoom player = ((PlayerEventArgs)e).Player; Seat seat = (Seat)InningeGame.GetSeatByPlayerId(player.Id); ChageRole(seat); RemoveFromJoinSeats(seat); base.BeforPlayerLeave(inningeGame, e); }
private void MyPlayerSitDown(IPlayerJoinRoom player_) { if (IsEmpty == true || IPlayer == null) { IPlayer = player_; IsEmpty = false; return; } }
/// <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); return(false); }
private void Mock_Player() { Mock <IPlayerJoinRoom> _IPlayerJoinRoomFactory = new Mock <IPlayerJoinRoom>(); _IPlayerJoinRoomFactory.SetupAllProperties(); _player = _IPlayerJoinRoomFactory.Object; _player.Id = 1; _player2 = new Mock <IPlayerJoinRoom>().SetupAllProperties().Object; _player2.Id = 2; }
/// <summary> /// 玩家坐下 /// </summary> /// <param name="player_">玩家</param> /// <returns></returns> public bool PlayerSitDown(IPlayerJoinRoom player_) { if (CheckSitDown(IIningeGame)) { BeforSitDownHandler?.Invoke(IIningeGame, new EventArgs()); MyPlayerSitDown(player_); AfterSitDownHandler?.Invoke(IIningeGame, new EventArgs()); return(true); } return(false); }
/// <summary> /// 添加座位坐下 /// </summary> /// <param name="player">玩家</param> /// <returns>座位</returns> public ISeat PlaySitDown(IPlayerJoinRoom player) { ISeat seat = GetOneEmptySeat(); if (seat == null) { seat = AddSet(1); } seat.PlayerSitDown(player); return(seat); }
public GameCityTest() { _mock = new MockRepository(MockBehavior.Default); _playerFactory = _mock.Create <IPlayerJoinRoom>(); _roomFactory = _mock.Create <Room>(); _cityManager = _mock.Create <ICityManager>().Object; _gameCity_ticket_0 = new GameCity("拉斯维加斯", _cityManager); _gameCity_ticket_5 = new GameCity("拉斯维加斯", _cityManager, ticketPrice_: 5); _player = _mock.Create <IPlayerJoinRoom>().Object; _inningGame = _mock.Create <IInningeGame>().Object; _roomConfig = new RoomConfig(_inningGame); _room = new Room(DateTime.Now.AddHours(1), 10, _inningGame, _player, ticketPrice_: 50); }
public RoomTest() { Mock <IPlayerJoinRoom> IPlayerFactory1 = new Mock <IPlayerJoinRoom>(); IPlayerFactory1.SetupAllProperties(); player1 = IPlayerFactory1.Object; player1.Id = 1; Mock <IPlayerJoinRoom> IPlayerFactory2 = new Mock <IPlayerJoinRoom>(); IPlayerFactory2.SetupAllProperties(); player2 = IPlayerFactory2.Object; player2.Id = 2; Mock <IInningeGame> IInningGameFactory = new Mock <IInningeGame>(); _room = new Room(DateTime.Now.AddHours(1), 10, IInningGameFactory.Object, IPlayerFactory1.Object); }
/// <summary> /// 玩家加入 /// </summary> /// <param name="player_">玩家</param> public bool AddPlayer(IPlayerJoinRoom player_) { if (Players.Exists(p => p.Id == player_.Id)) { return(true); } if (Players.Count >= PlayerCountTopLimit) { AddPlayerFailRoomFullEvent?.Invoke(player_, new PlayerEventArgs(player_)); return(false); } if (player_.Id != RoomManager.Id && TicketPrice > 0 && player_.Account < TicketPrice) { PlayCanNotPayTicketEvent?.Invoke(player_, new PlayerEventArgs(player_)); return(false); } if (player_.Id != RoomManager.Id) { if (!player_.DecutMoney(TicketPrice)) { return(false); } } if (!Players.Exists(p => p.Id == player_.Id)) { Players.Add(player_); try { InningGame.PlaySitDown(player_); } catch (Exception) { throw; } finally { CheckFull(); //AddPlayerSuccessEvent?.Invoke(this, new PlayerEventArgs(player_)); AddPlayer_SuccessEvent?.Invoke(this, new PlayerEventArgs(player_)); } } return(true); }
/// <summary> /// 玩家离开房间 /// </summary> /// <param name="player_">玩家</param> public void RemovePlayer(IPlayerJoinRoom player_) { ISeat seat = InningGame.GetSeatByPlayerId(player_.Id); if (seat != null) { seat.PlayLeave(); } var realPlayer = Players.Find(p => p.Id == player_.Id); Players.Remove(realPlayer); if (player_.Id == RoomManager.Id && Players.Count > 0) { ChanageManger(Players[0]); } RemovePlayer_SuccessEvent?.Invoke(this, new PlayerEventArgs(player_)); CheckFull(); InningGame.CheckSeatCountEnoughWhenRunning(); }
public SimpleCardsTest() { Mock <IPlayerJoinRoom> playerFactoryA = new Mock <IPlayerJoinRoom>(); playerFactoryA.SetupAllProperties(); playerFactoryA.Setup(p => p.AccountNotEnough(It.IsAny <decimal>())).Returns(false); _playerA = playerFactoryA.Object; Mock <IPlayerJoinRoom> playerFactoryB = new Mock <IPlayerJoinRoom>(); playerFactoryB.SetupAllProperties(); _playerB = playerFactoryB.Object; _playerA.Id = 1; _playerB.Id = 2; _simpleCards = new GameSimpleCards(); _inningeGame = new InningeGame(_simpleCards); _inningeGame.AddSet(2); _inningeGame.GetOneEmptySeat().PlayerSitDown(_playerA); _inningeGame.GetOneEmptySeat().PlayerSitDown(_playerB); }
/// <summary> /// 检查玩家session保存的房间Id等,初始化房间信息 /// </summary> private void LoadRoomInfo() { string gameCityId_; string roomId_; #region session中保存有房间信息就读取,没有就从Request.Query中读取 if (session.Keys.Contains("RoomId") && session.Keys.Contains("CityId")) { gameCityId_ = session.GetString("CityId"); roomId_ = session.GetString("RoomId"); } else { gameCityId_ = httpContextAccessor.HttpContext.Request.Query["gameCityId"]; roomId_ = httpContextAccessor.HttpContext.Request.Query["roomId"]; } #endregion #region sesson或Request.Query中有房间信息就使用 if (gameCityId_ != null && gameCityId_.Length > 0) { _gameCity = CityGameController.GameCityList.FindGameCityById(gameCityId_); } if (roomId_ != null && roomId_.Length > 0) { _room = _gameCity.FindRoomById(roomId_); if (_room == null) { throw new RoomIsNotExistException(player.Id, "房间已经不存在了"); } _inngeGame = _room.InningGame; _gameProject = _inngeGame.IGameProject; #endregion #region 保存玩家websocket对象 IPlayerJoinRoom roomPlayer = _room.Players.FirstOrDefault(p => p.Id == player.Id); if (null != roomPlayer) { roomPlayer.WebSocketLink = ClientWebsocketsManager.FindClientWebSocketByPlayerId(player.Id); } #endregion } }
public override void AfterPlayerLeave(object inningeGame, EventArgs e) { IPlayerJoinRoom player = ((PlayerEventArgs)e).Player; int playerId = player.Id; var notEmptySeatsCount = ((IInningeGame)inningeGame).NotEmptySeats().Count(); if (notEmptySeatsCount > 0) { if (CurrentStage == EStage.Running && JoinSeats.Count() == 1) { CompareAll(); NotifyRoomPlayersExcept(WebscoketSendObjs.RoomMessage(playerId, "有玩家要离开,人数不足,自动结算"), playerId); } 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; NotifyRoomPlayersExcept(WebscoketSendObjs.RoomMessage(playerId, "有玩家要离开,人数不足,退还你的押底"), playerId); } NotifyRoomPlayersExcept(WebscoketSendObjs.RoomMessage(playerId, "有玩家要离开,人数不足,取消押底"), playerId); } base.AfterPlayerLeave(inningeGame, e); // NotifyRoomPlayers(new FreshGameFace(0)); NotifyRoomPlayersExcept(new FreshGameFace(playerId), playerId); } }
public PlayerEventArgs(IPlayerJoinRoom player) { Player = player; }
/// <summary> /// 房间易主 /// </summary> /// <param name="player">新主人</param> public void ChanageManger(IPlayerJoinRoom player_) { RoomManager = player_; ManagerChangedHandler?.Invoke(player_, new PlayerEventArgs(player_)); }