private static void addAchievement() throws IOException, RequirementsNotMetException { String achievement; if (AccessController.getCurrentUser() == null) { System.out.println("Create person first!"); createPerson(); } Person current = AccessController.getCurrentPerson(); if (current != null) { System.out.print("Enter achievement:"); achievement = br.readLine(); current.addAchievement(getAchievement(achievement)); } else { System.out.println("No person in use."); } }
private static Achievement getAchievement(String achievement) throws RequirementsNotMetException { switch (achievement) { case "Rob": return new Rob(AccessController.getCurrentPerson()); case "Crawl": return new Crawl(AccessController.getCurrentPerson()); case "Stand": return new Stand(AccessController.getCurrentPerson()); case "Walk": return new Walk(AccessController.getCurrentPerson()); case "Run": return new Run(AccessController.getCurrentPerson()); case "Sprint": return new Sprint(AccessController.getCurrentPerson()); case "Balance": return new Balance(AccessController.getCurrentPerson()); case "BindShoeLaces": return new BindShoeLaces(AccessController.getCurrentPerson()); case "Giggle": return new Giggle(AccessController.getCurrentPerson()); case "Grow": return new Grow(AccessController.getCurrentPerson()); case "Laugh": return new Laugh(AccessController.getCurrentPerson()); case "UseValcrowShoes": return new UseValcrowShoes(AccessController.getCurrentPerson()); case "Speak": return new Speak(AccessController.getCurrentPerson()); case "Read": return new Read(AccessController.getCurrentPerson()); case "WatchTV": return new WatchTV(AccessController.getCurrentPerson()); case "DryDishes": return new DryDishes(AccessController.getCurrentPerson()); case "BeButtler": return new BeButtler(AccessController.getCurrentPerson()); case "BeWaiter": return new BeWaiter(AccessController.getCurrentPerson()); case "BindTie": return new BindTie(AccessController.getCurrentPerson()); case "PolishCuttlery": return new PolishCuttlery(AccessController.getCurrentPerson()); case "PolishShoes": return new PolishShoes(AccessController.getCurrentPerson()); case "Babble": return new Babble(AccessController.getCurrentPerson()); case "Drink": return new Drink(AccessController.getCurrentPerson()); case "Swallow": return new Swallow(AccessController.getCurrentPerson()); default: System.out.println("Achievement '" + achievement + "' not available."); return null; } }
private static void createPerson() throws IOException { boolean continueCreation = true; if (!AccessController.isLoggedInAsAdmin() && AccessController.getCurrentPerson() != null) { System.out.println( "Can have only 1 person at a time.\nDelete current person?" + getConfirmPhrase()); String delete = br.readLine(); if (delete.equals(confirmPhrase)) { // TODO only remove if admin requests this specific removal // PersonDatabase.removePerson(AccessController.getCurrentPerson() // .getId(), AccessController.getAdmin().getPerson()); AccessController.setCurrentPerson(null); } else { System.out.println("Creation cancelled."); continueCreation = false; } } if (continueCreation) { String firstName = "user", lastName = "" + (++counter); int age = 0; boolean valid = false; while (!valid) { System.out.print("Enter first name:"); firstName = br.readLine(); if (!firstName.equals("")) { valid = true; } } valid = false; while (!valid) { System.out.print("Enter last name:"); lastName = br.readLine(); if (!lastName.equals("")) { valid = true; } } valid = false; while (!valid) { try { System.out.print("Enter age:"); age = Integer.parseInt(br.readLine()); valid = true; } catch (NumberFormatException nfe) { System.out.println("Invalid Format!"); } } boolean editable = false; Permission permission = Permission.GUEST; if (AccessController.isLoggedInAsUser() || AccessController.isLoggedInAsAdmin()) { permission = Permission.USER; if (AccessController.isLoggedInAsAdmin()) { System.out.print("Editable person?" + getConfirmPhrase()); String editString = br.readLine(); if (editString.equals(confirmPhrase)) { editable = true; } System.out.print("Admin rights?" + getConfirmPhrase()); String permString = br.readLine(); if (permString.equals(confirmPhrase)) { permission = Permission.ADMIN; } } } if (AccessController.getCurrentUser() == null) { createGuestPerson(firstName, lastName, age); } else { Person person = new Person(firstName, lastName, age, editable, permission); AccessController.setCurrentPerson(person); } System.out.println( "Person created: " + AccessController.getCurrentPerson().getFirstName() + " " + AccessController.getCurrentPerson().getLastName() + " [" + AccessController.getCurrentPerson().getPermission() + "]"); } }