/// <summary> /// 创建一局游戏 /// </summary> /// <param name="firstPlayerCode">先手玩家</param> /// <param name="secondPlayerCode">后手玩家</param> /// <param name="fristCardGroupCode">先手玩家卡组</param> /// <param name="secondCardGroupCode">后手玩家卡组</param> /// <returns>游戏ID</returns> public APIResultBase CreateGame(string tableCode, PlayerModel firstUser, PlayerModel secondUser, List <UserCardGroupDetailModel> firstCardGroup, List <UserCardGroupDetailModel> secondCardGroup, GameModel game, string firstUserProfession, string secondUserProfession) { //if (firstPlayerCode.IsNullOrEmpty() || secondPlayerCode.IsNullOrEmpty() || fristCardGroupCode.IsNullOrEmpty() || secondCardGroupCode.IsNullOrEmpty()) //{ // return JsonModelResult.PackageFail(OperateResCodeEnum.参数错误); //} //CUsers firstUser = UsersBll.Instance.GetUser(firstPlayerCode); if (firstUser == null) { return(JsonModelResult.PackageFail(OperateResCodeEnum.参数错误)); } //CUsers secondUser = UsersBll.Instance.GetUser(secondPlayerCode); if (secondUser == null) { return(JsonModelResult.PackageFail(OperateResCodeEnum.参数错误)); } //var lstCtl = ControllerCache.Lstctl; //if (lstCtl.Any(c => c.chessboard.Players.First(x => x.IsFirst).User.UserCode == firstPlayerCode || //c.chessboard.Players.First(x => x.IsFirst == false).User.UserCode == secondPlayerCode)) //{ // res = OperateJsonRes.Error(OperateResCodeEnum.无法多开游戏); // return res; //} //List<HS_UserCardGroupDetail> firstCardGroup = UserCardGroupDetailBll.Instance.GetCardGroupDetail(fristCardGroupCode, firstPlayerCode); if (firstCardGroup == null || firstCardGroup.Count < 1) { return(JsonModelResult.PackageFail(OperateResCodeEnum.参数错误)); } //List<HS_UserCardGroupDetail> secondCardGroup = UserCardGroupDetailBll.Instance.GetCardGroupDetail(secondCardGroupCode, secondPlayerCode); if (secondCardGroup == null || secondCardGroup.Count < 1) { return(JsonModelResult.PackageFail(OperateResCodeEnum.参数错误)); } //GameContextCache.Init(); //var game = GameBll.Instance.CreateGame(tableCode, firstPlayerCode, secondPlayerCode, fristCardGroupCode, secondCardGroupCode); //string firstUserProfession = UserCardGroupBll.Instance.GetCardGroup(fristCardGroupCode, firstPlayerCode).Profession; //string secondUserProfession = UserCardGroupBll.Instance.GetCardGroup(secondCardGroupCode, secondPlayerCode).Profession; Controler_Base ctl = new Controler_Base(_gameCache); ctl.GameStart(game, firstUser, secondUser, firstCardGroup, secondCardGroup, firstUserProfession, secondUserProfession); return(JsonModelResult.PackageSuccess(_gameCache.GetContext(ctl.GameContext.GameCode).Output())); }
public void InitGameContext(UserContext first, UserContext second, BaseHero firstHero, BaseHero secondHero) { gameContext = new GameContext() { GameCode = "GameCode", CurrentTurnCode = "CurrentTurnCode", NextTurnCode = "NextTurnCode", Players = new List <UserContext> { first, second }, GameStatus = GameStatus.进行中, TurnIndex = 10, }; gameContext.DeskCards = new DeskBoard() { firstHero, null, null, null, null, null, null, null, secondHero, null, null, null, null, null, null, null }; IGameCache gameCache = Substitute.For <IGameCache>(); gameCache.GetAllCard().Returns(CardsUtil.AllCard); gameCache.GetContext(Arg.Any <string>()).Returns(gameContext); gameContext.GameCache = gameCache; proxy = new Controller_Base_Proxy(gameCache); }