Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
jberclaz committed Jul 6, 2024
1 parent 740c68c commit 1a0cf14
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/leflat/jass/client/CanvasCenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public class CanvasCenter extends JPanel {
private int mode; /* 0 : rien, 1 : tirer les équipes
* 2 : tirer les équipes et choisir une carte
* 3 : jouer */
private List<Integer> drawnCards = new ArrayList<>();
private Map<Integer, Card> shownCards = new HashMap<>();
private final List<Integer> drawnCards = new ArrayList<>();
private final Map<Integer, Card> shownCards = new HashMap<>();

public CanvasCenter() {
mode = MODE_PASSIVE;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/leflat/jass/client/CanvasLastPlie.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.List;

public class CanvasLastPlie extends JPanel {
private List<Card> lastPlie = new ArrayList<>();
private final List<Card> lastPlie = new ArrayList<>();
private int atout;
private int ourScore, theirScore;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/leflat/jass/client/CardImages.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private static String imagePath(int number) {
}

public static BufferedImage getImage(Card card) {
if (!card.isBack()) {
if (card.isFront()) {
return images[card.getNumber()];
}
return backImage;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/leflat/jass/client/ClientNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public ClientConnectionInfo connect(String host, int requestedGameId, String nam
return new ClientConnectionInfo(receivedGameId);
}
playerId = Integer.parseInt(receiveRawMessage());
var encodedName = URLEncoder.encode(name, StandardCharsets.UTF_8.toString());
var encodedName = URLEncoder.encode(name, StandardCharsets.UTF_8);
sendMessage(Collections.singletonList(encodedName));
return new ClientConnectionInfo(playerId, receivedGameId, ConnectionError.CONNECTION_SUCCESSFUL);
} catch (ServerDisconnectedException | UnsupportedEncodingException e) {
} catch (ServerDisconnectedException e) {
LOGGER.log(Level.WARNING, "Server disconnected during connection", e);
}
return new ClientConnectionInfo(ConnectionError.SERVER_UNREACHABLE);
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/leflat/jass/client/ModernGamePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@

import static java.lang.Math.*;

/**
* This class implements the central canvas on the player client, including the pad where cards are played,
* the players hands and the info area underneath the main player's cards. It also contains the logic for
* interactive cards selection.
*/
public class ModernGamePanel extends JPanel implements MouseMotionListener {

enum GameMode {
Expand Down Expand Up @@ -336,7 +341,7 @@ private Rectangle2D.Float getHandArea(Rectangle2D.Float renderingArea) {
return new Rectangle2D.Float(0, 0, 0, 0);
}
var hand = player.getHand();
if (hand.size() == 0) {
if (hand.isEmpty()) {
return new Rectangle2D.Float(0, 0, 0, 0);
}
var playerArea = getPlayerArea(renderingArea);
Expand All @@ -355,7 +360,7 @@ private Rectangle getCardArea(int number, Rectangle2D.Float area) {

float card_x_step = hand.size() < 2 ? 0 : (handArea.width - cardDimension.width) / (float) (hand.size() - 1);
return new Rectangle(round(handArea.x + number * card_x_step), round(handArea.y),
round(cardDimension.width), round(cardDimension.height));
cardDimension.width, cardDimension.height);
}

private Rectangle2D.Float getTeamDrawingArea(Rectangle2D.Float renderingArea) {
Expand Down Expand Up @@ -748,7 +753,7 @@ protected void paintComponent(Graphics g) {
var ia = toInt(getInfoArea(renderingArea));
var ha = toInt(getHandArea(renderingArea));
var da = toInt(getTeamDrawingArea(renderingArea));
if (players.containsKey(PlayerPosition.MYSELF) && players.get(PlayerPosition.MYSELF).getHand().size() > 0) {
if (players.containsKey(PlayerPosition.MYSELF) && !players.get(PlayerPosition.MYSELF).getHand().isEmpty()) {
var cca = getCardArea(0, renderingArea);
g2.drawRect(cca.x, cca.y, cca.width, cca.height);
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/leflat/jass/client/ModernStatusPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import javax.swing.border.BevelBorder;
import java.awt.*;

/**
* This class contains the information text box at the bottom of the UI.
*/
public class ModernStatusPanel extends JPanel {
private String text = "";

Expand Down
7 changes: 1 addition & 6 deletions src/main/java/com/leflat/jass/client/RemoteController.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,7 @@ private void handleControllerMessage(String[] message) {
switch (command) {
case RemoteCommand.SET_PLAYER_INFO:
int playerId = Integer.parseInt(message[1]);
String name = null;
try {
name = URLDecoder.decode(message[2], StandardCharsets.UTF_8.toString());
} catch (UnsupportedEncodingException e) {
LOGGER.log(Level.SEVERE, "Unable to decode name", e);
}
String name = URLDecoder.decode(message[2], StandardCharsets.UTF_8);
player.setPlayerInfo(new ClientPlayer(playerId, name));
break;
case RemoteCommand.CHOOSE_TEAM_SELECTION_METHOD:
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/leflat/jass/client/SwissCardImages.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private static String imagePath(int number) {
}

public static BufferedImage getImage(Card card) {
if (!card.isBack()) {
if (card.isFront()) {
return images[card.getNumber()];
}
return backImage;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/leflat/jass/common/Announcement.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public Announcement(int type, Card card) {
this.card = card;
}

private int type; // 0: stöck, 1: 3 cartes, 2: cinquante, 3: cent, 4: carré
private Card card; // plus haute carte de l'annonce
private final int type; // 0: stöck, 1: 3 cartes, 2: cinquante, 3: cent, 4: carré
private final Card card; // plus haute carte de l'annonce

public int getType() {
return type;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/leflat/jass/common/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public int getValue() {
return getColor() == Card.atout ? VALUES_ATOUT[getRank()] : VALUES[getRank()];
}

public boolean isBack() {
return number == BACK_NUMBER;
public boolean isFront() {
return number != BACK_NUMBER;
}

public static Card getBack() {
Expand Down

0 comments on commit 1a0cf14

Please sign in to comment.