Skip to content

Commit

Permalink
refactor: reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
LapisBerry committed May 27, 2024
1 parent 9d90cd3 commit b903ad6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 30 deletions.
36 changes: 17 additions & 19 deletions src/main/java/com/lapisberry/gui/scenes/LobbyScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,6 @@ private static class RoleBox extends VBox {
private static final RoleText rebelCounter = new RoleText("Rebel: 0");
private static final RoleText spyCounter = new RoleText("Spy: 0");

private static void updateCounter(int emperor, int royalist, int rebel, int spy) {
Platform.runLater(() -> {
emperorCounter.setText("Emperor: " + emperor);
royalistCounter.setText("Royalist: " + royalist);
rebelCounter.setText("Rebel: " + rebel);
spyCounter.setText("Spy: " + spy);
});
}

private RoleBox() {
super();
getChildren().addAll(new SubTitle("Roles"), emperorCounter, royalistCounter, rebelCounter, spyCounter);
Expand All @@ -100,6 +91,15 @@ private RoleBox() {
setSpacing(10);
}

private static void updateCounter(int emperor, int royalist, int rebel, int spy) {
Platform.runLater(() -> {
emperorCounter.setText("Emperor: " + emperor);
royalistCounter.setText("Royalist: " + royalist);
rebelCounter.setText("Rebel: " + rebel);
spyCounter.setText("Spy: " + spy);
});
}

private static class SubTitle extends Text {
private SubTitle(String text) {
super(text);
Expand Down Expand Up @@ -195,16 +195,14 @@ private StartButton(String text) {
setOnMouseExited(e -> setBackground(new Background(new BackgroundFill(Color.valueOf("44FF02"), new CornerRadii(40), null))));
setOnMousePressed(e -> setBackground(new Background(new BackgroundFill(Color.valueOf("2b850c"), new CornerRadii(40), null))));
setOnMouseReleased(e -> setBackground(new Background(new BackgroundFill(Color.valueOf("44FF02"), new CornerRadii(40), null))));
setOnAction(e -> {
new Thread(() -> {
Platform.runLater(() -> setDisable(true));
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
}
Platform.runLater(() -> setDisable(false));
}, "temporary disable start button thread").start();
});
setOnAction(e -> new Thread(() -> {
Platform.runLater(() -> setDisable(true));
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
}
Platform.runLater(() -> setDisable(false));
}, "temporary disable start button thread").start());
}
}
}
22 changes: 11 additions & 11 deletions src/main/java/com/lapisberry/utils/RoleCountHelper.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
package com.lapisberry.utils;

public final class RoleCountHelper {
// Array of role count
private static final int[][] TABLE = {// sp,rb,ry -> spy, rebel, royalist
{1, 2, 0},// 4 players
{1, 2, 1},// 5 players
{1, 3, 1},// 6 players
{1, 3, 2},// 7 players
{2, 3, 2},// 8 players
{2, 4, 2},// 9 players
{2, 4, 3} // 10 players
};

public static int getEmperors(int players) {
if (4 <= players && players <= 8) return 1;
return 0;
Expand All @@ -20,15 +31,4 @@ public static int getSpies(int players) {
if (4 <= players && players <= 8) return TABLE[players - 4][0];
return 0;
}

// Array of role count
private static final int[][] TABLE = {// sp,rb,ry -> spy, rebel, royalist
{1, 2, 0},// 4 players
{1, 2, 1},// 5 players
{1, 3, 1},// 6 players
{1, 3, 2},// 7 players
{2, 3, 2},// 8 players
{2, 4, 2},// 9 players
{2, 4, 3} // 10 players
};
}

0 comments on commit b903ad6

Please sign in to comment.