コード例 #1
0
ファイル: Game.cs プロジェクト: ruidxr/ai-edu
        /// <summary>
        /// 创建一个新的游戏房间,并在其中开启新游戏。
        /// </summary>
        /// <param name="mode"></param>
        /// <param name="userId">可选。要继承的玩家ID。</param>
        /// <returns>创建游戏的操作结果。</returns>
        public static async Task <GameOperation <CreateGameResult> > StartInNewRoomAsync(RoomNumberMode mode, string userId = null)
        {
            if (!SupportedNumberModes.ContainsKey(mode))
            {
                throw new ArgumentOutOfRangeException(nameof(mode));
            }

            // 先创建新房间,再在这个房间里,按正常流程启动游戏。
            var url       = string.Format(NewRoomEndpointTemplate, SupportedNumberModes[mode]);
            var newRoomOp = await OperationFromResponseAsync(s_httpClient.GetAsync(url), JsonConvert.DeserializeObject <NewRoom>);

            if (!newRoomOp.Succeeded)
            {
                return(GameOperation <CreateGameResult> .Fail(newRoomOp.ErrorMessage));
            }

            var newRoom = newRoomOp.OperationResult;

            return(await OpenRoomAsync(roomIdToStart : newRoom.RoomId, userId : userId));
        }
コード例 #2
0
 public Round(string rid, RoomNumberMode mode)
 {
     RoundId    = rid;
     NumberMode = mode;
 }