Skip to content

fix small bugs with merge #145

Merged
merged 1 commit into from
May 25, 2026
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public enum Audio {
CLOCK("/audio/clock.wav", true),

// Background music
WORK_THEME("/audio/work_theme.mp3", false),
WEEKEND_THEME("/audio/weekend_theme.mp3", false);

private final String path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public final class GameController {

private final List<AppController> appControllers = new ArrayList<>();
private Timer timer;
private GameState gameState;
private GameState gameState = GameState.FREEDAY;
private final AudioManager audioManager = AudioManager.get();
private boolean workMusicPlaying = false;
private boolean weekendMusicPlaying = false;
Expand All @@ -44,7 +44,7 @@ public void setGameState(final GameState gameState) {
this.gameState = gameState;

if (gameState == GameState.WORKDAY && !workMusicPlaying) {
//audioManager.playBgMusic(Audio.WORK_THEME);
audioManager.playBgMusic(Audio.WORK_THEME);
workMusicPlaying = true;
weekendMusicPlaying = false;
}
Expand All @@ -64,14 +64,16 @@ public void setGameState(final GameState gameState) {
public void startGame() {
timer = new Timer(true);
final int delay = 0;
final int period = 1000;
final int period = 100;

timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {

for (AppController controller : appControllers) {
controller.nextTick();
}

if (isWeekend()) {
stopGame();
}
Expand All @@ -90,11 +92,11 @@ public void stopGame() {
}

/**
* Returns whether the current game state is a weekend.
* Weekend checker.
*
* @return {@code true} if the game state is {@link GameState#FREEDAY}.
* @return {@code true} if the game state is weekend
*/
public boolean isWeekend() {
return gameState == GameState.FREEDAY;
return gameState == GameState.FREEDAY || gameState == GameState.RENTDAY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public final class MarketController implements AppController {
/**
* Creates a new market controller and loads stock data from a file.
*
* @param path the path to the stock data file
* @throws IOException if the file cannot be read
* @throws StockFileParseException if the file content is malformed
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* Controller responsible for managing in-game time, days, weeks, and weather.
*/
public class TimeAndWeatherController implements AppController {
private final IntegerProperty hour = new SimpleIntegerProperty(0);
private final IntegerProperty dayIndex = new SimpleIntegerProperty(0);
private final IntegerProperty hour = new SimpleIntegerProperty(HOURS_PER_DAY - 1);
private final IntegerProperty dayIndex = new SimpleIntegerProperty(SATURDAY_INDEX);
private final IntegerProperty weekNumber = new SimpleIntegerProperty(0);
private final IntegerProperty temperature = new SimpleIntegerProperty(15);
private final StringProperty weather = new SimpleStringProperty("Sunny");
Expand All @@ -41,26 +41,26 @@ public class TimeAndWeatherController implements AppController {
public TimeAndWeatherController(GameController gameController) {
this.gameController = gameController;
updateWeather();
updateGameState();
}

/**
* Processes the next tick.
*/
@Override
public void nextTick() {
Platform.runLater(() -> {
int nextHour = hour.get() + 1;
if (nextHour >= HOURS_PER_DAY) {
dayIndex.set((dayIndex.get() + 1) % 7);
updateGameState();
updateWeather();
int nextHour = hour.get() + 1;
if (nextHour >= HOURS_PER_DAY) {
int nextDayIndex = (dayIndex.get() + 1) % 7;
Platform.runLater(() -> {
dayIndex.set(nextDayIndex);
hour.set(0);
audioManager.playSfx(Audio.CLOCK);
} else {
hour.set(nextHour);
}
});
});
updateGameState(nextDayIndex);
updateWeather();
audioManager.playSfx(Audio.CLOCK);
} else {
Platform.runLater(() -> hour.set(nextHour));
}
}

/**
Expand Down Expand Up @@ -115,6 +115,7 @@ public IntegerProperty weekIndexProperty() {
public void advanceWeek() {
weekNumber.set(weekNumber.get() + 1);
dayIndex.set(1);
hour.set(0);
updateGameState();
gameController.startGame();
}
Expand Down Expand Up @@ -172,10 +173,20 @@ public String getWeekString() {
* all other days → {@link GameState#WORKDAY}.
*/
public void updateGameState() {
if (dayIndex.get() == SATURDAY_INDEX) {
updateGameState(dayIndex.get());
}

/**
* Updates the current game state based on a specific day index.
*
* @param index the day index
*/
private void updateGameState(int index) {

if (index == SATURDAY_INDEX) {
gameController.setGameState(GameState.RENTDAY);
return;
} else if (dayIndex.get() == SUNDAY_INDEX) {
} else if (index == SUNDAY_INDEX) {
gameController.setGameState(GameState.FREEDAY);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ private void wireWeekendRapport() {
weekendReportApp.getRoot().setVisible(false);
desktopView.exitLayer(ModalLayer.RAPPORT);
timeAndWeatherController.setDay(0);
timeAndWeatherController.hourProperty().set(0);
});
}

Expand Down
Binary file added src/main/resources/audio/work_theme.mp3
Binary file not shown.