public IActionResult CreateRoom(IFormCollection createRoom) { if (session.Keys.Contains("RoomId")) { throw new Exception("已经在一个房间里,不能再建"); } if (!decimal.TryParse(createRoom["TicketPrice"].ToString(), out decimal ticketPrice_)) { ticketPrice_ = 0; } string gameName_ = createRoom["gameProject"].ToString(); IGameProject gameProject_ = LoadGameProject(gameName_); IInningeGame inningeGame_ = new InningeGame(gameProject_); if (!int.TryParse(createRoom["PlayerCountTopLimit"].ToString(), out int limitCount_)) { limitCount_ = 1; } IRoomConfig roomConfig_ = new RoomConfig(inningeGame_) { Affiche = createRoom["Affiche"], Name = createRoom["Name"], PlayerCountTopLimit = limitCount_, SecretKey = createRoom["SecretKey"], TicketPrice = ticketPrice_ }; IRoom room_ = new Room(player, roomConfig_); BoundingEventOfRoom(room_); var gameCityId = createRoom["gameCityId"]; WriteToSeeion(gameCityId, room_); return(RedirectToAction("RoomsList")); }
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; } }
/// <summary> /// 房间加载游戏 /// </summary> /// <param name="gameName_">游戏名称</param> /// <returns></returns> protected IGameProject LoadGameProject(string gameName_) { Assembly assembly = Assembly.Load(new AssemblyName(gameName_)); IGameProject gameProject_ = (IGameProject)assembly.CreateInstance("AntDesigner.NetCore.Games." + gameName_ + "." + gameName_); gameProject_.Notify = ClientWebsocketsManager.Send; gameProject_.NotifyByWebsockLink = ClientWebsocketsManager.SendToWebsocket; gameProject_.DChangePlayerAccount = PlayerService.AdjustAccountForDelegate; return(gameProject_); }
private void Mock_gameProject() { _gameProjectFactory = new Mock <IGameProject>(); _gameProject = _gameProjectFactory.Object; _gameProjectFactory.Setup(g => g.CheckAddSeat(It.IsNotNull <IInningeGame>())).Returns(true); _gameProjectFactory.SetupAllProperties(); _gameProject.PlayerCountLeast = 1; _gameProject.PlayerCountLimit = 10; }
public InningeGame(IGameProject gameProject_) : this() { IGameProject = gameProject_; DCheckAddSeat += IGameProject.CheckAddSeat; DCheckStart += IGameProject.CheckStart; GameStartHandler += IGameProject.GameStart; BeforAddSeatHandler += IGameProject.BeforAddSeat; AfterAddSeatHandler += IGameProject.AfterAddSeat; BeforGameStartHandler += IGameProject.BeforGameStart; StoptedHandler += IGameProject.Stoped; GameOverHander += IGameProject.GameOver; AfterResetHander += IGameProject.ResetGame; }
/// <summary> /// 更换游戏 /// </summary> /// <param name="game">游戏</param> public void ChangeGame(IGameProject game) { if (InningGame.IsStarted) { throw new Exception("游戏已经开始了,不能更换"); } if (!(game.PlayerCountLeast <= PlayerCountTopLimit && PlayerCountTopLimit <= game.PlayerCountLimit)) { PlayerCountTopLimit = game.PlayerCountLimit; } InningGame.IGameProject = game; }
public virtual IActionResult WebSocketHandler(string askMethodName, Dictionary <string, string> methodParam) { if (_inngeGame != null && _inngeGame.IsStarted != true) { ClientWebsocketsManager.Send(new Alert(player.Id, "游戏还未启动!请房主先启动游戏")); return(null); } methodParam.Remove("askMethodName"); methodParam.Add("playerId", player.Id.ToString()); IGameProject gameProject = _room.InningGame.IGameProject; string respondStr = gameProject.ClinetHandler(askMethodName, methodParam); return(Content(respondStr)); }
/// <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 IActionResult CreateRoom(IFormCollection createRoom) { if (session.Keys.Contains("RoomId")) { ViewBag.result = ""; return(View("Index_CreateRoom")); // throw new Exception("已经在一个房间里,不能再建"); } if (!decimal.TryParse(createRoom["TicketPrice"].ToString(), out decimal ticketPrice_)) { ticketPrice_ = 0; } if (ticketPrice_ > 0) { if (player.AccountNotEnough(ticketPrice_ * TOOMTICKETPRICEMULTIPLE)) { return(RedirectToRoute("default", new { controller = "Player", action = "Index_recharge" })); } } string gameName_ = createRoom["gameProject"].ToString(); IGameProject gameProject_ = LoadGameProject(gameName_); IInningeGame inningeGame_ = new InningeGame(gameProject_) { DCreatSeat = gameProject_.CreatSeat }; gameProject_.InningeGame = inningeGame_; if (!int.TryParse(createRoom["PlayerCountTopLimit"].ToString(), out int limitCount_)) { limitCount_ = 1; } if (ticketPrice_ > TOPTICKETPRICE) { ticketPrice_ = TOPTICKETPRICE; } if (ticketPrice_ < 0) { ticketPrice_ = 0; } var affiche = createRoom["Affiche"].ToString(); if (affiche.Length >= 150) { affiche = affiche.Substring(0, 150); } var name = createRoom["Name"].ToString(); if (name.Length >= 6) { name.Substring(0, 6); } IRoomConfig roomConfig_ = new RoomConfig(inningeGame_) { Affiche = affiche, Name = name, PlayerCountTopLimit = limitCount_, SecretKey = createRoom["SecretKey"], TicketPrice = ticketPrice_ }; player.DecutMoney(ticketPrice_ * TOOMTICKETPRICEMULTIPLE, "开房"); IRoom room_ = new Room(player, roomConfig_); BoundingEventOfRoom(room_); var gameCityId = createRoom["gameCityId"]; WriteToSeeion(gameCityId, room_); if (inningeGame_.IGameProject.PlayerCountLimit == 1) { return(RedirectToAction("JoinRoom")); } return(RedirectToAction("RoomsList")); }