diff --git a/src/InterfaceAdapter/Gaas.GobbletGobblers.Client/Pages/Game.razor b/src/InterfaceAdapter/Gaas.GobbletGobblers.Client/Pages/Game.razor index 64d243b..2e1c5d3 100644 --- a/src/InterfaceAdapter/Gaas.GobbletGobblers.Client/Pages/Game.razor +++ b/src/InterfaceAdapter/Gaas.GobbletGobblers.Client/Pages/Game.razor @@ -246,55 +246,66 @@ StateHasChanged(); }); - hubConnection.On("GameInfo", async (gameModel) => + var request = new GameInfoRequest { - if (gameModel != null) - { - if (board == null) - { - boardSize = gameModel.BoardSize; - board = gameModel.Board; - } + Id = Guid.Parse(this.GameId), + }; - var playerModel = gameModel.Players.FirstOrDefault(p => p.Id == playerId); + var gameModel = await PostAsJsonAsync("Game/GameInfo", request); - playerViewModel = playerModel; + await GameModelAction(gameModel); - if (changeCockId.HasValue) - { - var cock = playerViewModel.Cocks.ElementAtOrDefault(changeCockId.Value); - if (cock != null) - { - cock.IsClick = true; - } - } + hubConnection.On("GameInfo", GameModelAction); - board = gameModel.Board; - winnerId = gameModel.WinnerId; - } + await hubConnection.StartAsync(); - if (!moveClick.Any()) + if (!string.IsNullOrEmpty(GameId)) + { + await hubConnection.SendAsync("JoinRoom", GameId.ToString(), name); + } + } + + public async Task GameModelAction(GameViewModel gameModel) + { + if (gameModel != null) + { + if (board == null) { - moveClick = Enumerable.Range(0, boardSize * boardSize).Select(x => { return false; }).ToList(); + boardSize = gameModel.BoardSize; + board = gameModel.Board; } - if (winnerId.HasValue) - { - //Console.WriteLine(winnerId.ToString()); - winnerName = gameModel.Players.FirstOrDefault(p => p.Id == winnerId).Name; + var playerModel = gameModel.Players.FirstOrDefault(p => p.Id == playerId); + + playerViewModel = playerModel; - await hubConnection.StopAsync(); + if (changeCockId.HasValue) + { + var cock = playerViewModel.Cocks.ElementAtOrDefault(changeCockId.Value); + if (cock != null) + { + cock.IsClick = true; + } } - await InvokeAsync(StateHasChanged); - }); + board = gameModel.Board; + winnerId = gameModel.WinnerId; + } - await hubConnection.StartAsync(); + if (!moveClick.Any()) + { + moveClick = Enumerable.Range(0, boardSize * boardSize).Select(x => { return false; }).ToList(); + } - if (!string.IsNullOrEmpty(GameId)) + if (winnerId.HasValue) { - await hubConnection.SendAsync("JoinRoom", GameId.ToString(), name); + //Console.WriteLine(winnerId.ToString()); + winnerName = gameModel.Players.FirstOrDefault(p => p.Id == winnerId).Name; + + await hubConnection.StopAsync(); } + + await InvokeAsync(StateHasChanged); } public bool IsConnected => !string.IsNullOrEmpty(name) && diff --git a/src/InterfaceAdapter/Gaas.GobbletGobblers.Core.WebApi/Controllers/GameController.cs b/src/InterfaceAdapter/Gaas.GobbletGobblers.Core.WebApi/Controllers/GameController.cs index bef9f97..1ab17f6 100644 --- a/src/InterfaceAdapter/Gaas.GobbletGobblers.Core.WebApi/Controllers/GameController.cs +++ b/src/InterfaceAdapter/Gaas.GobbletGobblers.Core.WebApi/Controllers/GameController.cs @@ -50,9 +50,7 @@ public async Task GamesAsync(GameRequest request) PlayerName = request.Players[1].Nickname }; - var game = await new JoinGameUseCase().ExecuteAsync(joinGameRequest, _repository); - - SendGameInfo(game.Id.ToString(), game); + _ = await new JoinGameUseCase().ExecuteAsync(joinGameRequest, _repository); return new { url = $"https://oneheed.github.io/Gobblet-Gobblers/games/{createGameResponse.Id}" }; }