Skip to content

Commit

Permalink
Add player name to leader board
Browse files Browse the repository at this point in the history
  • Loading branch information
beverly-hills-money-gangster committed Feb 21, 2024
1 parent f205aec commit 819a60c
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 14 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions schema/src/main/resources/server-response.proto
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ message ServerResponse {
message LeaderBoardItem {
optional int32 playerId = 1;
optional int32 kills = 2;
optional string playerName = 3;
}

message GameEventPlayerStats {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ static ServerResponse.LeaderBoard createLeaderBoard(List<GameLeaderBoardItem> le
leaderBoard.forEach(leaderBoardItem
-> leaderBoardResponse.addItems(ServerResponse.LeaderBoardItem.newBuilder()
.setPlayerId(leaderBoardItem.getPlayerId())
.setPlayerName(leaderBoardItem.getName())
.setKills(leaderBoardItem.getKills())
.build()));
return leaderBoardResponse.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public PlayerShootingGameState shoot(final PlayerState.PlayerCoordinates shootin
final Integer shotPlayerId) throws GameLogicError {
validateGameNotClosed();
PlayerState shootingPlayerState = getPlayer(shootingPlayerId).orElse(null);
List<GameLeaderBoardItem> leaderBoard = new ArrayList<>();
if (shootingPlayerState == null) {
LOG.warn("Non-existing player can't shoot");
return null;
Expand Down Expand Up @@ -94,7 +93,6 @@ public PlayerShootingGameState shoot(final PlayerState.PlayerCoordinates shootin
shotPlayer.getShot();
if (shotPlayer.isDead()) {
shootingPlayerState.registerKill();
leaderBoard.addAll(getLeaderBoard());
}
return shotPlayer;
}).orElse(null);
Expand All @@ -116,6 +114,7 @@ private List<GameLeaderBoardItem> getLeaderBoard() {
player1.getPlayerState().getKills(), player2.getPlayerState().getKills()))
.map(playerStateChannel -> GameLeaderBoardItem.builder()
.playerId(playerStateChannel.getPlayerState().getPlayerId())
.name(playerStateChannel.getPlayerState().getPlayerName())
.kills(playerStateChannel.getPlayerState().getKills())
.build())
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ public class GameLeaderBoardItem {

private final int playerId;

private final String name;

private final int kills;
}
Loading

0 comments on commit 819a60c

Please sign in to comment.