-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds bottom panel with clock and day and fake weather
- Loading branch information
Showing
4 changed files
with
213 additions
and
2 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/TimeAndWeatherController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| package edu.ntnu.idi.idatt2003.gruppe42.Controller; | ||
|
|
||
| import edu.ntnu.idi.idatt2003.gruppe42.Controller.AppControllers.AppController; | ||
| import java.time.LocalDate; | ||
| import java.time.format.DateTimeFormatter; | ||
| import java.util.Random; | ||
| import javafx.beans.property.IntegerProperty; | ||
| import javafx.beans.property.ObjectProperty; | ||
| import javafx.beans.property.SimpleIntegerProperty; | ||
| import javafx.beans.property.SimpleObjectProperty; | ||
| import javafx.beans.property.SimpleStringProperty; | ||
| import javafx.beans.property.StringProperty; | ||
|
|
||
| /** | ||
| * Controller for managing game time and weather. | ||
| * Advances 1 hour per tick. | ||
| */ | ||
| public class TimeAndWeatherController implements AppController { | ||
| private final IntegerProperty hour = new SimpleIntegerProperty(0); | ||
| private final IntegerProperty dayIndex = new SimpleIntegerProperty(0); // 0 = Sunday, 1 = Monday, etc. | ||
| private final IntegerProperty temperature = new SimpleIntegerProperty(15); | ||
| private final StringProperty weather = new SimpleStringProperty("Sunny"); | ||
| private final Random random = new Random(); | ||
|
|
||
| private static final String[] DAYS = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}; | ||
|
|
||
| public TimeAndWeatherController() { | ||
| updateWeather(); | ||
| } | ||
|
|
||
| @Override | ||
| public void nextTick() { | ||
| int nextHour = hour.get() + 1; | ||
| if (nextHour >= 24) { | ||
| hour.set(0); | ||
| dayIndex.set((dayIndex.get() + 1) % 7); | ||
| updateWeather(); | ||
| } else { | ||
| hour.set(nextHour); | ||
| } | ||
| } | ||
|
|
||
| private void updateWeather() { | ||
| // Basic seasonal/random temperature logic | ||
| // Range from -10 to 30 | ||
| int change = random.nextInt(11) - 5; // -5 to +5 | ||
| int newTemp = temperature.get() + change; | ||
| if (newTemp < -10) newTemp = -10; | ||
| if (newTemp > 30) newTemp = 30; | ||
| temperature.set(newTemp); | ||
|
|
||
| if (newTemp <= 0) { | ||
| weather.set("Snow"); | ||
| } else { | ||
| // If warm, could be sunny or rain | ||
| if (random.nextBoolean()) { | ||
| weather.set("Sunny"); | ||
| } else { | ||
| weather.set("Rain"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public IntegerProperty hourProperty() { | ||
| return hour; | ||
| } | ||
|
|
||
| public IntegerProperty dayIndexProperty() { | ||
| return dayIndex; | ||
| } | ||
|
|
||
| public IntegerProperty temperatureProperty() { | ||
| return temperature; | ||
| } | ||
|
|
||
| public StringProperty weatherProperty() { | ||
| return weather; | ||
| } | ||
|
|
||
| public String getTimeString() { | ||
| return String.format("%02d:00", hour.get()); | ||
| } | ||
|
|
||
| public String getDayOfWeekString() { | ||
| return DAYS[dayIndex.get()]; | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters