diff --git a/src/main/java/org/vashonsd/pirateship/Game.java b/src/main/java/org/vashonsd/pirateship/Game.java index 320a136..3df5d83 100644 --- a/src/main/java/org/vashonsd/pirateship/Game.java +++ b/src/main/java/org/vashonsd/pirateship/Game.java @@ -7,6 +7,9 @@ import org.vashonsd.pirateship.interactions.Request; import org.vashonsd.pirateship.io.*; import org.vashonsd.pirateship.item.*; +import org.vashonsd.pirateship.runtimeevents.listeners.PlayerDropListener; +import org.vashonsd.pirateship.runtimeevents.listeners.PlayerMovementListener; +import org.vashonsd.pirateship.runtimeevents.listeners.PlayerTakeListener; import org.vashonsd.pirateship.structure.*; import org.vashonsd.pirateship.minigame.*; @@ -14,13 +17,13 @@ public class Game { private StringRead reader; private StringWrite writer; - private DatabaseWriter db = new DatabaseWriter(); - //This is our register of current Players, each with a unique ID. private PlayerRegistry players; //private HashMap players; + private World thisWorld; + private String quitWord; public Game(String world) throws IOException { @@ -28,12 +31,13 @@ public Game(String world) throws IOException { quitWord = "exit"; - //thisWorld = WorldBuilder.makeWorldByFile(world); - World thisWorld = WorldBuilder.makeWorld(world); + thisWorld = DatabaseParser.parseWorld(world); + //thisWorld = WorldBuilder.makeWorld(world); this.players = new PlayerRegistry(); Player p = new Player("Demo", "Just a player"); p.setLocation(thisWorld.getStartingLocation()); + p.addEventListeners(new PlayerMovementListener(), new PlayerTakeListener(), new PlayerDropListener()); String pid = players.EnrollPlayer(p); reader = new UserInput(); @@ -52,6 +56,7 @@ public void Run() throws IOException { } writer.write(p.handle(command).getText());; } + DatabaseWriter.worldWriter(thisWorld); writer.write("Thanks for playing!"); } } diff --git a/src/main/java/org/vashonsd/pirateship/interactions/Actor.java b/src/main/java/org/vashonsd/pirateship/interactions/Actor.java index 0c7f7ef..1f328ee 100644 --- a/src/main/java/org/vashonsd/pirateship/interactions/Actor.java +++ b/src/main/java/org/vashonsd/pirateship/interactions/Actor.java @@ -1,10 +1,16 @@ package org.vashonsd.pirateship.interactions; import java.util.ArrayList; +import java.util.EventListener; import java.util.HashMap; +import java.util.Iterator; +import java.util.List; import java.util.UUID; import org.vashonsd.pirateship.commands.Command; +import org.vashonsd.pirateship.runtimeevents.events.PlayerInventoryEvent; +import org.vashonsd.pirateship.runtimeevents.events.PlayerMovementEvent; +import org.vashonsd.pirateship.runtimeevents.listeners.*; /** * An Actor is anything that can interact in the World. @@ -61,6 +67,43 @@ public HashMap getCommands() { public void setCommands(HashMap commands) { this.commands = commands; } + + /** + * Represents all the listeners that can act upon an event originating from this Actor. + * + * Once a listener is added to the Actor's listeners, that listener can handle that event + * with the "onEvent()" method. + */ + //If we end up adding more types of listeners, we will need to change these list parameters. + private List _listeners = new ArrayList(); + + + /** + * Use this to add a listener to the current listeners on this Actor. + */ + public synchronized void addEventListener(EventListener l) { + _listeners.add(l); + } + + public synchronized void addEventListeners(EventListener... l) { + for(EventListener eL: l) { + addEventListener(eL); + } + } + + /** + * Use this to remove a listener from the current listeners on this Actor. + */ + public synchronized void removeEventListener(EventListener l) { + _listeners.remove(l); + } + + public synchronized void removeEventListeners(EventListener... l) { + for(EventListener eL: l) { + removeEventListener(eL); + } + } + /** * An Inventory object keeps all the Actors within this Actor. @@ -77,10 +120,24 @@ public Inventory getInventory() { */ public void addToInventory(Actor a) { a.setLocation(this); + Iterator i = _listeners.iterator(); + while(i.hasNext()) { + try { + ((PlayerTakeListener) i.next()).onPlayerTake(new PlayerInventoryEvent(this, a)); + } catch(ClassCastException e) { + } + } this.inventory.addActor(a); } public boolean removeFromInventory(Actor a) { + Iterator i = _listeners.iterator(); + while(i.hasNext()) { + try { + ((PlayerDropListener) i.next()).onPlayerDrop(new PlayerInventoryEvent(this, a)); + } catch(ClassCastException e) { + } + } return this.inventory.remove(a); } @@ -113,7 +170,17 @@ public Actor getLocation() { return currentLocation; } + /** + * This method sets the location of an Actor, but also triggers the event "PlayerMovement". + */ public void setLocation(Actor currentLocation) { + Iterator i = _listeners.iterator(); + while(i.hasNext()) { + try { + ((PlayerMovementListener) i.next()).onPlayerMovement(new PlayerMovementEvent(this, currentLocation)); + } catch(ClassCastException e) { + } + } this.currentLocation = currentLocation; } diff --git a/src/main/java/org/vashonsd/pirateship/interactions/ItemFactory.java b/src/main/java/org/vashonsd/pirateship/interactions/ItemFactory.java new file mode 100644 index 0000000..f2ab4a0 --- /dev/null +++ b/src/main/java/org/vashonsd/pirateship/interactions/ItemFactory.java @@ -0,0 +1,46 @@ +package org.vashonsd.pirateship.interactions; + + +import org.vashonsd.pirateship.creature.*; +import org.vashonsd.pirateship.minigame.MinigameRunner; + +public class ItemFactory { + + private static String[] minigames = new String[] {"20Q", "Blackjack", "CC", "GF", "GuessCalc", "math", "GOPP", "Shot", "TTT"}; + + public static Actor newActor(String name, String typeName, + String description, String splash) { + Actor a; + if(isMinigame(typeName)) { + a = new MinigameRunner(typeName); + } else if (typeName.equalsIgnoreCase("Baguette")) { + a = new Baguette(name, description, splash); + } else if (typeName.equalsIgnoreCase("Sword")) { + a = new Sword(name, description, splash); + } else if (typeName.equalsIgnoreCase("Bandage")) { + a = new Bandage(name, description, splash); + } else if (typeName.equalsIgnoreCase("StopWatch")) { + a = new StopWatch(name); + } else if (typeName.equalsIgnoreCase("Eagle")) { + a = new Eagle(name); + } else if (typeName.equalsIgnoreCase("Kraken")) { + a = new Kraken(name, description, splash); + } else if (typeName.equalsIgnoreCase("Lizard")) { + a = new Lizard(name, description, splash); + } else if (typeName.equalsIgnoreCase("Dog")) { + a = new Dog(name, description, splash); + } else { + a = null; + } + return a; + } + + private static boolean isMinigame(String typeName) { + for(String s: minigames) { + if(s.equalsIgnoreCase(typeName)) { + return true; + } + } + return false; + } +} diff --git a/src/main/java/org/vashonsd/pirateship/item/ItemType.java b/src/main/java/org/vashonsd/pirateship/item/ItemType.java index 29a5af1..96d553f 100644 --- a/src/main/java/org/vashonsd/pirateship/item/ItemType.java +++ b/src/main/java/org/vashonsd/pirateship/item/ItemType.java @@ -2,6 +2,7 @@ import java.util.*; + public class ItemType { private ArrayList tags; diff --git a/src/main/java/org/vashonsd/pirateship/minigame/Minigame.java b/src/main/java/org/vashonsd/pirateship/minigame/Minigame.java index 794d6f3..a9c6e4b 100644 --- a/src/main/java/org/vashonsd/pirateship/minigame/Minigame.java +++ b/src/main/java/org/vashonsd/pirateship/minigame/Minigame.java @@ -34,7 +34,7 @@ public static Minigame produce(String s) { m = new PrisonEscapeFactory(); } else if (s.equalsIgnoreCase("Shot")) { m = new ShotgunFactory(); - } else if (s.equalsIgnoreCase("Tic tac toe")) { + } else if (s.equalsIgnoreCase("TTT")) { m = new TicTacToeFactory(); } else { diff --git a/src/main/java/org/vashonsd/pirateship/runtimeevents/events/PlayerInventoryEvent.java b/src/main/java/org/vashonsd/pirateship/runtimeevents/events/PlayerInventoryEvent.java new file mode 100644 index 0000000..842f46b --- /dev/null +++ b/src/main/java/org/vashonsd/pirateship/runtimeevents/events/PlayerInventoryEvent.java @@ -0,0 +1,19 @@ +package org.vashonsd.pirateship.runtimeevents.events; + +import java.util.EventObject; + +import org.vashonsd.pirateship.interactions.Actor; + +public class PlayerInventoryEvent extends EventObject { + + private Actor recipient; + + public PlayerInventoryEvent(Object source, Actor recipient) { + super(source); + this.recipient = recipient; + } + + public Actor getRecipient() { + return this.recipient; + } +} diff --git a/src/main/java/org/vashonsd/pirateship/runtimeevents/events/PlayerMovementEvent.java b/src/main/java/org/vashonsd/pirateship/runtimeevents/events/PlayerMovementEvent.java new file mode 100644 index 0000000..71b06d0 --- /dev/null +++ b/src/main/java/org/vashonsd/pirateship/runtimeevents/events/PlayerMovementEvent.java @@ -0,0 +1,19 @@ +package org.vashonsd.pirateship.runtimeevents.events; + +import java.util.EventObject; + +import org.vashonsd.pirateship.interactions.Actor; + +public class PlayerMovementEvent extends EventObject { + + private Actor currentLocation; + + public PlayerMovementEvent(Object source, Actor currentLocation) { + super(source); + this.currentLocation = currentLocation; + } + + public Actor getCurrentLocation() { + return this.currentLocation; + } +} diff --git a/src/main/java/org/vashonsd/pirateship/runtimeevents/listeners/PlayerDropListener.java b/src/main/java/org/vashonsd/pirateship/runtimeevents/listeners/PlayerDropListener.java new file mode 100644 index 0000000..1c92308 --- /dev/null +++ b/src/main/java/org/vashonsd/pirateship/runtimeevents/listeners/PlayerDropListener.java @@ -0,0 +1,24 @@ +package org.vashonsd.pirateship.runtimeevents.listeners; + +import java.io.IOException; +import java.util.EventListener; + +import org.vashonsd.pirateship.interactions.Actor; +import org.vashonsd.pirateship.interactions.Player; +import org.vashonsd.pirateship.io.ConsoleOut; +import org.vashonsd.pirateship.io.StringWrite; +import org.vashonsd.pirateship.runtimeevents.events.PlayerInventoryEvent; + +public class PlayerDropListener implements EventListener{ + + public void onPlayerDrop(PlayerInventoryEvent e){ + Player p = (Player)e.getSource(); + Actor a = e.getRecipient(); + try { + StringWrite writer = new ConsoleOut(); + writer.write(a.getName() + " has been dropped by " + p.getName()); + } catch (IOException e1) { + e1.printStackTrace(); + } + } +} diff --git a/src/main/java/org/vashonsd/pirateship/runtimeevents/listeners/PlayerMovementListener.java b/src/main/java/org/vashonsd/pirateship/runtimeevents/listeners/PlayerMovementListener.java new file mode 100644 index 0000000..7c0c487 --- /dev/null +++ b/src/main/java/org/vashonsd/pirateship/runtimeevents/listeners/PlayerMovementListener.java @@ -0,0 +1,21 @@ +package org.vashonsd.pirateship.runtimeevents.listeners; + +import java.io.IOException; +import java.util.EventListener; + +import org.vashonsd.pirateship.interactions.Player; +import org.vashonsd.pirateship.io.*; +import org.vashonsd.pirateship.runtimeevents.events.PlayerMovementEvent; + +public class PlayerMovementListener implements EventListener { + + public void onPlayerMovement(PlayerMovementEvent e) { + Player p = (Player)e.getSource(); + try { + StringWrite writer = new ConsoleOut(); + writer.write(p.getName() + " has entered " + e.getCurrentLocation().getName()); + } catch (IOException e1) { + e1.printStackTrace(); + } + } +} diff --git a/src/main/java/org/vashonsd/pirateship/runtimeevents/listeners/PlayerTakeListener.java b/src/main/java/org/vashonsd/pirateship/runtimeevents/listeners/PlayerTakeListener.java new file mode 100644 index 0000000..d7feb0d --- /dev/null +++ b/src/main/java/org/vashonsd/pirateship/runtimeevents/listeners/PlayerTakeListener.java @@ -0,0 +1,24 @@ +package org.vashonsd.pirateship.runtimeevents.listeners; + +import java.io.IOException; +import java.util.EventListener; + +import org.vashonsd.pirateship.interactions.Actor; +import org.vashonsd.pirateship.interactions.Player; +import org.vashonsd.pirateship.io.ConsoleOut; +import org.vashonsd.pirateship.io.StringWrite; +import org.vashonsd.pirateship.runtimeevents.events.PlayerInventoryEvent; + +public class PlayerTakeListener implements EventListener{ + + public void onPlayerTake(PlayerInventoryEvent e){ + Player p = (Player)e.getSource(); + Actor a = e.getRecipient(); + try { + StringWrite writer = new ConsoleOut(); + writer.write(p.getName() + " has taken " + a.getName()); + } catch (IOException e1) { + e1.printStackTrace(); + } + } +} diff --git a/src/main/java/org/vashonsd/pirateship/structure/DatabaseParser.java b/src/main/java/org/vashonsd/pirateship/structure/DatabaseParser.java index d76627e..62d3f42 100644 --- a/src/main/java/org/vashonsd/pirateship/structure/DatabaseParser.java +++ b/src/main/java/org/vashonsd/pirateship/structure/DatabaseParser.java @@ -3,51 +3,78 @@ import java.io.*; import java.util.*; +import org.vashonsd.pirateship.interactions.ItemFactory; + import com.google.gson.stream.*; public class DatabaseParser { - private HashMap locations = new HashMap(); - private ArrayList locationNames = new ArrayList(); - private ArrayList ids = new ArrayList(); - private World world; - private Route current; - - private String currentLocation; - - public DatabaseParser() { - super(); - } - - public World parseWorld(String worldName) throws IOException { - DatabaseParser.class.getClassLoader().getResource("main/resources/" + worldName + ".json"); + + public static World parseWorld(String worldName) throws IOException { + HashMap locations = new HashMap(); + ArrayList ids = new ArrayList(); + String startingLocation = null; + World world = null; + DatabaseParser.class.getClassLoader().getResource( + "src/main/resources/" + worldName + ".json"); String fileName = "src/main/resources/" + worldName + ".json"; JsonReader reader = new JsonReader(new FileReader(fileName)); reader.beginObject(); - while(reader.hasNext()) { + while (reader.hasNext()) { String name = reader.nextName(); - if(name.equals("name")) { + if (name.equals("name")) { world = new World(reader.nextString()); - } - else if(name.equals("locations")) { + } else if (name.equals("locations")) { reader.beginArray(); - while(reader.hasNext()) { + String lName = null; + String lDescription = null; + String lSplash = null; + while (reader.hasNext()) { reader.beginObject(); - while(reader.hasNext()) { + while (reader.hasNext()) { name = reader.nextName(); - if(name.equals("locname")) { - locations.put("foo", new Location(reader.nextString())); - Location foo = locations.remove("foo"); - currentLocation = foo.getName(); - locationNames.add(currentLocation); - locations.put(currentLocation, foo); - } - else if(name.equals("description")) { - locations.get(currentLocation).setDescription(reader.nextString()); - } - else if(name.equals("route_id")) { + if (name.equals("locname")) { + lName = reader.nextString(); + } else if (name.equals("description")) { + lDescription = reader.nextString(); + } else if (name.equals("splash")) { + lSplash = reader.nextString(); + Location locTemp = new Location(lName, + lDescription, lSplash); + locations.put(lName, locTemp); + } else if (name.equals("route_id")) { + reader.beginArray(); + while (reader.hasNext()) { + String curID = reader.nextString(); + if (!ids.contains(curID)) { + ids.add(curID); + } + } + reader.endArray(); + } else if (name.equals("inventory")) { reader.beginArray(); - while(reader.hasNext()) { - ids.add(reader.nextString()); + while (reader.hasNext()) { + String iName = null; + String iTypeName = null; + String iDescription = null; + String iSplash = null; + reader.beginObject(); + while (reader.hasNext()) { + name = reader.nextName(); + if (name.equals("name")) { + iName = reader.nextString(); + } else if (name.equals("type")) { + iTypeName = reader.nextString(); + } else if (name.equals("description")) { + iDescription = reader.nextString(); + } else if (name.equals("splash")) { + iSplash = reader.nextString(); + } + } + reader.endObject(); + Location l = locations.get(lName); + l.addToInventory( + ItemFactory.newActor(iName, iTypeName, + iDescription, iSplash)); } reader.endArray(); } @@ -55,42 +82,53 @@ else if(name.equals("route_id")) { reader.endObject(); } reader.endArray(); - } - else if(name.equals("starting_location")) { - world.setPointer(reader.nextString()); - } - else if(name.equals("route")) { + } else if (name.equals("starting_location")) { + startingLocation = reader.nextString(); + } else if (name.equals("route")) { reader.beginArray(); - while(reader.hasNext()) { + while (reader.hasNext()) { + String id = null; + String rName = null; + String rDescription = null; + String rSplash = null; + String rWhereIs = null; + String rDestination = null; reader.beginObject(); - while(reader.hasNext()) { + while (reader.hasNext()) { name = reader.nextName(); - if(name.equals("id")) { - current = new Route(reader.nextString()); - } - else if(name.equals("description")) { - current.setDescription(reader.nextString()); - } - else if(name.equals("accessor")) { - current.setAccessor(reader.nextString()); - } - else if(name.equals("from")) { - current.setFrom(reader.nextString()); - locations.get(current.getPlayer()).addRoute(current); - } - else if(name.equals("destination")) { - current.setDestination(locations.get(reader.nextString())); + if (name.equals("id")) { + id = reader.nextString(); + } else if (name.equals("name")) { + rName = reader.nextString(); + } else if (name.equals("description")) { + rDescription = reader.nextString(); + } else if (name.equals("splash")) { + rSplash = reader.nextString(); + } else if (name.equals("from")) { + rWhereIs = reader.nextString(); + } else if (name.equals("destination")) { + rDestination = reader.nextString(); } } + locations.get(rWhereIs).addRoute(rDescription, rName, + rSplash, locations.get(rDestination)); reader.endObject(); } reader.endArray(); } } reader.close(); - for(String l: locationNames) { - world.addLocation(locations.get(l)); + Iterator it = locations.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry pair = (Map.Entry)it.next(); + world.addLocation((Location)pair.getValue()); + it.remove(); + } + for(Location sL: world.getLocations()) { + if(sL.getName().equalsIgnoreCase(startingLocation)) { + world.setStartingLocation(sL); + } } - return world; + return world; } } diff --git a/src/main/java/org/vashonsd/pirateship/structure/DatabaseWriter.java b/src/main/java/org/vashonsd/pirateship/structure/DatabaseWriter.java index 730226d..90513e1 100644 --- a/src/main/java/org/vashonsd/pirateship/structure/DatabaseWriter.java +++ b/src/main/java/org/vashonsd/pirateship/structure/DatabaseWriter.java @@ -3,23 +3,28 @@ import java.io.*; import java.util.*; +import org.vashonsd.pirateship.interactions.Actor; + import com.google.gson.stream.*; public class DatabaseWriter { - private ArrayList writtenids = new ArrayList(); - private ArrayList checkedLocations = new ArrayList(); - - public DatabaseWriter() { - super(); - } - - public void worldWriter(World world) throws IOException { + + public static void worldWriter(World world) throws IOException { + ArrayList writtenids = new ArrayList(); + ArrayList checkedLocations = new ArrayList(); JsonWriter writer; - String fileName = "main/resources/" + world.getName() + ".json"; + String fileName = "src/main/resources/" + world.getName() + ".json"; File file = new File(fileName); - if(!file.exists() && file.isDirectory()) { + if(file.exists()) { + try { + boolean deleted = file.delete(); + } + catch(Exception e) { + e.printStackTrace(); + } + } + if (!file.exists()) { file.createNewFile(); - System.out.println("Created?"); } writer = new JsonWriter(new FileWriter(file)); writer.setIndent(" "); @@ -28,31 +33,48 @@ public void worldWriter(World world) throws IOException { writer.name("name").value(world.getName()); writer.name("locations"); writer.beginArray(); - for(Location l: world.getLocations()) { + for (Location l : world.getLocations()) { writer.beginObject(); writer.name("locname").value(l.getName()); writer.name("description").value(l.getDescription()); + writer.name("splash").value(l.getSplashText()); writer.name("route_id"); writer.beginArray(); - for(Route r: l.getRoutes()) { + for (Route r : l.getRoutes()) { writer.value(r.getId()); } writer.endArray(); + writer.name("inventory"); + writer.beginArray(); + for (Actor a : l.getAllItems()) { + if (!a.isTraversable()) { + writer.beginObject(); + writer.name("name").value(a.getName()); + writer.name("type").value(a.getTypeName()); + writer.name("description").value(a.getDescription()); + writer.name("splash").value(a.getSplashText()); + writer.endObject(); + } + } + writer.endArray(); writer.endObject(); } writer.endArray(); + writer.name("starting_location").value(world.getStartingLocation().getName()); writer.name("route"); writer.beginArray(); - for(Location l: world.getLocations()) { - for(Route r: l.getRoutes()) { - if(!(writtenids.contains(r.getId()))) { + for (Location l : world.getLocations()) { + for (Route r : l.getRoutes()) { + if (!(writtenids.contains(r.getId()))) { writtenids.add(r.getId()); writer.beginObject(); writer.name("id").value(r.getId()); - writer.name("description").value(r.getDescriptionNA()); - writer.name("accessor").value(r.getAccessor()); - writer.name("from").value(r.getPlayer()); - writer.name("destination").value(r.getDestination().getName()); + writer.name("name").value(r.getTypeName()); + writer.name("description").value(r.getDescription()); + writer.name("splash").value(r.getSplashText()); + writer.name("from").value(r.getLocation().getName()); + writer.name("destination").value( + r.getDestination().getName()); writer.endObject(); } } @@ -61,16 +83,13 @@ public void worldWriter(World world) throws IOException { writer.endArray(); writer.endObject(); System.out.println("World: " + world.getName() + " Saved!"); - } - catch(IOException e) { + } catch (IOException e) { e.printStackTrace(); System.out.println("Failed. IOException"); - } - finally { - try{ + } finally { + try { writer.close(); - } - catch(IOException e) { + } catch (IOException e) { e.printStackTrace(); System.out.println("Failed. IOException"); } diff --git a/src/main/java/org/vashonsd/pirateship/structure/Location.java b/src/main/java/org/vashonsd/pirateship/structure/Location.java index 06ae140..d88bd04 100644 --- a/src/main/java/org/vashonsd/pirateship/structure/Location.java +++ b/src/main/java/org/vashonsd/pirateship/structure/Location.java @@ -1,33 +1,45 @@ package org.vashonsd.pirateship.structure; +import java.util.ArrayList; + import org.vashonsd.pirateship.commands.TravelCommand; import org.vashonsd.pirateship.interactions.Actor; /** - * @author andy - * A location represents a single place in our world. + * @author andy A location represents a single place in our world. * - * Notice that a location does not "know" how you got there; it does not know what locations can get to it. - * It can, through the routes list, figure out what destinations it can go to. + * Notice that a location does not "know" how you got there; it does not + * know what locations can get to it. It can, through the routes list, + * figure out what destinations it can go to. */ public class Location extends Actor { - public Location(String name, String description, String splash) - { - super(name, "here", description, splash); - this.name = name; - this.description = description; - this.setTraversable(true); + private ArrayList routes; + + public Location(String name, String description, String splash) { + super(name, "here", description, splash); + routes = new ArrayList(); + this.name = name; + this.description = description; + this.setTraversable(true); } - - public void addRoute(String description, String accessor, String splash, Location dest) { + + public void addRoute(String description, String accessor, String splash, + Location dest) { Route r = new Route(accessor, description, splash, this, dest); r.enrollCommand(new TravelCommand(accessor, dest)); addToInventory(r); + routes.add(r); } - + + public ArrayList getRoutes() { + return routes; + } + /** - * Use this method to add something to a Location. To add a Route, use the addRoute method. + * Use this method to add something to a Location. To add a Route, use the + * addRoute method. + * * @param a */ public void addToLocation(Actor a) { diff --git a/src/main/java/org/vashonsd/pirateship/structure/WorldBuilder.java b/src/main/java/org/vashonsd/pirateship/structure/WorldBuilder.java index 37cc1d7..eb1046e 100644 --- a/src/main/java/org/vashonsd/pirateship/structure/WorldBuilder.java +++ b/src/main/java/org/vashonsd/pirateship/structure/WorldBuilder.java @@ -1,7 +1,5 @@ package org.vashonsd.pirateship.structure; -import java.io.IOException; - import org.vashonsd.pirateship.creature.CreatureFactory; import org.vashonsd.pirateship.interactions.*; import org.vashonsd.pirateship.minigame.*; @@ -37,13 +35,6 @@ else if (s.equals("Busytown")) } } - /* - public static World makeWorldByFile(String s) throws IOException { - DatabaseParser dp = new DatabaseParser(); - return dp.parseWorld(s); - } - */ - public static World busyWorld() { World w = new World("Busytown"); @@ -60,14 +51,12 @@ public static World busyWorld() main.addRoute("You can't see very far into the alley", "north", "A dark alley leads to the north", news); main.addRoute("The sign says type \"games\" for some games!", "games", "A sign says type \"games\" for some games!", gameRoom); main.addRoute("Go straight to jail", "prison", "You can also go to prison if you want.", prison); - //main.addRoute("Enter the Casino", "casino", casino); news.addRoute("You can return to City Hall", "south", "City Hall is to the south", main); soft.addRoute("The gravel walkway leads back to City Hall", "west", "Head west to go back to City Hall", main); chat.addRoute("It looks nice out there", "outside", "You could go back outside", main); gameRoom.addRoute("It's the way back", "back", "You could go back to City Hall.", main); prison.addRoute("Escape!", "escape", "You must type \"escape\" to escape!",main); - //casino.addRoute("Back to City Hall", "back", main); main.addToInventory(CreatureFactory.newCreature("eagle")); main.addToInventory(new StopWatch("stopwatch")); @@ -77,14 +66,13 @@ public static World busyWorld() gameRoom.addToInventory(new MinigameRunner("20Q")); - //gameRoom.addToInventory(new MinigameRunner("Blackjack")); gameRoom.addToInventory(new MinigameRunner("CC")); gameRoom.addToInventory(new MinigameRunner("GF")); gameRoom.addToInventory(new MinigameRunner("GuessCalc")); gameRoom.addToInventory(new MinigameRunner("math")); gameRoom.addToInventory(new MinigameRunner("GOPP")); gameRoom.addToInventory(new MinigameRunner("Shot")); - gameRoom.addToInventory(new MinigameRunner("Tic tac toe")); + gameRoom.addToInventory(new MinigameRunner("TTT")); w.addLocation(main); w.addLocation(chat); @@ -92,155 +80,9 @@ public static World busyWorld() w.addLocation(news); w.addLocation(gameRoom); w.addLocation(prison); - //w.addLocation(casino); - - -// gameRoom.addGame(new TwentyQuestionsFactory()); -// gameRoom.addGame(new CookieClickerFactory()); -// gameRoom.addGame(new MathFactory()); -// gameRoom.addGame(new GuessingCalculatorFactory()); -// gameRoom.addGame(new TicTacToeFactory()); -// gameRoom.addGame(new MinigameTwitterFactory()); -// gameRoom.addGame(new ShotgunFactory()); - -// casino.addGame(new GoFishFactory()); - - //prison.addGame(new PrisonEscapeFactory()); w.setStartingLocation(main); return w; } - - /* - public static World BBSWorld() - { - World w = new World("BBS"); - Location main = new Location("Main board", "Here you can view updates from the admins."); - Location chat = new Location("Chat Room", "Start a conversation!"); - Location soft = new Location("Software Exchange", "Come get your shareware!"); - Location news = new Location("News room", "This place is miserable."); - Location gameRoom = new Location("Game Room", "Play minigames!"); - - main.addRoute("Visit the chat room -->", "chat", chat); - main.addRoute("Shareware library -->", "soft", soft); - main.addRoute("Latest news", "news", news); - main.addRoute("Have fun in the Game Room", "games", gameRoom); - - news.addRoute("Back to the main board", "main", main); - soft.addRoute("Back to the main board", "main", main); - chat.addRoute("Back to the main board", "main", main); - gameRoom.addRoute("Back to the main board", "main", main); - - w.addLocation(main); - w.addLocation(chat); - w.addLocation(soft); - w.addLocation(news); - w.addLocation(gameRoom); - -// gameRoom.addGame(new TwentyQuestionsFactory()); -// gameRoom.addGame(new CookieClickerFactory()); -// gameRoom.addGame(new MathFactory()); -// gameRoom.addGame(new GuessingCalculatorFactory()); -// gameRoom.addGame(new TicTacToeFactory()); -// gameRoom.addGame(new MinigameTwitterFactory()); -// gameRoom.addGame(new ShotgunFactory()); - - w.setPointer(main); - -// gameRoom.addGame(new TwentyQuestionsFactory()); -// gameRoom.addGame(new CookieClickerFactory()); -// gameRoom.addGame(new MathFactory()); -// gameRoom.addGame(new GuessingCalculatorFactory()); -// gameRoom.addGame(new TicTacToeFactory()); -// gameRoom.addGame(new MinigameTwitterFactory()); -// gameRoom.addGame(new ShotgunFactory()); - - return w; - } - */ - - /* - public static World littleTown() { - World w = new World("Littletown"); - Location square = new Location("Town square", "It's bustling with excitment."); - Location florist = new Location("Florist stand", "Fresh flowers for sale!"); - Location baker = new Location("Baker's shop", "Bread, bagels, and buns all right here."); - Location clother = new Location("Tailorist", "Clothes for everybody folks."); - Location west = new Location("West Street", "A nice looking cobblestone road with houses lining it."); - Location houseJacob = new Location("Jacob's House", "A good sized oak door with a shining brass door handle."); - Location houseJacobLocked = new Location("The door is locked tight", "Must not be home."); - Location houseMary = new Location("Mary's House", "A small circular door with colorful painted designs."); - Location houseMaryInside = new Location("Mary's house is very bright with colors", "Mary is sobbing in the corner."); - Location houseMaryInsideTalk = new Location("She says through her tears", "My hampster died and i'm sad."); - Location houseMaryInsideTalkNice = new Location("Her tears dry up", "She starts to smile."); - Location houseMaryInsideTalkMean = new Location("She pushes you away", "You are forced to leave."); - - square.addRoute("The florist's stand is bright with colors", "florist", "Town square", florist); - square.addRoute("A warm aroma wafts from the bakery", "bakery", "Town square", baker); - square.addRoute("The tailor is hard at work mending a green shirt", "tailor", "Town square", clother); - square.addRoute("Neighbors talk and laugh in the street", "west", "Town square", west); - - west.addRoute("Visit Jacob's house", "jacob", "West Street", houseJacob); - west.addRoute("Visit Mary's house", "mary", "West Street", houseMary); - west.addRoute("Go back to the square", "back", "West Street", square); - - houseJacob.addRoute("Go inside", "open", "Jacob's House", houseJacobLocked); - houseJacobLocked.addRoute("Leave", "back", "The door is locked tight", west); - - houseMary.addRoute("Go inside", "open", "Mary's House", houseMaryInside); - houseMaryInside.addRoute("Talk to her", "talk", "Mary's house is very bright with colors", houseMaryInsideTalk); - houseMaryInsideTalk.addRoute("Comfort her", "comfort", "She says through her tears", houseMaryInsideTalkNice); - houseMaryInsideTalkNice.addRoute("Talk to her some more", "talk", "Her tears dry up", houseMaryInsideTalk); - houseMaryInsideTalkNice.addRoute("Leave", "leave", "Her tears dry up", west); - houseMaryInsideTalk.addRoute("Laugh in her face", "laugh", "She says through her tears", houseMaryInsideTalkMean); - houseMaryInsideTalkMean.addRoute("Leave", "leave", "She pushes you away", west); - houseMaryInside.addRoute("Leave", "back", "Mary's house is very bright with colors", west); - - florist.addRoute("Leave the florist's stand", "back", "Florist stand", square); - baker.addRoute("Leave the bakery", "back", "Baker's shop", square); - clother.addRoute("Leave the tailorist's", "back", "Tailorist", square); - square.addRoute("The florist's stand is bright with colors", "florist", florist); - square.addRoute("A warm aroma wafts from the bakery", "bakery", baker); - square.addRoute("The tailor is hard at work mending a green shirt", "tailor", clother); - square.addRoute("Neighbors talk and laugh in the street", "west", west); - - west.addRoute("Visit Jacob's house", "jacob", houseJacob); - west.addRoute("Visit Mary's house", "mary", houseMary); - west.addRoute("Go back to the square", "back", square); - - houseJacob.addRoute("Go inside", "open", houseJacobLocked); - houseJacobLocked.addRoute("Leave", "back", west); - - houseMary.addRoute("Go inside", "open", houseMaryInside); - houseMaryInside.addRoute("Talk to her", "talk", houseMaryInsideTalk); - houseMaryInsideTalk.addRoute("Comfort her", "comfort", houseMaryInsideTalkNice); - houseMaryInsideTalkNice.addRoute("Talk to her some more", "talk", houseMaryInsideTalk); - houseMaryInsideTalkNice.addRoute("Leave", "leave", west); - houseMaryInsideTalk.addRoute("Laugh in her face", "laugh", houseMaryInsideTalkMean); - houseMaryInsideTalkMean.addRoute("Leave", "leave", west); - houseMaryInside.addRoute("Leave", "back", west); - - florist.addRoute("Leave the florist's stand", "back", square); - baker.addRoute("Leave the bakery", "back", square); - clother.addRoute("Leave the tailorist's", "back", square); - - w.addLocation(square); - w.addLocation(florist); - w.addLocation(baker); - w.addLocation(clother); - w.addLocation(west); - w.addLocation(houseJacob); - w.addLocation(houseJacobLocked); - w.addLocation(houseMary); - w.addLocation(houseMaryInside); - w.addLocation(houseMaryInsideTalk); - w.addLocation(houseMaryInsideTalkNice); - w.addLocation(houseMaryInsideTalkMean); - - w.setPointer(square); - - return w; - } -*/ } diff --git a/src/main/resources/BBS.json b/src/main/resources/BBS.json deleted file mode 100644 index 8d2373b..0000000 --- a/src/main/resources/BBS.json +++ /dev/null @@ -1,79 +0,0 @@ -{ - "name": "BBS", - "locations": [ - { - "locname": "Main board", - "description": "Here you can view updates from the admins.", - "route_id": [ - "Main board - Chat Room", - "Main board - Software Exchange", - "Main board - News room" - ] - }, - { - "locname": "Chat Room", - "description": "Start a conversation!", - "route_id": [ - "Chat Room - Main board" - ] - }, - { - "locname": "Software Exchange", - "description": "Come get your shareware!", - "route_id": [ - "Software Exchange - Main board" - ] - }, - { - "locname": "News room", - "description": "This place is miserable.", - "route_id": [ - "News room - Main board" - ] - } - ], - "route": [ - { - "id": "Main board - Chat Room", - "description": "Visit the chat room -->", - "accessor": "chat", - "from": "Main board", - "destination": "Chat Room" - }, - { - "id": "Main board - Software Exchange", - "description": "Shareware library -->", - "accessor": "soft", - "from": "Main board", - "destination": "Software Exchange" - }, - { - "id": "Main board - News room", - "description": "Latest news", - "accessor": "news", - "from": "Main board", - "destination": "News room" - }, - { - "id": "Chat Room - Main board", - "description": "Back to the main board", - "accessor": "main", - "from": "Chat Room", - "destination": "Main board" - }, - { - "id": "Software Exchange - Main board", - "description": "Back to the main board", - "accessor": "main", - "from": "Software Exchange", - "destination": "Main board" - }, - { - "id": "News room - Main board", - "description": "Back to the main board", - "accessor": "main", - "from": "News room", - "destination": "Main board" - } - ] -} \ No newline at end of file diff --git a/src/main/resources/Busytown.json b/src/main/resources/Busytown.json index 1b8e818..9a06d7b 100644 --- a/src/main/resources/Busytown.json +++ b/src/main/resources/Busytown.json @@ -2,77 +2,224 @@ "name": "Busytown", "locations": [ { - "locname": "City Hall", - "description": "You stand before a brick building with Greek gods painted on it", + "locname": "City Hall Lobby", + "description": "Giant columns rise up 100 feet.", + "splash": "You are in the City Hall Lobby. It is majestic.", "route_id": [ - "City HallCity Hall Lobby", - "City HallHappy Park", - "City HallDead End Street" - ] + "City Hall Lobby - City Hall" + ], + "inventory": [] }, { - "locname": "City Hall Lobby", - "description": "Giant columns rise up 100 feet.", + "locname": "Dead End Street", + "description": "This place is miserable.", + "splash": "Uh oh! Dead end.", "route_id": [ - "City Hall LobbyCity Hall" + "Dead End Street - City Hall" + ], + "inventory": [] + }, + { + "locname": "City Hall", + "description": "It's a brick building", + "splash": "You stand before a brick building with Greek gods painted on it", + "route_id": [ + "City Hall - City Hall Lobby", + "City Hall - Happy Park", + "City Hall - Dead End Street", + "City Hall - Game Room", + "City Hall - Pig Prison" + ], + "inventory": [ + { + "name": "Daniel the Eagle", + "type": "eagle", + "description": "It is an eagle with sharp talons", + "splash": "An eagle soars above" + }, + { + "name": "stopwatch", + "type": "stopwatch", + "description": "You hear a stopwatch ticking", + "splash": "You hear a stopwatch" + }, + { + "name": "Little Larry Lizard", + "type": "lizard", + "description": "It is sleek and green", + "splash": "There is a lizard here." + }, + { + "name": "Jake the Dog", + "type": "dog", + "description": "It is a loyal dog who will stay by your side", + "splash": "A dog wags its tail" + }, + { + "name": "bandage", + "type": "bandage", + "description": "bandage", + "splash": "There is a bandage here." + } ] }, { "locname": "Happy Park", "description": "This happy place has birds singing, people playing.", + "splash": "Welcome to Happy Park! What a happy place.", "route_id": [ - "Happy ParkCity Hall" - ] + "Happy Park - City Hall" + ], + "inventory": [] }, { - "locname": "Dead End Street", - "description": "This place is miserable.", + "locname": "Pig Prison", + "description": "You done it now sonny", + "splash": "It's Pig Prison, the worst place ever.", "route_id": [ - "Dead End StreetCity Hall" + "Pig Prison - City Hall" + ], + "inventory": [] + }, + { + "locname": "Game Room", + "description": "Play minigames!", + "splash": "You are in the Game Room. Bells ring and machines whir.", + "route_id": [ + "Game Room - City Hall" + ], + "inventory": [ + { + "name": "Twenty Questions", + "type": "20Q", + "description": "I'll pick a number between 1 and 1,000. You have 20 questions to guess it.", + "splash": " I'll pick a number between 1 and 1,000. You have 20 questions to guess it.[20Q]" + }, + { + "name": "Cookie Clicker", + "type": "CC", + "description": "You click a cookie to gain cookies.", + "splash": " You click a cookie to gain cookies.[CC]" + }, + { + "name": "Go Fish", + "type": "GF", + "description": "Play a game of Go Fish against the computer.", + "splash": " Play a game of Go Fish against the computer.[GF]" + }, + { + "name": "Guessing Calculator", + "type": "GuessCalc", + "description": "I'll give you two whole numbers, and you tell me what their sum is.", + "splash": " I'll give you two whole numbers, and you tell me what their sum is.[GuessCalc]" + }, + { + "name": "Solve the math problem.", + "type": "math", + "description": "Solve the math problem.", + "splash": " Solve the math problem.[math]" + }, + { + "name": "Get Out of Pig Prison", + "type": "GOPP", + "description": "Convice your pig warden to let you out of jail", + "splash": " Convice your pig warden to let you out of jail[GOPP]" + }, + { + "name": "Shotgun", + "type": "Shot", + "description": "Reload, Block, or Shoot, but time it right or you're dead", + "splash": " Reload, Block, or Shoot, but time it right or you're dead[Shot]" + }, + { + "name": "Tic Tac Toe", + "type": "TTT", + "description": "Play tic tac toe against me, the computer. Don't worry, I'm not very good.", + "splash": " Play tic tac toe against me, the computer. Don't worry, I'm not very good.[TTT]" + } ] } ], + "starting_location": "City Hall", "route": [ { - "id": "City HallCity Hall Lobby", - "description": "You see a heavy door with a brass handle", - "accessor": "open", + "id": "City Hall Lobby - City Hall", + "name": "outside", + "description": "It looks nice out there", + "splash": "You could go back outside", + "from": "City Hall Lobby", + "destination": "City Hall" + }, + { + "id": "Dead End Street - City Hall", + "name": "south", + "description": "You can return to City Hall", + "splash": "City Hall is to the south", + "from": "Dead End Street", + "destination": "City Hall" + }, + { + "id": "City Hall - City Hall Lobby", + "name": "open", + "description": "This door has a brass handle. You could open it.", + "splash": "You see a heavy door with a brass handle", "from": "City Hall", "destination": "City Hall Lobby" }, { - "id": "City HallHappy Park", - "description": "A gravel walkway leads to a park", - "accessor": "east", + "id": "City Hall - Happy Park", + "name": "east", + "description": "You can see a park off to the east", + "splash": "A gravel walkway leads east", "from": "City Hall", "destination": "Happy Park" }, { - "id": "City HallDead End Street", - "description": "You can just barely spot a dark alley", - "accessor": "north", + "id": "City Hall - Dead End Street", + "name": "north", + "description": "You can't see very far into the alley", + "splash": "A dark alley leads to the north", "from": "City Hall", "destination": "Dead End Street" }, { - "id": "City Hall LobbyCity Hall", - "description": "It's time to head back outside", - "accessor": "open", - "from": "City Hall Lobby", - "destination": "City Hall" + "id": "City Hall - Game Room", + "name": "games", + "description": "The sign says type \"games\" for some games!", + "splash": "A sign says type \"games\" for some games!", + "from": "City Hall", + "destination": "Game Room" }, { - "id": "Happy ParkCity Hall", + "id": "City Hall - Pig Prison", + "name": "prison", + "description": "Go straight to jail", + "splash": "You can also go to prison if you want.", + "from": "City Hall", + "destination": "Pig Prison" + }, + { + "id": "Happy Park - City Hall", + "name": "west", "description": "The gravel walkway leads back to City Hall", - "accessor": "west", + "splash": "Head west to go back to City Hall", "from": "Happy Park", "destination": "City Hall" }, { - "id": "Dead End StreetCity Hall", - "description": "You can return to City Hall", - "accessor": "south", - "from": "Dead End Street", + "id": "Pig Prison - City Hall", + "name": "escape", + "description": "Escape!", + "splash": "You must type \"escape\" to escape!", + "from": "Pig Prison", + "destination": "City Hall" + }, + { + "id": "Game Room - City Hall", + "name": "back", + "description": "It's the way back", + "splash": "You could go back to City Hall.", + "from": "Game Room", "destination": "City Hall" } ] diff --git a/src/main/resources/Littletown.json b/src/main/resources/Littletown.json new file mode 100644 index 0000000..824d360 --- /dev/null +++ b/src/main/resources/Littletown.json @@ -0,0 +1,239 @@ +{ + "name": "Littletown", + "locations": [ + { + "locname": "Town square", + "description": "It's bustling with excitment.", + "route_id": [ + "Town square - Florist stand", + "Town square - Baker's shop", + "Town square - Tailorist", + "Town square - West Street" + ] + }, + { + "locname": "Florist stand", + "description": "Fresh flowers for sale!", + "route_id": [ + "Florist stand - Town square" + ] + }, + { + "locname": "Baker's shop", + "description": "Bread, bagels, and buns all right here.", + "route_id": [ + "Baker's shop - Town square" + ] + }, + { + "locname": "Tailorist", + "description": "Clothes for everybody folks.", + "route_id": [ + "Tailorist - Town square" + ] + }, + { + "locname": "West Street", + "description": "A nice looking cobblestone road with houses lining it.", + "route_id": [ + "West Street - Jacob's House", + "West Street - Mary's House", + "West Street - Town square" + ] + }, + { + "locname": "Jacob's House", + "description": "A good sized oak door with a shining brass door handle.", + "route_id": [ + "Jacob's House - The door is locked tight" + ] + }, + { + "locname": "The door is locked tight", + "description": "Must not be home.", + "route_id": [ + "The door is locked tight - West Street" + ] + }, + { + "locname": "Mary's House", + "description": "A small circular door with colorful painted designs.", + "route_id": [ + "Mary's House - Mary's house is very bright with colors" + ] + }, + { + "locname": "Mary's house is very bright with colors", + "description": "Mary is sobbing in the corner.", + "route_id": [ + "Mary's house is very bright with colors - She says through her tears", + "Mary's house is very bright with colors - West Street" + ] + }, + { + "locname": "She says through her tears", + "description": "My hampster died and i'm sad.", + "route_id": [ + "She says through her tears - Her tears dry up", + "She says through her tears - She pushes you away" + ] + }, + { + "locname": "Her tears dry up", + "description": "She starts to smile.", + "route_id": [ + "Her tears dry up - She says through her tears", + "Her tears dry up - West Street" + ] + }, + { + "locname": "She pushes you away", + "description": "You are forced to leave.", + "route_id": [ + "She pushes you away - West Street" + ] + } + ], + "route": [ + { + "id": "Town square - Florist stand", + "description": "The florist's stand is bright with colors", + "accessor": "florist", + "from": "Town square", + "destination": "Florist stand" + }, + { + "id": "Town square - Baker's shop", + "description": "A warm aroma wafts from the bakery", + "accessor": "bakery", + "from": "Town square", + "destination": "Baker's shop" + }, + { + "id": "Town square - Tailorist", + "description": "The tailor is hard at work mending a green shirt", + "accessor": "tailor", + "from": "Town square", + "destination": "Tailorist" + }, + { + "id": "Town square - West Street", + "description": "Neighbors talk and laugh in the street", + "accessor": "west", + "from": "Town square", + "destination": "West Street" + }, + { + "id": "Florist stand - Town square", + "description": "Leave the florist's stand", + "accessor": "back", + "from": "Florist stand", + "destination": "Town square" + }, + { + "id": "Baker's shop - Town square", + "description": "Leave the bakery", + "accessor": "back", + "from": "Baker's shop", + "destination": "Town square" + }, + { + "id": "Tailorist - Town square", + "description": "Leave the tailorist's", + "accessor": "back", + "from": "Tailorist", + "destination": "Town square" + }, + { + "id": "West Street - Jacob's House", + "description": "Visit Jacob's house", + "accessor": "jacob", + "from": "West Street", + "destination": "Jacob's House" + }, + { + "id": "West Street - Mary's House", + "description": "Visit Mary's house", + "accessor": "mary", + "from": "West Street", + "destination": "Mary's House" + }, + { + "id": "West Street - Town square", + "description": "Go back to the square", + "accessor": "back", + "from": "West Street", + "destination": "Town square" + }, + { + "id": "Jacob's House - The door is locked tight", + "description": "Go inside", + "accessor": "open", + "from": "Jacob's House", + "destination": "The door is locked tight" + }, + { + "id": "The door is locked tight - West Street", + "description": "Leave", + "accessor": "back", + "from": "The door is locked tight", + "destination": "West Street" + }, + { + "id": "Mary's House - Mary's house is very bright with colors", + "description": "Go inside", + "accessor": "open", + "from": "Mary's House", + "destination": "Mary's house is very bright with colors" + }, + { + "id": "Mary's house is very bright with colors - She says through her tears", + "description": "Talk to her", + "accessor": "talk", + "from": "Mary's house is very bright with colors", + "destination": "She says through her tears" + }, + { + "id": "Mary's house is very bright with colors - West Street", + "description": "Leave", + "accessor": "back", + "from": "Mary's house is very bright with colors", + "destination": "West Street" + }, + { + "id": "She says through her tears - Her tears dry up", + "description": "Comfort her", + "accessor": "comfort", + "from": "She says through her tears", + "destination": "Her tears dry up" + }, + { + "id": "She says through her tears - She pushes you away", + "description": "Laugh in her face", + "accessor": "laugh", + "from": "She says through her tears", + "destination": "She pushes you away" + }, + { + "id": "Her tears dry up - She says through her tears", + "description": "Talk to her some more", + "accessor": "talk", + "from": "Her tears dry up", + "destination": "She says through her tears" + }, + { + "id": "Her tears dry up - West Street", + "description": "Leave", + "accessor": "leave", + "from": "Her tears dry up", + "destination": "West Street" + }, + { + "id": "She pushes you away - West Street", + "description": "Leave", + "accessor": "leave", + "from": "She pushes you away", + "destination": "West Street" + } + ] +} \ No newline at end of file diff --git a/main/resources/New York.json b/src/main/resources/New York.json similarity index 100% rename from main/resources/New York.json rename to src/main/resources/New York.json