Skip to content

Commit

Permalink
Change methods for better indipendence
Browse files Browse the repository at this point in the history
  • Loading branch information
bagarozzi committed Mar 27, 2024
1 parent 8b16a65 commit f126dff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
14 changes: 10 additions & 4 deletions src/main/java/it/unibo/bombardero/map/api/BombarderoTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@ public interface BombarderoTimer {
void startTimer();

/**
* Checks if the time is over, if such it alerts the @manager
* so the proper changes can be made to the map.
* Updates the timer
* This method is assumed to be called peiodically and after the @startTimer method
* has been called at least once.
*/
void updateTimer();

/**
* Returns the time left for the logic to check, no formatting is done
* @return the time left
*/
long getTimeLeft();

/**
* Formats the time properly for displaying as such: "MM:SS"
* Formats the time properly for displaying as such: "MM:SS" and
* returns a String type
* @return the properly formatted time
*/
String getTimeLeft();
String getFormattedTimeLeft();

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class BombarderoTimerImpl implements BombarderoTimer {
private final static String TIME_SEPARATOR = ":";

private long startTime = 0l;
private long timeLeft = 0l;
private final MapManager manager;

public BombarderoTimerImpl(MapManager manager) {
Expand All @@ -25,13 +26,16 @@ public void startTimer() {

@Override
public void updateTimer() {
if(System.currentTimeMillis() - startTime >= Utils.GAME_TIME) {
manager.triggerArenaCollpse();
}
this.timeLeft = System.currentTimeMillis() - startTime;
}

public long getTimeLeft() {
updateTimer();
return this.timeLeft;
}

@Override
public String getTimeLeft() {
public String getFormattedTimeLeft() {
double secondsLeft = (System.currentTimeMillis() - this.startTime)/SECONDS_TO_MILLIS;
return Double.toString(Math.ceil(secondsLeft/BombarderoTimerImpl.MINUTES_TO_SECONDS)) +
BombarderoTimerImpl.TIME_SEPARATOR +
Expand Down

0 comments on commit f126dff

Please sign in to comment.