Esempio n. 1
0
 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;
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 游戏城自动生成房间
 /// </summary>
 /// <param name="inningGame_">游戏</param>
 /// <param name="playerCount_">房间人数上限</param>
 /// <param name="n">生成个数</param>
 public void AddAutoRoom(IInningeGame inningGame_, int playerCount_, int n)
 {
     for (int i = 0; i < n; i++)
     {
         Rooms.Add(RoomCreator(inningGame_, playerCount_));
     }
 }
Esempio n. 3
0
 /// <summary>
 /// 添加座位到游戏最低数
 /// </summary>
 /// <param name="innineGame_"></param>
 private void AddSeatToLeastCount(IInningeGame innineGame_)
 {
     if (innineGame_.SeatCount < PlayerCountLeast)
     {
         innineGame_.AddSet(PlayerCountLeast - innineGame_.SeatCount);
     }
 }
Esempio n. 4
0
        public CityGameController(IHttpContextAccessor httpContextAccessor_, IPlayerService playerService) : base(httpContextAccessor_, playerService)
        {
            string gameCityId_;
            string roomId_;

            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"];
            }


            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;
            }
        }
Esempio n. 5
0
 private bool CheckSitDown(IInningeGame inningeGame_)
 {
     if (DCheckSitDown != null)
     {
         return(DCheckSitDown(inningeGame_));
     }
     return(true);
 }
 public override bool CheckAddSeat(IInningeGame innineGame_)
 {
     if (innineGame_.SeatCount >= innineGame_.IGameProject.PlayerCountLimit)
     {
         return(false);
     }
     return(true);
 }
 /// <summary>
 /// 玩家能否坐下检查
 /// </summary>
 /// <param name="inningeGame">一局游戏</param>
 /// <returns>YN</returns>
 public override bool CheckSitDown(IInningeGame inningeGame)
 {
     if (inningeGame.IsStarted == false)
     {
         return(true);
     }
     return(false);
 }
Esempio n. 8
0
        public ISeat CreatSeat(IInningeGame inningeGame)
        {
            var seat = new Seat(inningeGame);

            seat.PayedCard       += Seat_PayedCard;
            seat.GetCardAction    = GetCardAction_Handler;
            seat.EjectionedToken += Seat_EjectionedToken;;
            return(seat);
        }
Esempio n. 9
0
        public void PlayerSitDown()
        {
            IInningeGame inningeGame = _IInningeGameCreator();

            inningeGame.AddSet(1);
            ISeat emptySeat = inningeGame.GetOneEmptySeat();

            Assert.NotNull(emptySeat);
        }
Esempio n. 10
0
 public Seat(IInningeGame inningeGame) : base(inningeGame)
 {
     PokersShow = new List <Card>();
     InitialPokerShow();
     PokerOtherCanSee = null;
     PreChipInAmount  = 0;
     IsChipIned       = false;
     IsLooked         = false;
     IsGaveUp         = false;
 }
Esempio n. 11
0
        public void StartGame_SeatIsZero_(int playerCount_, int seatCount_)
        {
            IInningeGame inningeGame = _IInningeGameCreator();

            inningeGame.IGameProject.PlayerCountLeast = playerCount_;

            inningeGame.AddSet(seatCount_);

            Assert.Throws <Exception>(() => inningeGame.Start());
        }
Esempio n. 12
0
 public Seat(IInningeGame inningeGame)
 {
     IsEmpty                      = true;
     IIningeGame                  = inningeGame;
     this.DCheckSitDown           = IIningeGame.IGameProject.CheckSitDown;
     this.BeforSitDownHandler     = IIningeGame.IGameProject.BeforSitDown;
     this.AfterSitDownHandler     = IIningeGame.IGameProject.AfterSitDown;
     this.BeforPlayerLeaveHandler = IIningeGame.IGameProject.BeforPlayerLeave;
     this.AfterPlayerLeaveHandler = IIningeGame.IGameProject.AfterPlayerLeave;
 }
Esempio n. 13
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)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 14
0
        public void AddSeat_NoEmptySeat(int playerCountLimit_, int seatCount_)
        {
            IInningeGame inningeGame = _IInningeGameCreator();

            inningeGame.IGameProject.PlayerCountLimit = playerCountLimit_;

            inningeGame.AddSet(seatCount_);
            int preSeatCount = inningeGame.SeatCount;

            Assert.Throws <Exception>(() => inningeGame.AddSet(1));
        }
Esempio n. 15
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);
        }
Esempio n. 16
0
        public void GetEmptySeats_n(int emptyCount_)
        {
            IInningeGame inningeGame = _IInningeGameCreator();

            inningeGame.IGameProject.PlayerCountLimit = emptyCount_;
            inningeGame.IGameProject.PlayerCountLeast = emptyCount_;

            inningeGame.AddSet(emptyCount_);
            List <ISeat> Seats = inningeGame.EmptySeats();

            Assert.True(Seats.Count == emptyCount_);
        }
Esempio n. 17
0
        /// <summary>
        /// 房间默认配置
        /// </summary>
        /// <param name="inningGame_"></param>

        public RoomConfig(IInningeGame inningGame_)
        {
            InningGame          = inningGame_;
            IsFull              = false;
            Timelimit           = DateTime.Now.AddHours(1);
            IsOpening           = true;
            SecretKey           = "";
            TicketPrice         = 0;
            PlayerCountTopLimit = 8;
            Affiche             = "";
            IsRandom            = true;
        }
Esempio n. 18
0
        public void Start_DCheckStart_yes()
        {
            var          canStart    = false;
            IInningeGame inningeGame = _IInningeGameCreator();

            inningeGame.DCheckStart += delegate { canStart = true; return(true); };
            inningeGame.AddSet(1);
            var gameHaveStarted = inningeGame.Start();

            Assert.True(gameHaveStarted);
            Assert.True(canStart);
        }
Esempio n. 19
0
 public Seat(IInningeGame inningeGame)
 {
     IsEmpty                      = true;
     GameDateStr                  = new Dictionary <string, List <string> >();
     GameDateObj                  = new Dictionary <string, List <object> >();
     IIningeGame                  = inningeGame;
     this.DCheckSitDown           = IIningeGame.IGameProject.CheckSitDown;
     this.BeforSitDownHandler     = IIningeGame.IGameProject.BeforSitDown;
     this.AfterSitDownHandler     = IIningeGame.IGameProject.AfterSitDown;
     this.BeforPlayerLeaveHandler = IIningeGame.IGameProject.BeforPlayerLeave;
     this.AfterPlayerLeaveHandler = IIningeGame.IGameProject.AfterPlayerLeave;
 }
Esempio n. 20
0
 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);
 }
Esempio n. 21
0
        public void StartGame_SeatEnough_(int playerCount_, int limitCount_, int seatCount_)
        {
            IInningeGame inningeGame = _IInningeGameCreator();

            inningeGame.IGameProject.PlayerCountLeast = playerCount_;
            inningeGame.IGameProject.PlayerCountLimit = limitCount_;

            inningeGame.AddSet(seatCount_);
            var gameHaveStarted = inningeGame.Start();

            Assert.True(inningeGame.IsStarted);
            Assert.True(gameHaveStarted);
        }
Esempio n. 22
0
        /// <summary>
        /// 添加座位检查
        /// </summary>
        /// <param name="innineGame_">本局游戏</param>
        /// <returns>YN</returns>
        public virtual bool CheckAddSeat(IInningeGame innineGame_)
        {
            if (innineGame_.IsStarted)
            {
                return(false);
            }
            if (innineGame_.SeatCount >= innineGame_.IGameProject.PlayerCountLimit)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 23
0
        public void AddSeat_DCheckAddRoom(int playerCountLimit_, int seatCount_)
        {
            IInningeGame inningeGame = _IInningeGameCreator();

            inningeGame.IGameProject.PlayerCountLimit = playerCountLimit_;

            bool DCheckAddRoom = false;

            inningeGame.DCheckAddSeat += delegate { DCheckAddRoom = true; return(true); };
            inningeGame.AddSet(seatCount_);
            int preSeatCount = inningeGame.SeatCount;

            Assert.True(DCheckAddRoom);
        }
Esempio n. 24
0
        public void Start_Event()
        {
            var          beforGameStartEvent = false;
            var          StartEvent          = false;
            IInningeGame inningeGame         = _IInningeGameCreator();

            inningeGame.BeforGameStartHandler += delegate { beforGameStartEvent = true; };
            inningeGame.GameStartHandler      += delegate { StartEvent = true; };

            inningeGame.AddSet(1);
            var gameHaveStarted = inningeGame.Start();

            Assert.True(beforGameStartEvent, "启动游戏前");
            Assert.True(StartEvent, "启动游戏事件");
        }
Esempio n. 25
0
        public void AddSeat_AddSeatEvent(int playerCountLimit_, int seatCount_)
        {
            IInningeGame inningeGame = _IInningeGameCreator();

            inningeGame.IGameProject.PlayerCountLimit = playerCountLimit_;

            bool beforAddSeatEvent = false;
            bool afterAddSeatEvent = false;

            inningeGame.BeforAddSeatHandler += delegate { beforAddSeatEvent = true; };
            inningeGame.AfterAddSeatHandler += delegate { afterAddSeatEvent = true; };
            inningeGame.AddSet(seatCount_);
            int preSeatCount = inningeGame.SeatCount;

            Assert.True(beforAddSeatEvent, "添加座位前");
            Assert.True(afterAddSeatEvent, "添加座位后");
        }
Esempio n. 26
0
        public void GetNotEmptySeats_n(int notEmptyCount_)
        {
            Mock <IPlayerJoinRoom> playerFactory = new Mock <IPlayerJoinRoom>();

            IInningeGame inningeGame = _IInningeGameCreator();

            inningeGame.IGameProject.PlayerCountLimit = notEmptyCount_;
            inningeGame.IGameProject.PlayerCountLeast = notEmptyCount_;

            inningeGame.AddSet(notEmptyCount_);

            List <ISeat> Seats = inningeGame.EmptySeats();

            while (inningeGame.GetOneEmptySeat() != null)
            {
                inningeGame.GetOneEmptySeat().PlayerSitDown(playerFactory.Object);
            }

            Assert.True(Seats.Count == notEmptyCount_);
        }
Esempio n. 27
0
        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);
        }
Esempio n. 28
0
        /// <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
            }
        }
Esempio n. 29
0
 /// <summary>
 /// 玩家能否坐下
 /// </summary>
 /// <param name="inningeGame">一局游戏</param>
 /// <returns></returns>
 public virtual bool CheckSitDown(IInningeGame inningeGame)
 {
     return(true);
 }
Esempio n. 30
0
 /// <summary>
 ///创建游戏项目的特性座位对象,继承自seat
 /// </summary>
 /// <param name="inningeGame"></param>
 /// <returns></returns>
 public ISeat CreatSeat(IInningeGame inningeGame)
 {
     return(new Seat(inningeGame));
 }