/// <summary> /// ゲーム開始 /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task GameStartAsync(GameStartRequest request) { IsStarted = true; if (WithOther) { // 2P logger.LogInformation($"GameStart at {MineId}"); var param = new Dictionary <string, IReadOnlyList <short> >(); // 2P / 互いの情報取得 var mineLoop = ServerMainGameLoop.TryTakeGame(MineId); var enemLoop = ServerMainGameLoop.TryTakeGame(EnemyId); param[MineId] = mineLoop.PlayingState.Board; param[EnemyId] = enemLoop.PlayingState.Board; BroadcastToSelf(gameRoom).OnGameStart(new GameStartResponse { RoomName = request.RoomName, PlayerBoards = param }); } else { // 1人の場合は速攻で始める logger.LogInformation($"GameStart at {MineId}"); var loop = ServerMainGameLoop.TryTakeGame(MineId); var param = new Dictionary <string, IReadOnlyList <short> >(); param[MineId] = loop.PlayingState.Board; BroadcastToSelf(gameRoom).OnGameStart(new GameStartResponse { RoomName = request.RoomName, PlayerBoards = param }); } await Task.Yield(); }
/// <summary> /// >マッチング時に与えられたルーム名をもとにゲーム準備を宣言 /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task GameReadyAsync(GameReadyRequest request) { IsConnected = true; MineId = request.MineId; EnemyId = request.EnemyId; WithOther = request.WithOther; // ゲームループ作成 ServerMainGameLoop.LoopData data = new ServerMainGameLoop.LoopData(MineId, EnemyId, this, NetworkInput); ServerMainGameLoop.CreateNew(looperPool, logger, data); // ゲーム部屋に放り込む gameRoom = await Group.AddAsync(request.RoomName); if (WithOther) { // 2P var memberNum = await gameRoom.GetMemberCountAsync(); if (memberNum == 2) { // 2人揃ったらゲームを開始してよい logger.LogInformation($"GameReady at {MineId}"); var param = new Dictionary <string, IReadOnlyList <short> >(); // 互いの情報取得 var mineLoop = ServerMainGameLoop.TryTakeGame(MineId); var enemLoop = ServerMainGameLoop.TryTakeGame(EnemyId); param[MineId] = mineLoop.PlayingState.Board; param[EnemyId] = enemLoop.PlayingState.Board; var res = new GameReadyResponse { RoomName = request.RoomName, PlayerBoards = param }; Broadcast(gameRoom).OnGameReady(res); } } else { // 1P / 速攻でスタート logger.LogInformation($"GameReady at {MineId}"); var loop = ServerMainGameLoop.TryTakeGame(request.MineId); var param = new Dictionary <string, IReadOnlyList <short> >(); param[MineId] = loop.PlayingState.Board; BroadcastToSelf(gameRoom).OnGameReady(new GameReadyResponse { RoomName = request.RoomName, PlayerBoards = param }); } }