diff --git "a/Gantt-projektplanl\303\246gger.xlsx" "b/Gantt-projektplanl\303\246gger.xlsx" index 6816c97..06a495b 100644 Binary files "a/Gantt-projektplanl\303\246gger.xlsx" and "b/Gantt-projektplanl\303\246gger.xlsx" differ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4daba56 --- /dev/null +++ b/Makefile @@ -0,0 +1,29 @@ +# Define variables +SRC_DIR = woz +OUT_DIR = class_files +SRCS := $(wildcard $(SRC_DIR)/*.java) +CLASSES := $(patsubst $(SRC_DIR)/%.java,$(OUT_DIR)/%.class,$(SRCS)) +JAVAC = javac +MKDIR_P = mkdir -p +MAIN_CLASS = woz.Game + +# Default target to compile all .java files +all: $(OUT_DIR) $(CLASSES) + +# Create the output directory if it doesn't exist +$(OUT_DIR): + $(MKDIR_P) $(OUT_DIR) + +# Compile .java files into .class files +$(OUT_DIR)/%.class: $(SRC_DIR)/%.java + $(JAVAC) -d $(OUT_DIR) $< + +# Run the Java program +run: all + java -cp $(OUT_DIR) $(MAIN_CLASS) + +# Clean target to remove compiled .class files +clean: + rm -rf $(OUT_DIR) + +.PHONY: all run clean diff --git a/woz.zip b/woz.zip deleted file mode 100644 index 4ec076b..0000000 Binary files a/woz.zip and /dev/null differ diff --git a/woz/BaseCommand.class b/woz/BaseCommand.class new file mode 100644 index 0000000..63a74b1 Binary files /dev/null and b/woz/BaseCommand.class differ diff --git a/woz/BaseCommand.java b/woz/BaseCommand.java index c393afa..9f6d396 100644 --- a/woz/BaseCommand.java +++ b/woz/BaseCommand.java @@ -2,7 +2,15 @@ */ class BaseCommand { - String description = "Undocumented"; + String description; + + BaseCommand(String description) { + this.description = description; + } + + BaseCommand() { + description = "Undocumented"; + } protected boolean guardEq (String[] parameters, int bound) { return parameters.length!=bound; diff --git a/woz/Command.class b/woz/Command.class new file mode 100644 index 0000000..7090229 Binary files /dev/null and b/woz/Command.class differ diff --git a/woz/CommandExit.class b/woz/CommandExit.class new file mode 100644 index 0000000..dcb5636 Binary files /dev/null and b/woz/CommandExit.class differ diff --git a/woz/CommandExit.java b/woz/CommandExit.java index 79688ed..0ec6cd5 100644 --- a/woz/CommandExit.java +++ b/woz/CommandExit.java @@ -2,6 +2,10 @@ */ class CommandExit extends BaseCommand implements Command { + CommandExit() { + description = "Stop spillet"; + } + @Override public void execute (Context context, String command, String parameters[]) { context.makeDone(); diff --git a/woz/CommandGo.class b/woz/CommandGo.class new file mode 100644 index 0000000..aaaf358 Binary files /dev/null and b/woz/CommandGo.class differ diff --git a/woz/CommandHelp.class b/woz/CommandHelp.class new file mode 100644 index 0000000..839637d Binary files /dev/null and b/woz/CommandHelp.class differ diff --git a/woz/CommandResetDay.class b/woz/CommandResetDay.class new file mode 100644 index 0000000..13c76d8 Binary files /dev/null and b/woz/CommandResetDay.class differ diff --git a/woz/CommandResetDay.java b/woz/CommandResetDay.java new file mode 100644 index 0000000..890ee52 --- /dev/null +++ b/woz/CommandResetDay.java @@ -0,0 +1,11 @@ +class CommandResetDay extends BaseCommand implements Command { + + public CommandResetDay(){ + description = "Reset the day"; + } + @Override + public void execute (Context context, String command, String parameters[]) { + System.out.println("Resetting the day"); + context.resetDay(); + } +} \ No newline at end of file diff --git a/woz/CommandRoomAction.class b/woz/CommandRoomAction.class new file mode 100644 index 0000000..7369753 Binary files /dev/null and b/woz/CommandRoomAction.class differ diff --git a/woz/CommandRoomAction.java b/woz/CommandRoomAction.java new file mode 100644 index 0000000..9878765 --- /dev/null +++ b/woz/CommandRoomAction.java @@ -0,0 +1,112 @@ +/* Command for handlign actions in a room + */ + +class CommandRoomAction extends BaseCommand implements Command { + + Player player; + + + CommandRoomAction (String description) { + super(String.format("Rumhandlinger: %s", description)); + player = Game.context.getPlayer(); + + } + + + public void pickup(Context context, String[] parameters) { + + //we get the player, our current location and the amount of trash present + Space cspace = context.getCurrent(); + int amountPresent = cspace.getGeneratedTrash(); + + //if the pickup-command has 1 parameter (amount of trash to collect) we do as follows + if (!guardEq(parameters, 1)) { + int amount = Integer.parseInt(parameters[0]); //parameters[] is a string array which we convert to int + + if (amount > amountPresent) {//if you ask to collect more trah than present: + System.out.printf("%nSå meget skrald er der ikke! Der er %d", amountPresent); + } + else {//otherwise we add the trash to inventory and set the amount of trash in the location after pickup + player.addToInventory("trash", amount); + cspace.setGeneratedTrash(amountPresent - amount); + System.out.printf("%nDu har samlet %d skrald op - nu har du " + player.getInventory() + " i din taske!", amount); + } + } + else if (!guardEq(parameters, 0)) {//if you only type "pickup": + player.addToInventory("trash", amountPresent); + cspace.setGeneratedTrash(0); + System.out.printf("%nDu har samlet alt skrald op - nu har du " + player.getInventory() + " i din taske!"); + } else { + context.youStupid(); + } + } + + // Hint can be called from everywhere + public void hint(Context context, String[] parameters) { + if (guardEq(parameters, 0)) { + context.youStupid(); + return; + } + System.out.println("Congratulations, you have recieved a hint"); + } + + //Buy command can be executed from shop (butik). this is checked in registry w baseCommands and roomCommands + public void buy(Context context, String[] parameters) { + if (guardEq(parameters, 1)) { + context.youStupid(); + return; + } + context.buyExecuter(parameters);//calls buyExecuter from context who will peform the necessary actions + + } + + //command to sell trash valid in shop (shouldn't it be valid at genbrugsstation only?) + public void sell(Context context, String[] parameters) { + if (guardEq(parameters, 1)) { + context.youStupid(); + return; + }else{ + player.removeFromInventory("trash", Integer.parseInt(parameters[0])); + System.out.println(player.getInventory()); + } + System.out.printf("%nDu har solgt %s bunker skrald%n", parameters[0]); + } + + + //default action for commands + public void default_(Context context, String command, String[] parameters) { + if (guardEq(parameters, 0)) { + context.youStupid(); + return; + } + System.out.println("From default: Have not implemented that command yet :))"); + } + + @Override + public void execute (Context context, String command, String[] parameters) { + switch(command) { + + case "pickup" : + pickup(context, parameters); + break; + + case "hint" : + hint(context, parameters); + break; + + case "sell" : + sell(context, parameters); + break; + + case "buy" : + buy(context, parameters); + break; + + default : + default_(context, command, parameters); + + } + + context.getCurrent().updateExits(); + } +} diff --git a/woz/CommandUnknown.class b/woz/CommandUnknown.class new file mode 100644 index 0000000..ba1e63d Binary files /dev/null and b/woz/CommandUnknown.class differ diff --git a/woz/Commandsaveload.java b/woz/Commandsaveload.java new file mode 100644 index 0000000..b587cd3 --- /dev/null +++ b/woz/Commandsaveload.java @@ -0,0 +1,71 @@ +import java.io.*; +import java.util.*; + +class Commandsaveload extends BaseCommand implements Command { + private final String fileName; // This variable stores the name of the file where we save and read variables. + private final Map variables; // Use a LinkedHashMap to preserve the order + + // Constructor to initialize the class with a file name. + public Commandsaveload(String fileName) { + this.fileName = fileName; + variables = new LinkedHashMap<>(); + } + + // Method to save a variable and its value to the text file. + public void save(String variableName, String variableValue) { + // Read existing variables, overwrite the file, and then add the new variable. + variables.put(variableName, variableValue); + + try (PrintWriter writer = new PrintWriter(new FileWriter(fileName, false))) { + for (String key : variables.keySet()) { + writer.println(key + "=" + variables.get(key)); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + // Method to read variables from the text file and store them in a map. + public Map load() { + Map variables = new LinkedHashMap<>(); + + try (BufferedReader reader = new BufferedReader(new FileReader(fileName)) ) { + // Read lines from the file and split them into variable name and value. + reader.lines().map(line -> line.split("=", 2)) + .filter(parts -> parts.length == 2) + .forEach(parts -> variables.put(parts[0], parts[1])); + } catch (IOException e) { + e.printStackTrace(); + // Handle any errors that occur during file reading, such as if the file doesn't exist. + } + + return variables; + } + + @Override + public void execute (Context context, String command, String[] parameters) { + + Commandsaveload Commandsaveload = new Commandsaveload("variables.txt"); + + switch(command) { + + case "save": + + + // Save variables + Commandsaveload.save("name", "Tom Smith"); + Commandsaveload.save("age", "34"); + Commandsaveload.save("city", "New Amsterdam"); + Commandsaveload.save("city status", "Polluted"); + Commandsaveload.save("lake status", "5 Trash"); + + break; + + case "load": + // Read and print variables + Map savedVariables = Commandsaveload.load(); + savedVariables.forEach((key, value) -> System.out.println(key + " = " + value)); + break; + } + } +} diff --git a/woz/Context.class b/woz/Context.class new file mode 100644 index 0000000..0799901 Binary files /dev/null and b/woz/Context.class differ diff --git a/woz/Context.java b/woz/Context.java index 919cab9..a1502b8 100644 --- a/woz/Context.java +++ b/woz/Context.java @@ -1,21 +1,93 @@ /* Context class to hold all context relevant to a session. */ +import java.util.Map; +import java.util.HashMap; + class Context { - Space current; - boolean done = false; - - Context (Space node) { + + private Space current; + private Player player; + private boolean done = false; + private int day; + + Context (Space node, Player player) { current = node; + this.player = player; + day = 1; + } + + //resets amount of generated trash, the handleRoom(), increments the day and transitions to "Kontor" + + void resetDay(){ + World.park.setGeneratedTrash((int)(Math.random()*(15 - 1) + 1)); + World.bymidte.setGeneratedTrash((int)(Math.random()*(15 - 1) + 1)); + World.hospital.setGeneratedTrash((int)(Math.random()*(15 - 1) + 1)); + + World.park.makeHandled(); + World.bymidte.makeHandled(); + World.hospital.makeHandled(); + World.genbrugsstation.makeHandled(); + World.butik.makeHandled(); + + day++; + + transition("kontor");//man "vågner op" i kontoret igen + + + } + + public int getDay(){//gets the day-number + return day; + } + + + //checks if all available actions for the day are done + public boolean isDayDone(Space s1, Space s2, Space s3, Space s4, Space s5){ + if((s1.isHandled && s2.isHandled && s3.isHandled && s4.isHandled && s5.isHandled)){ + return true; + }else{ + return false; + } } public Space getCurrent() { return current; } + + public Player getPlayer() { + return player; + } + + public void buyExecuter(String[] parameters) { + String item = parameters[0]; //gets the parameter from command (what to buy) + Map lowerExtensions = current.getExtensions(); + + if (containsKey(lowerExtensions.keySet().toArray(new String[0]), item)) { + //checks if the item from the terminal is a valid product in the shop + + int[] priceXP = lowerExtensions.get(item); //the value belonging to the item name is a 2D array containg price and xp + + if (player.canAfford(priceXP[0])) { + //Add to inventory + player.addToInventory(item, 1); + player.subtractMoney(priceXP[0]); + player.addPoints(priceXP[1]); + + System.out.printf("%nDu har købt %s. Godt gået!", item); + + } else { + System.out.println("Du har ikke råd til denne udvidelse"); + } + } else { + System.out.println("Denne udvidelse eksisterer ikke i shoppen"); + } + System.out.println("inventory: " + player.getInventory()); + } public void transition (String direction) { Space next = current.followEdge(direction); - if (next==null) { + if (next == null) { System.out.println("You are confused, and walk in a circle looking for '"+direction+"'. In the end you give up 😩"); } else { current.goodbye(); @@ -23,6 +95,10 @@ public void transition (String direction) { current.welcome(); } } + + public void youStupid () { + System.out.println("You are an idiot, and have used this command wrong"); + } public void makeDone () { done = true; @@ -31,5 +107,20 @@ public void makeDone () { public boolean isDone () { return done; } -} +//Helpers + + + private boolean containsKey(String[] hm, String itemName) { + //checks if the itemName is in the array + for (String name : hm) { + if (itemName.equals(name.toLowerCase().trim())) { + return true; + } + } + return false; + } + + + +} diff --git a/woz/Game.class b/woz/Game.class new file mode 100644 index 0000000..0b6f8db Binary files /dev/null and b/woz/Game.class differ diff --git a/woz/Game.java b/woz/Game.java index 7f58349..054c4ab 100644 --- a/woz/Game.java +++ b/woz/Game.java @@ -4,32 +4,50 @@ import java.util.Scanner; class Game { - static World world = new World(); - static Context context = new Context(world.getEntry()); - static Command fallback = new CommandUnknown(); + static World world = new World(); + static Player player = new Player(); + static Context context = new Context(world.getEntry(), player); + static Command fallback = new CommandUnknown(); static Registry registry = new Registry(context, fallback); - static Scanner scanner = new Scanner(System.in); + static Scanner scanner = new Scanner(System.in); + private static void initRegistry () { Command cmdExit = new CommandExit(); registry.register("exit", cmdExit); registry.register("quit", cmdExit); registry.register("bye", cmdExit); + //added commands: + registry.register("pickup", new CommandRoomAction("Saml skrald op")); + registry.register("sell", new CommandRoomAction("Sælg dit skrald")); + registry.register("buy", new CommandRoomAction("Køb udvidelser til din by")); + registry.register("hint", new CommandRoomAction("Få hjælp til at forstå dine muligheder")); + registry.register("status", new CommandRoomAction("Vis en statusoversigt over din by")); registry.register("go", new CommandGo()); registry.register("help", new CommandHelp(registry)); + registry.register("reset", new CommandResetDay()); + registry.register("save", new Commandsaveload("Gem spillet")); + registry.register("load", new Commandsaveload("load spillet")); + } public static void main (String args[]) { - System.out.println("Welcome to the World of Zuul!"); + System.out.println("Velkommen til din by, her er du borgmester! Gør dit bedste for at tage bæredygtige beslutninger!"); initRegistry(); context.getCurrent().welcome(); - - while (context.isDone()==false) { + + while (context.isDone() == false) { + System.out.print("> "); String line = scanner.nextLine(); registry.dispatch(line); + + if(context.isDayDone(world.park, world.hospital, world.bymidte, world.butik, world.genbrugsstation)){ + System.out.println("Der er ikke mere, du kan gøre i dag. Du kan gå til næste dag ved at skrive 'reset'."); + } } - System.out.println("Game Over 😥"); + + System.out.println("Game Over."); } } diff --git a/woz/InteractableSpace.java b/woz/InteractableSpace.java new file mode 100644 index 0000000..9eeccd0 --- /dev/null +++ b/woz/InteractableSpace.java @@ -0,0 +1,7 @@ +public class InteractableSpace { + String name; + + InteractableSpace(String name) { + this.name = name; + } +} \ No newline at end of file diff --git a/woz/Node.class b/woz/Node.class new file mode 100644 index 0000000..44c0487 Binary files /dev/null and b/woz/Node.class differ diff --git a/woz/Node.java b/woz/Node.java index 27a03c3..864d889 100644 --- a/woz/Node.java +++ b/woz/Node.java @@ -1,8 +1,7 @@ /* Node class for modeling graphs */ -import java.util.HashMap; -import java.util.Map; +import java.util.*; class Node { String name; diff --git a/woz/Player.class b/woz/Player.class new file mode 100644 index 0000000..de7b1f8 Binary files /dev/null and b/woz/Player.class differ diff --git a/woz/Player.java b/woz/Player.java new file mode 100644 index 0000000..868f4ba --- /dev/null +++ b/woz/Player.java @@ -0,0 +1,109 @@ + +import java.util.Map; +import java.util.HashMap; + +class Player{ + private int level; + private int points; + private int money; + private int trash; + HashMap inventory; + + + private final int LEVEL1 = 10; //level 1 når point er mellem 0 og 9 + private final int LEVEL2 = 20; //level 2 når point er mellem 10 og 19 + private final int LEVEL3 = 30; //level 3 når point er mellem 20 og 29 + private final int LEVEL4 = 40; //level 4 når point er mellem 30 og 39 + private final int LEVEL5 = 50; //level 5 når point er mellem 40 og 49 + + public Player(){ + level = 1; + points = 0; + money = 200; + inventory = new HashMap(); + } + + public void addToInventory(String itemName, int amount) { //adds trash to player inventory + if(inventory.containsKey(itemName)){ + inventory.put(itemName, inventory.get(itemName) + amount) ; + }else{ + inventory.put(itemName, Integer.valueOf(amount)); + } + } + + public void removeFromInventory(String itemName, int amount){ + if(inventory.containsKey(itemName) && amount <= inventory.get(itemName)){//hashmap function, not our containsKey + //checks if we actually can remove the given amount from inventory + + inventory.put(itemName, inventory.get(itemName) - amount); + }else{ + System.out.println("det er ikke muligt"); + } + } + + public HashMap getInventory(){ + return inventory; + } + + + + public int getTrash() { + return trash; + } + + void addPoints(int amount){//add points /xp after buying from the shop + points += amount; + } + + void addMoney(int amount){//earn money by selling trash + money += amount; + } + + + void subtractMoney(int amount){//subtract money from player + if(canAfford(amount)){ //checks if the player has enough money + money -= amount; + }else{ + System.out.printf("Det har du ikke råd til. Du har %d penge på din konto", money); + } + } + + boolean canAfford(int price) { + return (price <= getMoney() ? true : false); + } + + public int getPoints(){ + return points; + } + + public int getMoney(){ + return money; + } + + public int getLevel(){ + return level; + } + + public void getPlayerStatus(){ + System.out.println("Level: " + level + ", XP: " + points + ", money: " + money + " on day " + Game.context.getDay()); + } + + + void levelUp(int points){ + if(points > 0 && points < LEVEL1){ + level = 1; + }else if (points > LEVEL1 && points < LEVEL2){ + level = 2; + }else if (points > LEVEL2 && points < LEVEL3){ + level = 3; + }else if (points > LEVEL3 && points < LEVEL4){ + level = 4; + }else if (points > LEVEL4 && points < LEVEL5){ + level = 5; + } + } + + + + +} \ No newline at end of file diff --git a/woz/Registry.class b/woz/Registry.class new file mode 100644 index 0000000..ea52130 Binary files /dev/null and b/woz/Registry.class differ diff --git a/woz/Registry.java b/woz/Registry.java index 7118217..7e7944f 100644 --- a/woz/Registry.java +++ b/woz/Registry.java @@ -5,9 +5,12 @@ import java.util.Map; class Registry { - Context context; + Context context; Command fallback; - Map commands = new HashMap(); + Map commands = new HashMap(); //key-value map of String name of command and the belonging command + + //Get basecommands from commands + String[] baseCommands = {"exit", "bye", "quit", "help", "go", "reset", "save", "load"}; Registry (Context context, Command fallback) { this.context = context; @@ -19,11 +22,17 @@ public void register (String name, Command command) { } public void dispatch (String line) { - String[] elements = line.split(" "); - String command = elements[0]; - String[] parameters = getParameters(elements); - Command handler = getCommand(command); - (handler==null ? fallback : handler).execute(context, command, parameters); + String[] elements = line.toLowerCase().split(" "); //splits the terminal command by " " and puts the strings in an array + String command = elements[0]; //command is the first element of the array + String[] parameters = getParameters(elements); //creates a new array for the parameters from the elements-array + Command handler = getCommand(command); //retrieves the command from the list of commands + ((context.getCurrent().isCommandPossible(command) && handler != null) || isInBaseCommands(command) ? handler : fallback).execute(context, command, parameters); + /* + ^^ checks if the command is valid (depending on the location), and checks the handler is not empty (there is an actual command) + or + if the command is a base command, call execute on handler, otherwise call execute on fallback + */ + } public Command getCommand (String commandName) { @@ -33,10 +42,19 @@ public Command getCommand (String commandName) { public String[] getCommandNames () { return commands.keySet().toArray(new String[0]); } + + public boolean isInBaseCommands(String cmd) { + for (String command : baseCommands) { + if (cmd.equals(command)) { + return true; + } + } return false; + } // helpers private String[] getParameters (String[] input) { + //returns a string array containg only the parameters (no command) String[] output = new String[input.length-1]; for (int i=0 ; i commands = new ArrayList(); + boolean isHandled; + private Map extensions; + private int generatedTrash; + Space (String name) { super(name); + isHandled = false; + extensions = new HashMap<>(); //laver et key-value map, så hhv pris og navn på udvidelse hænger sammen. + generatedTrash = (int)(Math.random()*(15 - 1) + 1); + + } + + public void makeHandled() { + isHandled = !isHandled; //toggles isHandled to true or false depending on its current value + } + + //getter for generated trash + public int getGeneratedTrash(){ + return generatedTrash; + } + + public Map getExtensions() { + /* + returns the map of key-value of the extensions you can buy. + case_insensitive_order so that when we compare the parameter with the elements + in the shop, we are not case sensitive. TreeMap can be case insensitive + */ + Map lowerExtensions = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + lowerExtensions.putAll(extensions); + + return lowerExtensions; + } + + //sets amount of trash in a location + public void setGeneratedTrash(int newAmount){ + generatedTrash = newAmount; + } + + public void welcome() { + System.out.printf("%n%s%n", name); + System.out.println("\nDu er nu ved "+name); + + updateExits(); + + //acts according to the location + switch(name){ + case "Butik": + showShop(); + makeHandled(); + + break; + + case "Genbrugsstation": + recycle(); + makeHandled(); + + break; + + case "Park": + collectTrashPark(); + makeHandled(); + break; + + case "Hospital": + collectTrashHospital(); + makeHandled(); + break; + + case "Bymidte": + collectTrashBymidte(); + makeHandled(); + break; + + case "Kontor": + //player.getStatus(); + break; + + default: + break; + } + } + + void updateShop(){ + /* + checks the player's level and adjusts the selection in the shop + */ + int lvl = Game.player.getLevel(); + + switch(lvl){ + case 1: + extensions.put("Billboards på Rådhuspladsen", new int[]{20, 10}); + extensions.put("Solceller", new int[]{150, 10}); + extensions.put("Cykelsti", new int[]{10, 10}); + break; + case 2: + extensions.put("Billboards på Rådhuspladsen", new int[]{20,10}); + extensions.put("Solceller", new int[]{150, 10}); + break; + case 3: + extensions.put("Billboards på Rådhuspladsen", new int[]{20, 10}); + extensions.put("Solceller", new int[]{150, 10}); + extensions.put("Isolerende vinduer", new int[]{30, 10}); + break; + case 4: + extensions.put("Supermotorvej", new int[]{20, 10}); + extensions.put("Parkeringshus", new int[]{150, 10}); + extensions.put("Isolerende vinduer", new int[]{70, 10}); + break; + case 5: + extensions.put("Varmeanlæg med oliefyr", new int[]{50, 10}); + default: + break; + } + } + + public void showShop() { + //prints out the shop - updates it first + updateShop(); + System.out.println("Du er trådt ind i butikken. Du har følgende udvalg: \n"); + for (String key : extensions.keySet()){ + int[] priceXP = extensions.get(key); + System.out.printf(" - Navn: %s, pris: %d, XP: %d%n", key, priceXP[0], priceXP[1]); + } } - public void welcome () { - System.out.println("You are now at "+name); + private void collectTrashPark(){ + System.out.println("collecting trash at this park; " + generatedTrash); //placeholder + } + + public void updateExits() { + //updates what exits are available and lists the relevant commands for the location + System.out.println("\n-------------------------------------------"); Set exits = edges.keySet(); - System.out.println("Current exits are:"); + System.out.println("Du kan gå mod:"); for (String exit: exits) { System.out.println(" - "+exit); } + + System.out.println("Rumhandlinger"); + for (String command : commands) { + System.out.printf(" - %s%n", command); + } + } + + + private void collectTrashBymidte(){ + System.out.println("collecting trash at bymidte; " + generatedTrash); //placeholder + } + + private void collectTrashHospital(){ + System.out.println("collecting trash at this hospital; " + generatedTrash); //placeholder + } + + + private void recycle(){ + System.out.println("du har afleveret dit affald for i dag"); //placeholder + + } + + + public void goodbye () { + System.out.printf("%nHere will be some information about %s (the room you just left)", name); } - + + public void addCommand(String cmdName) { + commands.add(cmdName); + } + + public boolean isCommandPossible(String cmdName) { + //checks wether the command is recognizable from the list of commands + for (String command : commands) { + if (command.equals(cmdName)) { + return true; + } + } + return false; + } + @Override public Space followEdge (String direction) { - return (Space) (super.followEdge(direction)); + return (Space)(super.followEdge(direction)); + } + + public String spaceToString(){ + return name; } } diff --git a/woz/World.class b/woz/World.class new file mode 100644 index 0000000..356bd95 Binary files /dev/null and b/woz/World.class differ diff --git a/woz/World.java b/woz/World.java index 7231668..92086f4 100644 --- a/woz/World.java +++ b/woz/World.java @@ -1,28 +1,78 @@ /* World class for modeling the entire in-game world */ +import java.util.ArrayList; +import java.util.Arrays; + +class World { + static Space kontor; + static Space park; + static Space bymidte; + static Space hospital; + static Space butik; + static Space genbrugsstation; -class World { - Space entry; World () { - Space entry = new Space("Entry"); - Space corridor = new Space("Corridor"); - Space cave = new Space("Cave"); - Space pit = new Space("Darkest Pit"); - Space outside = new Space("Outside"); + + //creates our locations + kontor = new Space("Kontor"); + park = new Space("Park"); + bymidte = new Space("Bymidte"); //bymidte? rådhusplads? + hospital = new Space("Hospital"); + butik = new Space("Butik"); + genbrugsstation = new Space("Genbrugsstation"); - entry.addEdge("door", corridor); - corridor.addEdge("door", cave); - cave.addEdge("north", pit); - cave.addEdge("south", outside); - pit.addEdge("door", cave); - outside.addEdge("door", cave); + + //arrays af hhv navne og steder, som kan sættes ind i et for-loop, der laver edges til alle steder + String[] locationArr = {"kontor", "park", "bymidte", "hospital", "butik", "genbrugsstation"}; + Space[] spaceArr = {kontor, park, bymidte, hospital, butik, genbrugsstation}; + + //uddelegerer edges til hver lokation/rum. sørger også for, at et rum ikke har adgang til sig selv (med kontor som undtagelse). + for(int i = 0; i < spaceArr.length; i++){ + for(int j = 0; j < locationArr.length; j++){ + if(!(locationArr[j].toLowerCase().equals(spaceArr[i].spaceToString().toLowerCase()))){ + spaceArr[i].addEdge(locationArr[j], spaceArr[j]); + } + } + } + + ArrayList locations = new ArrayList(); + locations.addAll(Arrays.asList(spaceArr)); - this.entry = entry; + //adds valid commands to the locations + for (Space location : locations) { + if (location.name.equals(getEntry().name)) { + location.addCommand("status"); + } else if (location.name.equals(getShop().name)) { + location.addCommand("sell"); + location.addCommand("buy"); + } else { + location.addCommand("pickup"); + } + + location.addCommand("hint"); + location.addCommand("reset"); + } + + /* + kontor skal have sig selv som edge, for at resetDay() virker inde fra kontoret af. + hvis ikke kontor har adgang til sig selv, vil transition() ikke du, da den "næste" + edge er null. + */ + kontor.addEdge("kontor", kontor); + + this.kontor = kontor; } + + //Build spaces with SpaceBuilder() + - Space getEntry () { - return entry; + Space getEntry() { + return kontor; //redigeret fra "entry" til "kontor", da kontor fungerer som vores entry + } + + private Space getShop() { + return butik; } } diff --git a/woz/class_files/BaseCommand.class b/woz/class_files/BaseCommand.class index 2fa8e94..63a74b1 100644 Binary files a/woz/class_files/BaseCommand.class and b/woz/class_files/BaseCommand.class differ