Skip to content

Commit

Permalink
Fixed Scheduling error
Browse files Browse the repository at this point in the history
  • Loading branch information
Antenehden authored Aug 4, 2024
1 parent b06e3bf commit 9784e42
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/main/java/uta/cse3310/GameTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ public GameTimer() {
this.timer = new Timer();
this.elapsedTime = 0;
this.isRunning = false;
this.timerTask = new TimerTask() {
@Override
public void run() {
elapsedTime = System.currentTimeMillis() - startTime;
}
};
}

public void start() {
Expand All @@ -28,6 +22,15 @@ public void start() {
}
this.startTime = System.currentTimeMillis();
this.isRunning = true;

// Create a new TimerTask instance each time the timer is started
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
elapsedTime = System.currentTimeMillis() - startTime;
}
};

timer.scheduleAtFixedRate(timerTask, 0, 1000); // Update elapsed time every second
}

Expand Down Expand Up @@ -55,6 +58,3 @@ public boolean isRunning() {
return isRunning;
}
}



0 comments on commit 9784e42

Please sign in to comment.