diff options
| author | Jacob Shimp <jrs9538@g.rit.edu> | 2025-10-05 14:35:04 -0400 |
|---|---|---|
| committer | Jacob Shimp <jrs9538@g.rit.edu> | 2025-10-05 14:35:04 -0400 |
| commit | ea6a4afbe65ff6e26b568345efbb564a0a86abc9 (patch) | |
| tree | c815add1a75fed21f129845bc170b12cdfdca0cf /src/main/java/design/model/Round.java | |
| parent | b4919667c3455d8b517df6a72b7d37e0734d9155 (diff) | |
| parent | c5cbe4ffd56b7c96d85dc1676387993c6c15af7b (diff) | |
| download | designproject-design-6-ea6a4afbe65ff6e26b568345efbb564a0a86abc9.tar.gz designproject-design-6-ea6a4afbe65ff6e26b568345efbb564a0a86abc9.tar.bz2 designproject-design-6-ea6a4afbe65ff6e26b568345efbb564a0a86abc9.zip | |
merged from main
Diffstat (limited to 'src/main/java/design/model/Round.java')
| -rw-r--r-- | src/main/java/design/model/Round.java | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/main/java/design/model/Round.java b/src/main/java/design/model/Round.java index 9cc1462..e4442d3 100644 --- a/src/main/java/design/model/Round.java +++ b/src/main/java/design/model/Round.java @@ -1,20 +1,37 @@ package design.model; +import com.fasterxml.jackson.annotation.JsonCreator; + import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; public class Round { - private final transient Course course; + private final Course course; private final LocalDateTime dateTime; private final Hole startingHole; private final List<Play> plays; + private int currentHoleIndex; + + @JsonCreator + private Round(Course course, LocalDateTime dateTime, Hole startingHole, List<Play> plays) { + this.course = course; + this.dateTime = dateTime; + this.startingHole = startingHole; + this.plays = plays; + // Allows the golfer to start anywhere on the course. Helps HolePalyContext be + // simpler. + this.currentHoleIndex = Math.max(0, startingHole.getNumber() - 1); + } public Round(Course course, LocalDateTime dateTime, Hole startingHole) { this.course = course; this.dateTime = dateTime; this.startingHole = startingHole; plays = new ArrayList<>(); + // Allows the golfer to start anywhere on the course. Helps HolePalyContext be + // simpler. + this.currentHoleIndex = Math.max(0, startingHole.getNumber() - 1); } public int getTotalSwings() { @@ -48,4 +65,14 @@ public class Round { public void addPlay(Play play) { plays.add(play); } + + // Current hole + public Hole getCurrentHole() { + return course.getHoles().get(currentHoleIndex); + } + + // Handles wraparound too + public void nextHole() { + currentHoleIndex = (currentHoleIndex + 1) % course.getHoleCount(); + } } |
