diff options
Diffstat (limited to 'src/ch/epfl/xblast/client/XBlastComponent.java')
-rw-r--r-- | src/ch/epfl/xblast/client/XBlastComponent.java | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/src/ch/epfl/xblast/client/XBlastComponent.java b/src/ch/epfl/xblast/client/XBlastComponent.java index fe5bf5a..0ef8c5c 100644 --- a/src/ch/epfl/xblast/client/XBlastComponent.java +++ b/src/ch/epfl/xblast/client/XBlastComponent.java | |||
@@ -107,27 +107,25 @@ public final class XBlastComponent extends JComponent { | |||
107 | drawString(g, e.getKey(), e.getValue().toString()); | 107 | drawString(g, e.getKey(), e.getValue().toString()); |
108 | } | 108 | } |
109 | 109 | ||
110 | } | 110 | /** |
111 | 111 | * Draws the players on the graphic context. | |
112 | private static Comparator<GameState.Player> buildPlayerComparator(PlayerID priorityPlayer) { | 112 | * |
113 | Comparator<GameState.Player> coordinateComparator = | 113 | * @param g the graphic context |
114 | (p1, p2) -> p1.position().compareTo(p2.position()); | 114 | * @param players the list of players to be displayed |
115 | 115 | */ | |
116 | Comparator<GameState.Player> idComparator = | 116 | private static void drawPlayers(Graphics2D g, List<GameState.Player> players) { |
117 | (p1, p2) -> p1.id() == priorityPlayer ? -1 : 0; | 117 | for (GameState.Player p : players) |
118 | drawImage(g, Grid.positionForPlayer(p), p.image()); | ||
119 | } | ||
118 | 120 | ||
119 | return coordinateComparator.thenComparing(idComparator); | ||
120 | } | 121 | } |
121 | 122 | ||
122 | /** | 123 | private static List<GameState.Player> sortPlayers(List<GameState.Player> players, PlayerID currentPlayerID) { |
123 | * Draws the players on the graphic context. | 124 | return Lists.sorted( |
124 | * | 125 | players, |
125 | * @param g the graphic context | 126 | GameState.Player |
126 | * @param players the list of players to be displayed | 127 | .POSITION_COMPARATOR |
127 | */ | 128 | .thenComparing(GameState.Player.idPushingComparator(currentPlayerID))); |
128 | private static void drawPlayers(Graphics2D g, List<GameState.Player> players) { | ||
129 | for (GameState.Player p : players) | ||
130 | Painter.drawImage(g, Grid.positionForPlayer(p), p.image()); | ||
131 | } | 129 | } |
132 | 130 | ||
133 | private GameState gameState; | 131 | private GameState gameState; |
@@ -172,7 +170,7 @@ public final class XBlastComponent extends JComponent { | |||
172 | Painter.drawImageMap(g, Lists.linearMap(Grid.SCORE_BG_POSITIONS, this.gameState.scores())); | 170 | Painter.drawImageMap(g, Lists.linearMap(Grid.SCORE_BG_POSITIONS, this.gameState.scores())); |
173 | Painter.drawImageMap(g, Lists.linearMap(Grid.TIME_LINE_POSITIONS, this.gameState.ticks())); | 171 | Painter.drawImageMap(g, Lists.linearMap(Grid.TIME_LINE_POSITIONS, this.gameState.ticks())); |
174 | Painter.drawStringMap(g, Lists.traverseMaps(Lists.invertMap(Grid.SCORE_TXT_POSITIONS), this.gameState.playerScores())); | 172 | Painter.drawStringMap(g, Lists.traverseMaps(Lists.invertMap(Grid.SCORE_TXT_POSITIONS), this.gameState.playerScores())); |
175 | drawPlayers(g, Lists.sorted(this.gameState.players(), buildPlayerComparator(this.playerID))); | 173 | Painter.drawPlayers(g, sortPlayers(this.gameState.players(), this.playerID)); |
176 | } | 174 | } |
177 | 175 | ||
178 | } | 176 | } |