コード例 #1
0
        public async Task SetBoard(int sessionId, int[][] board)
        {
            var loggedPlayer      = GetLoggedPlayer();
            var battleshipSession = _battleshipSessionService.FindById(sessionId, loggedPlayer.GetAsPlayer());

            switch (battleshipSession.SetBoard(loggedPlayer, board))
            {
            case BoardStatus.BoardOK:
                battleshipSession.SetPlayerReady(loggedPlayer);
                if (battleshipSession.ReadyToStart())
                {
                    var groupName = MapSessionIdToGroupName(sessionId);
                    await Clients.Group(groupName).InvokeAsync("playersReady", battleshipSession.GetGameUrl());
                }
                else
                {
                    await Clients.Client(Context.ConnectionId).InvokeAsync("waitForOpponent");
                }
                break;

            case BoardStatus.TooManyShips:
                await Clients.Client(Context.ConnectionId).InvokeAsync("tooManyShips", true);

                break;

            case BoardStatus.TooFewShips:
                await Clients.Client(Context.ConnectionId).InvokeAsync("tooManyShips", false);

                break;

            case BoardStatus.ErrorsInPlacement:
                await Clients.Client(Context.ConnectionId).InvokeAsync("errorsInShipPlacement");

                break;

            case BoardStatus.WrongValues:
                await Clients.Client(Context.ConnectionId).InvokeAsync("badInput");

                break;
            }
        }
        public IActionResult JoinGame(int lobbyId)
        {
            var battleshipSession = _sessionService.FindById(lobbyId, new Player(User));

            return(View("StartGame", battleshipSession));
        }