Skip to content

Commit

Permalink
Modify Game.razor
Browse files Browse the repository at this point in the history
  • Loading branch information
oneheed committed Oct 3, 2023
1 parent 243f83e commit 0a3d6bb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 36 deletions.
77 changes: 44 additions & 33 deletions src/InterfaceAdapter/Gaas.GobbletGobblers.Client/Pages/Game.razor
Original file line number Diff line number Diff line change
Expand Up @@ -246,55 +246,66 @@
StateHasChanged();
});

hubConnection.On<GameViewModel>("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<GameInfoRequest, GameViewModel>("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<GameViewModel>("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) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ public async Task<dynamic> 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}" };
}
Expand Down

0 comments on commit 0a3d6bb

Please sign in to comment.