diff options
| author | Willem Dalton <144246261+WillemDalton@users.noreply.github.com> | 2025-10-12 12:36:17 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-12 12:36:17 -0400 |
| commit | ab1c8dbf8e3fbd7ae1affd17e7b5596b1e58e839 (patch) | |
| tree | 91ed2c27e9735e05c8569f48e1130a95a7bdeb46 /src/main/java/design/controller/userinput/menus/HolePlayMenu.java | |
| parent | 1eca2f8681752ad359e8372780cdf719e2b1747d (diff) | |
| parent | 050118d5d029382ffc3b11e9f8159fb297007ef5 (diff) | |
| download | designproject-design-6-ab1c8dbf8e3fbd7ae1affd17e7b5596b1e58e839.tar.gz designproject-design-6-ab1c8dbf8e3fbd7ae1affd17e7b5596b1e58e839.tar.bz2 designproject-design-6-ab1c8dbf8e3fbd7ae1affd17e7b5596b1e58e839.zip | |
Merge pull request #12 from RIT-SWEN-262/menu-reorganize
Menu reorganize
Diffstat (limited to 'src/main/java/design/controller/userinput/menus/HolePlayMenu.java')
| -rw-r--r-- | src/main/java/design/controller/userinput/menus/HolePlayMenu.java | 74 |
1 files changed, 42 insertions, 32 deletions
diff --git a/src/main/java/design/controller/userinput/menus/HolePlayMenu.java b/src/main/java/design/controller/userinput/menus/HolePlayMenu.java index 14e5345..c824341 100644 --- a/src/main/java/design/controller/userinput/menus/HolePlayMenu.java +++ b/src/main/java/design/controller/userinput/menus/HolePlayMenu.java @@ -2,6 +2,8 @@ package design.controller.userinput.menus; import design.controller.userinput.Menu; import design.controller.userinput.MenuOption; +import design.model.Course; +import design.model.Hole; import design.runtime.Session; import design.model.Club; import design.model.Round; @@ -17,8 +19,8 @@ public class HolePlayMenu extends Menu { private final Round round; private final HolePlayContext ctx; - public HolePlayMenu(Round round) { - this.round = round; + public HolePlayMenu() { + this.round = createRound(); this.ctx = new HolePlayContext(Session.getCurrentGolfer(), round, PersonalDatabase.INSTANCE); } @@ -44,38 +46,11 @@ public class HolePlayMenu extends Menu { } else { // 0) Take a shot opts.add(new MenuOption("take a shot", () -> { - // loads golfers clubs - var golfer = Session.getCurrentGolfer(); - Club[] clubs = (golfer == null) ? new Club[0] : golfer.getClubs(); - - if (clubs.length == 0) { - System.out.println("You don't have any clubs yet. Add one first."); - new AddClubMenu().present(); - this.present(); - return; - } - - // list clubs - System.out.println("-- YOUR CLUBS --"); - for (int i = 0; i < clubs.length; i++) { - Club c = clubs[i]; - System.out.printf("%d: #%d %s - %s (%s)%n", - i + 1, c.getId(), c.getNickname(), c.getManufacture(), c.getClubType()); - } + var selector = new SelectClub(); + selector.present(); + Club club = selector.getResult(); - // user selects one of their clubs Scanner sc = new Scanner(System.in); - Club club = null; - while (club == null) { - System.out.print("Select club # (1.." + clubs.length + "): "); - String line = sc.nextLine().trim(); - int idx = Integer.parseInt(line); - if (idx < 1 || idx > clubs.length) { - System.out.println("Out of range. Try again."); - continue; - } - club = clubs[idx - 1]; - } // Get shot distance (defaults to 0 of not stated) System.out.print("Distance (yds, blank=0): "); @@ -111,4 +86,39 @@ public class HolePlayMenu extends Menu { return opts; } + + private static Round createRound() { + var golfer = Session.getCurrentGolfer(); + + var selector = new SelectCourse(); + selector.present(); + Course course = selector.getResult(); + + Scanner sc = new Scanner(System.in); + // Gets starting hole on course + int startHoleNum = 1; + int holeCount = course.getHoleCount(); + // Asks for a hole number until a valid number is selected + System.out.print("Starting hole (1.." + holeCount + ", blank=1): "); + String s = sc.nextLine().trim(); + if (!s.isEmpty()) { + int start; + try { + start = Integer.parseInt(s); + } catch (NumberFormatException ex) { + System.out.println("Input must be a number"); + return createRound(); + } + if (start < 1 || start > holeCount) { + System.out.println("Starting hole must be between 1 and " + holeCount + "."); + return createRound(); + } + startHoleNum = start; + } + // Starts round and sends user to HolePlayMenu + Hole startHole = course.getHoles().get(startHoleNum - 1); + Round r = new Round(course, Session.getDateTime(), startHole); + golfer.addRound(r); + return r; + } } |
