diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..9a960a2 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_1_2.xml b/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_1_2.xml new file mode 100644 index 0000000..6ac1c42 --- /dev/null +++ b/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_1_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_8_1.xml b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_8_1.xml new file mode 100644 index 0000000..4910ca9 --- /dev/null +++ b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_8_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_8_1.xml b/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_8_1.xml new file mode 100644 index 0000000..3417208 --- /dev/null +++ b/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_8_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_opentest4j_opentest4j_1_2_0.xml b/.idea/libraries/Maven__org_opentest4j_opentest4j_1_2_0.xml new file mode 100644 index 0000000..fbc1b16 --- /dev/null +++ b/.idea/libraries/Maven__org_opentest4j_opentest4j_1_2_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..67e1e61 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..797acea --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Video Youtube definitief b/Video Youtube definitief new file mode 100644 index 0000000..87d61cb --- /dev/null +++ b/Video Youtube definitief @@ -0,0 +1,14 @@ +https://youtu.be/ZUSgK_amCQw + +00:00 - 00:45 = Part +00:49 - 03:06 = Assembly +03:10 - 03:38 = Suspect +03:39 - 03:50 = Weapon +03:51 - 05:55 = Room +05:57 - 07:16 = Mansion +07:19 - 08:35 = Detective +08:36 - 09:30 = Envelope +09:30 - 21:01 = Game Engine +21:02 - 28:03 = Commands +28:04 - 31:00 = Tests +31:01 - einde = Spelverloop diff --git a/pom.xml b/pom.xml index fa13be6..29d9b63 100644 --- a/pom.xml +++ b/pom.xml @@ -7,9 +7,21 @@ be.pxl CluedoOpgave 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 17 + 17 + + + + - + 17 17 @@ -22,6 +34,18 @@ 5.8.1 test - + + junit + junit + 4.13 + test + + + junit + junit + 4.13 + test + + diff --git a/src/main/java/be/pxl/ja/Anagram.java b/src/main/java/be/pxl/ja/Anagram.java new file mode 100644 index 0000000..6514a2b --- /dev/null +++ b/src/main/java/be/pxl/ja/Anagram.java @@ -0,0 +1,27 @@ +package be.pxl.ja; + +public class Anagram extends Riddle{ + public String word; + public String description; + public String answer; + + public Anagram(String word, String description, String answer) { + this.word = word; + this.description = description; + this.answer = answer; + } + + public String getWord() { + return word; + } + + + public String getDescription() { + return description; + } + + + public String getAnswer() { + return answer; + } +} diff --git a/src/main/java/be/pxl/ja/Assembly.java b/src/main/java/be/pxl/ja/Assembly.java new file mode 100644 index 0000000..da08a2f --- /dev/null +++ b/src/main/java/be/pxl/ja/Assembly.java @@ -0,0 +1,34 @@ +package be.pxl.ja; + +import java.lang.reflect.Array; +import java.util.*; +import java.util.stream.Collectors; + +public class Assembly { + private final List assemblyParts; + + public Assembly(List assemblyParts) { + this.assemblyParts = assemblyParts; + } + + public int getNumberOfParts() { + return assemblyParts.size(); + } + + public Optional getPart(String name) { + return assemblyParts.stream() // loop over assemblyParts + .filter(assemblyPart -> name.equals(assemblyPart.getName())) // if name = assemblyPart name + .findFirst(); // return the first that matches the if statement + } + + public T getPart(int index) { + return assemblyParts.get(index); + } + + public List getParts() { + return assemblyParts.stream() + .sorted(Comparator.comparing(Part::getName)) + .collect(Collectors.toList()); + } +} + diff --git a/src/main/java/be/pxl/ja/CluedoException.java b/src/main/java/be/pxl/ja/CluedoException.java new file mode 100644 index 0000000..ef38a11 --- /dev/null +++ b/src/main/java/be/pxl/ja/CluedoException.java @@ -0,0 +1,7 @@ +package be.pxl.ja; + +public class CluedoException extends RuntimeException { + public CluedoException(String message) { + super(message); + } +} diff --git a/src/main/java/be/pxl/ja/CrackTheCode.java b/src/main/java/be/pxl/ja/CrackTheCode.java new file mode 100644 index 0000000..330ada7 --- /dev/null +++ b/src/main/java/be/pxl/ja/CrackTheCode.java @@ -0,0 +1,19 @@ +package be.pxl.ja; + +public class CrackTheCode extends Riddle{ + public String[] questions; + public String answer; + + public CrackTheCode(String[] questions, String answer) { + this.questions = questions; + this.answer = answer; + } + + public String[] getQuestions() { + return questions; + } + + public String getAnswer() { + return answer; + } +} diff --git a/src/main/java/be/pxl/ja/Detective.java b/src/main/java/be/pxl/ja/Detective.java index d6eb096..1262b8e 100644 --- a/src/main/java/be/pxl/ja/Detective.java +++ b/src/main/java/be/pxl/ja/Detective.java @@ -1,19 +1,26 @@ package be.pxl.ja; +import java.util.ArrayList; +import java.util.List; + public class Detective { - private final String name; + private final String name; + private Room currentRoom; + public List collectedClues = new ArrayList<>(1); - public Detective(String name) { - this.name = name; - } + public Detective(String name) { + this.name = name; + } - public String getCurrentRoom() { - // TODO: update this method (and change return type!) - return "Hall"; - } + public Room getCurrentRoom() { + return this.currentRoom; + } - public void moveTo() { - // TODO: add parameter and implement this method. - } + public void moveTo(Room nextRoom) { + if (nextRoom.equals(currentRoom)) { + throw new CluedoException("This move is not allowed"); + } + currentRoom = nextRoom; + } } diff --git a/src/main/java/be/pxl/ja/Envelope.java b/src/main/java/be/pxl/ja/Envelope.java new file mode 100644 index 0000000..0c0410b --- /dev/null +++ b/src/main/java/be/pxl/ja/Envelope.java @@ -0,0 +1,20 @@ +package be.pxl.ja; + +import java.util.ArrayList; +import java.util.List; + +public class Envelope { + private final List secrets = new ArrayList<>(); + + public void addSecret(T secret) { + secrets.add(secret); + } + + public void removeSecret(T secret) { + secrets.remove(secret); + } + + public boolean isSecret(T secret) { + return secrets.contains(secret); + } +} diff --git a/src/main/java/be/pxl/ja/GameEngine.java b/src/main/java/be/pxl/ja/GameEngine.java index 19e3ae1..d383d00 100644 --- a/src/main/java/be/pxl/ja/GameEngine.java +++ b/src/main/java/be/pxl/ja/GameEngine.java @@ -1,51 +1,220 @@ package be.pxl.ja; -import be.pxl.ja.command.HelpCommand; +import be.pxl.ja.command.*; -import java.io.IOException; -import java.util.Random; -import java.util.Scanner; +import java.io.File; +import java.io.FileNotFoundException; +import java.util.*; public class GameEngine { - private static final Random RANDOM = new Random(); - private Detective detective; - private final Scanner scanner; - private boolean murderSolved; - private HelpCommand helpCommand = new HelpCommand(); - - public GameEngine(Scanner scanner) { - this.scanner = scanner; - } - - public void initialize(String playerName) { - murderSolved = false; - // read all files to initialize the game - detective = new Detective(playerName); - // randomly choose weapon, crimescene and murderer - // put all other weapons and suspects in the rooms of the mansion - } - - public void start() { - System.out.println("Who murdered Dr. Black? Where did the crime took place, and which weapon was used?"); - System.out.println("Type 'help' for information..."); - } - - - /** - * Handle the command. - * @param command a command: goto, clue, describe,... - */ - public void executeCommand(String command) { - helpCommand.execute(null); - } - - public void printLocation() { - System.out.println("You are in the " + detective.getCurrentRoom()); - } - - - public boolean isMurderSolved() { - return murderSolved; - } + private static final Random RANDOM = new Random(); + public static Detective detective; + private Scanner scanner; + public static boolean murderSolved; + public static Envelope envelope; + + private HelpCommand helpCommand = new HelpCommand(); + private SuspectsCommand suspectsCommand = new SuspectsCommand(); + private RoomsCommand roomsCommand = new RoomsCommand(); + private WeaponsCommand weaponsCommand = new WeaponsCommand(); + private ClueCommand clueCommand = new ClueCommand(); + private GoToCommand goToCommand = new GoToCommand(); + private DescribeCommand describeCommand = new DescribeCommand(); + private UnlockCommand unlockCommand = new UnlockCommand(); + private AccuseCommand accuseCommand = new AccuseCommand(); + + public static List rooms; + public static List weapons; + public static List suspects; + public static Mansion mansion; + public static List parts; + public static List anagrams; + public static List crackTheCodes; + + public GameEngine(Scanner scanner) { + this.scanner = scanner; + } + + public void initialize(String playerName) throws FileNotFoundException { + murderSolved = false; + + File file = new File("src/main/resources/cluedo.txt"); + File anagram = new File("src/main/resources/anagrams.txt"); + File crackTheCode = new File("src/main/resources/crackthecode.txt"); + scanner = new Scanner(file); + + + rooms = new ArrayList<>(); + weapons = new ArrayList<>(); + suspects = new ArrayList<>(); + parts = new ArrayList<>(); + + String objectType = null; + + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + + if ("#ROOMS".equals(line) || "#WEAPONS".equals(line) || "#SUSPECTS".equals(line)) { + objectType = line; + } else { + if ("#ROOMS".equals(objectType)) { + Room room = new Room(line); + if (!rooms.contains(room)) { + rooms.add(room); + parts.add(room); + } + } else if ("#WEAPONS".equals(objectType)) { + Weapon weapon = new Weapon(line); + if (!weapons.contains(weapon)) { + weapons.add(weapon); + parts.add(weapon); + } + } else if ("#SUSPECTS".equals(objectType)) { + String[] params = line.split(";"); + + String name = params[0].substring(params[0].indexOf(" ")).strip(); + String title = params[0].substring(0, params[0].indexOf(" ")); + + Suspect suspect = new Suspect(name); + suspect.setAge(Integer.parseInt(params[1])); + suspect.setNationality(params[2]); + suspect.setOccupation(params[2]); + suspect.setTitle(title); + + if (!suspects.contains(suspect)) { + suspects.add(suspect); + parts.add(suspect); + } + } + } + } + + detective = new Detective(playerName); + + Room crimeScene = rooms.stream() + .skip(RANDOM.nextInt(rooms.size())) + .findFirst() + .orElseThrow(() -> new CluedoException("No rooms found from game file")); + crimeScene.setCrimeScene(true); + + Weapon murderWeapon = weapons.stream() + .skip(RANDOM.nextInt(weapons.size())) + .findFirst() + .orElseThrow(() -> new CluedoException("No weapons found from game file")); + + Suspect murderer = suspects.stream() + .skip(RANDOM.nextInt(suspects.size())) + .findFirst() + .orElseThrow(() -> new CluedoException("No suspects found from game file")); + + envelope = new Envelope<>(); + envelope.addSecret(crimeScene); + envelope.addSecret(murderWeapon); + envelope.addSecret(murderer); + + // overige wapens en suspects verdelen over de kamers + List roomWeapons = new ArrayList<>(); + for (Weapon weapon : weapons){ + if (!weapon.equals(murderWeapon)){ + roomWeapons.add(weapon); + } + } + + List roomSuspects = new ArrayList<>(); + for (Suspect suspect : suspects){ + if (!suspect.equals(murderer)){ + roomSuspects.add(suspect); + } + } + + for (Room room : rooms) { + if (roomWeapons.size() != 0){ + Weapon weapon = roomWeapons.get(RANDOM.nextInt(roomWeapons.size())); + roomWeapons.remove(weapon); + room.setWeapon(weapon); + } + + if (roomSuspects.size() != 0){ + Suspect suspect = roomSuspects.get(RANDOM.nextInt(roomSuspects.size())); + roomSuspects.remove(suspect); + room.setSuspect(suspect); + } + } + + mansion = new Mansion(new ArrayList<>(rooms)); + detective.moveTo(mansion.getHall()); + + anagrams = new ArrayList<>(); + scanner = new Scanner(anagram); + + while(scanner.hasNextLine()){ + String line = scanner.nextLine(); + String[] anagramPieces = line.split(";"); + Anagram anagramConstruct = new Anagram(anagramPieces[0], anagramPieces[1], anagramPieces[2]); + anagrams.add(anagramConstruct); + } + + crackTheCodes = new ArrayList<>(); + + scanner = new Scanner(crackTheCode); + int counter = 0; + + while(scanner.hasNextLine()){ + String line = scanner.nextLine(); + + String[] questions = new String[5]; + String answer; + + if ("#".equals(line.substring(0, 1))){ + counter = 0; + } else if (line.contains("ANSWER")){ + String[] crackTheCodePieces = line.split(":"); + answer = crackTheCodePieces[1].strip(); + CrackTheCode crackTheCodeConstruct = new CrackTheCode(questions, answer); + crackTheCodes.add(crackTheCodeConstruct); + } else { + questions[counter] = line; + counter++; + } + } + + //--------------------------------------------------- + scanner.close(); // einde van init, alle code voor deze lijn + } + + public void start() { + System.out.println("Who murdered Dr. Black? Where did the crime took place, and which weapon was used?"); + System.out.println("Type 'help' for information..."); + } + + public void executeCommand(String command) { + if ("suspects".equals(command)){ + suspectsCommand.execute(command); + } else if ("rooms".equals(command)){ + roomsCommand.execute(command); + } else if ("weapons".equals(command)){ + weaponsCommand.execute(command); + } else if ("describe".equals(command)){ + describeCommand.execute(command); + } else if ("unlock".equals(command)){ + unlockCommand.execute(command); + } else if (command.contains("clue")){ //voorlopig + clueCommand.execute(command.substring(5)); + } else if ("help".equals(command)){ + helpCommand.execute(command); + } else if (command.contains("accuse")){ //voorlopig + accuseCommand.execute(command.substring(7)); + } else if (command.contains("goto")){ + goToCommand.execute(command.substring(5)); + } + } + + public void printLocation() { + System.out.println("You are in the " + detective.getCurrentRoom().getName()); + } + + public boolean isMurderSolved() { + return murderSolved; + } } diff --git a/src/main/java/be/pxl/ja/Mansion.java b/src/main/java/be/pxl/ja/Mansion.java new file mode 100644 index 0000000..f3a3358 --- /dev/null +++ b/src/main/java/be/pxl/ja/Mansion.java @@ -0,0 +1,34 @@ +package be.pxl.ja; + +import java.util.List; +import java.util.Optional; + +public class Mansion extends Assembly { + + private static final String HALL = "Hall"; + + public Mansion(List assemblyParts) { + super(assemblyParts); + } + + public Room getHall() { + return getPart(HALL) + .orElseThrow(() -> new CluedoException("Every mansion must have a hall")); + } + + public int getNumberOfRooms() { + return getNumberOfParts(); + } + + public Optional getRoom(String room) { + return getPart(room); + } + + public Room getRoom(int room) { + return getPart(room); + } + + public List getRooms() { + return getParts(); + } +} diff --git a/src/main/java/be/pxl/ja/Part.java b/src/main/java/be/pxl/ja/Part.java new file mode 100644 index 0000000..5e85f84 --- /dev/null +++ b/src/main/java/be/pxl/ja/Part.java @@ -0,0 +1,32 @@ +package be.pxl.ja; + +import java.util.Objects; + +public abstract class Part { + private final String name; + + public Part(String name){ + this.name = name; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Part part = (Part) o; + return Objects.equals(name, part.name); + } + + @Override + public int hashCode() { + return Objects.hash(name); + } + + public String getName(){ + return name; + } + + public String ToString(){ + return name; + } +} diff --git a/src/main/java/be/pxl/ja/Predicate.java b/src/main/java/be/pxl/ja/Predicate.java new file mode 100644 index 0000000..8edb9bc --- /dev/null +++ b/src/main/java/be/pxl/ja/Predicate.java @@ -0,0 +1,5 @@ +package be.pxl.ja; + +public interface Predicate { + //to be made +} diff --git a/src/main/java/be/pxl/ja/Riddle.java b/src/main/java/be/pxl/ja/Riddle.java new file mode 100644 index 0000000..8d1265b --- /dev/null +++ b/src/main/java/be/pxl/ja/Riddle.java @@ -0,0 +1,5 @@ +package be.pxl.ja; + +public abstract class Riddle implements Predicate{ + +} diff --git a/src/main/java/be/pxl/ja/Room.java b/src/main/java/be/pxl/ja/Room.java new file mode 100644 index 0000000..33045d9 --- /dev/null +++ b/src/main/java/be/pxl/ja/Room.java @@ -0,0 +1,73 @@ +package be.pxl.ja; + +import java.util.Optional; + +public class Room extends Part { + + // use of static final to avoid changing multiple strings in case the separator needs to be different + private static final String SEPARATOR = "\n"; + + private Weapon weapon; + private Suspect suspect; + private boolean crimeScene; + private boolean locked; + + public Room(String name) { + super(name); + this.locked = true; + } + + public String describe(String input) { + if (locked) { + return input + " is locked."; + } + + StringBuilder description = new StringBuilder(); + + if (crimeScene) { + description.append("There's blood in this room"); + } else { + description.append("There's no blood in this room"); + } + + getWeapon().map(Part::getName) // get the name in case the weapon is not empty + .ifPresent(name -> description.append(SEPARATOR).append(name)); // if the name is present, add it to the description + + getSuspect().map(Part::getName) // get the name in case the suspect is not empty + .ifPresent(name -> description.append(SEPARATOR).append(name)); // if the name is present, add it to the description + + return description.toString(); + } + + public Optional getSuspect() { + return Optional.ofNullable(suspect); + } + + public Optional getWeapon() { + return Optional.ofNullable(weapon); + } + + public boolean isLocked() { + return locked; + } + + public void setCrimeScene(boolean crimeScene) { + this.crimeScene = crimeScene; + } + + public void setSuspect(Suspect suspect) { + this.suspect = suspect; + } + + public void setWeapon(Weapon weapon) { + this.weapon = weapon; + } + + public void removeSuspect() { + this.suspect = null; + } + + public void unlock() { + this.locked = false; + } +} diff --git a/src/main/java/be/pxl/ja/RoomLockedClientException.java b/src/main/java/be/pxl/ja/RoomLockedClientException.java new file mode 100644 index 0000000..b69f3ce --- /dev/null +++ b/src/main/java/be/pxl/ja/RoomLockedClientException.java @@ -0,0 +1,4 @@ +package be.pxl.ja; + +public class RoomLockedClientException extends RuntimeException{ +} diff --git a/src/main/java/be/pxl/ja/Suspect.java b/src/main/java/be/pxl/ja/Suspect.java new file mode 100644 index 0000000..a884d9f --- /dev/null +++ b/src/main/java/be/pxl/ja/Suspect.java @@ -0,0 +1,45 @@ +package be.pxl.ja; + +public class Suspect extends Part { + private String title; + private String occupation; + private String nationality; + private int age; + + public Suspect(String name) { + super(name); + } + + public int getAge(){ + return age; + } + + public String getOccupation() { + return occupation; + } + + public String getNationality() { + return nationality; + } + + public void setTitle(String title) { + this.title = title; + } + + public void setOccupation(String occupation) { + this.occupation = occupation; + } + + public void setNationality(String nationality) { + this.nationality = nationality; + } + + public void setAge(int age) { + this.age = age; + } + + @Override + public String toString() { + return title + ", " + this.getName(); + } +} diff --git a/src/main/java/be/pxl/ja/Weapon.java b/src/main/java/be/pxl/ja/Weapon.java new file mode 100644 index 0000000..f0354b1 --- /dev/null +++ b/src/main/java/be/pxl/ja/Weapon.java @@ -0,0 +1,8 @@ +package be.pxl.ja; + +public class Weapon extends Part { + + public Weapon(String name) { + super(name); + } +} diff --git a/src/main/java/be/pxl/ja/command/AccuseCommand.java b/src/main/java/be/pxl/ja/command/AccuseCommand.java new file mode 100644 index 0000000..8d492bd --- /dev/null +++ b/src/main/java/be/pxl/ja/command/AccuseCommand.java @@ -0,0 +1,47 @@ +package be.pxl.ja.command; + +import be.pxl.ja.GameEngine; +import be.pxl.ja.Room; +import be.pxl.ja.Suspect; +import be.pxl.ja.Weapon; + +public class AccuseCommand implements Command{ + @Override + public void execute(String input) { + String[] inputParts = input.split(", "); + boolean corrrectRoom = false; + boolean correctWeapon = false; + boolean correctSuspect = false; + + if (!GameEngine.envelope.isSecret(GameEngine.detective.getCurrentRoom())){ + System.out.println("It was not in the " + GameEngine.detective.getCurrentRoom().getName() + "."); + } else { + corrrectRoom = true; + } + + for (Weapon weapon : GameEngine.weapons){ + if (inputParts[1].equalsIgnoreCase(weapon.getName())){ + if (GameEngine.envelope.isSecret(weapon)){ + System.out.println("It was not with a " + weapon.getName()); + } else { + correctWeapon = true; + } + } + } + + for (Suspect suspect : GameEngine.suspects){ + if (inputParts[0].equalsIgnoreCase(suspect.getName().strip())){ + if (!GameEngine.envelope.isSecret(suspect)){ + System.out.println(suspect.getName().strip() + " is not the killer."); + } else { + correctSuspect = true; + } + } + } + + if (correctWeapon && corrrectRoom && correctSuspect){ + System.out.println("Correct you won!"); + GameEngine.murderSolved = true; + } + } +} diff --git a/src/main/java/be/pxl/ja/command/ClueCommand.java b/src/main/java/be/pxl/ja/command/ClueCommand.java new file mode 100644 index 0000000..643d451 --- /dev/null +++ b/src/main/java/be/pxl/ja/command/ClueCommand.java @@ -0,0 +1,26 @@ +package be.pxl.ja.command; + +import be.pxl.ja.*; + +public class ClueCommand implements Command{ + @Override + public void execute(String input) { + boolean containsClue = false; + + // controle op dubbele ingave + for (Part part : GameEngine.detective.collectedClues){ + if (input.equalsIgnoreCase(part.getName())){ + System.out.println("Deze clue heb je al doorgegeven."); + containsClue = true; + } + } + + if (!containsClue){ + for (Part part : GameEngine.parts){ + if (input.equalsIgnoreCase(part.getName())){ + GameEngine.detective.collectedClues.add(part); + } + } + } + } +} diff --git a/src/main/java/be/pxl/ja/command/DescribeCommand.java b/src/main/java/be/pxl/ja/command/DescribeCommand.java new file mode 100644 index 0000000..aebba7c --- /dev/null +++ b/src/main/java/be/pxl/ja/command/DescribeCommand.java @@ -0,0 +1,11 @@ +package be.pxl.ja.command; + +import be.pxl.ja.GameEngine; + +public class DescribeCommand implements Command{ + @Override + public void execute(String input) { + //System.out.println(GameEngine.detective.getCurrentRoom().getName()); + System.out.println(GameEngine.detective.getCurrentRoom().describe(GameEngine.detective.getCurrentRoom().getName())); + } +} diff --git a/src/main/java/be/pxl/ja/command/GoToCommand.java b/src/main/java/be/pxl/ja/command/GoToCommand.java new file mode 100644 index 0000000..a52bac2 --- /dev/null +++ b/src/main/java/be/pxl/ja/command/GoToCommand.java @@ -0,0 +1,18 @@ +package be.pxl.ja.command; + +import be.pxl.ja.GameEngine; +import be.pxl.ja.Part; +import be.pxl.ja.Room; + +import java.util.Locale; + +public class GoToCommand implements Command{ + @Override + public void execute(String input) { + for (Room room : GameEngine.rooms){ + if (input.equalsIgnoreCase(room.getName())){ + GameEngine.detective.moveTo(room); + } + } + } +} diff --git a/src/main/java/be/pxl/ja/command/HelpCommand.java b/src/main/java/be/pxl/ja/command/HelpCommand.java index 7bb25ce..7ba0631 100644 --- a/src/main/java/be/pxl/ja/command/HelpCommand.java +++ b/src/main/java/be/pxl/ja/command/HelpCommand.java @@ -1,10 +1,12 @@ package be.pxl.ja.command; +import be.pxl.ja.GameEngine; +import be.pxl.ja.Part; + public class HelpCommand implements Command { @Override public void execute(String input) { - System.out.println("You can use following commands:"); System.out.println("SUSPECTS - gives you an overview of all possible suspects"); System.out.println("ROOMS - gives you an overview of all rooms"); System.out.println("WEAPONS - gives you an overview of all weapons"); diff --git a/src/main/java/be/pxl/ja/command/RoomsCommand.java b/src/main/java/be/pxl/ja/command/RoomsCommand.java new file mode 100644 index 0000000..dbbb5cd --- /dev/null +++ b/src/main/java/be/pxl/ja/command/RoomsCommand.java @@ -0,0 +1,26 @@ +package be.pxl.ja.command; + +import be.pxl.ja.GameEngine; +import be.pxl.ja.Part; +import be.pxl.ja.Room; + +import java.util.ArrayList; +import java.util.List; + +public class RoomsCommand implements Command{ + @Override + public void execute(String input) { + for (Room room : GameEngine.rooms){ + boolean isClue = false; + for (Part part : GameEngine.detective.collectedClues){ + if (room.getName().equalsIgnoreCase(part.getName())){ + System.out.println(room.getName() + " 0"); + isClue = true; + } + } + if (!isClue){ + System.out.println(room.getName()); + } + } + } +} diff --git a/src/main/java/be/pxl/ja/command/SuspectsCommand.java b/src/main/java/be/pxl/ja/command/SuspectsCommand.java new file mode 100644 index 0000000..8868159 --- /dev/null +++ b/src/main/java/be/pxl/ja/command/SuspectsCommand.java @@ -0,0 +1,24 @@ +package be.pxl.ja.command; + +import be.pxl.ja.GameEngine; +import be.pxl.ja.Part; +import be.pxl.ja.Room; +import be.pxl.ja.Suspect; + +public class SuspectsCommand implements Command{ + @Override + public void execute(String input) { + for (Suspect suspect : GameEngine.suspects) { + boolean isClue = false; + for (Part part : GameEngine.detective.collectedClues) { + if (suspect.getName().equalsIgnoreCase(part.getName())) { + System.out.println(suspect.getName() + " 0"); + isClue = true; + } + } + if (!isClue) { + System.out.println(suspect.getName()); + } + } + } +} diff --git a/src/main/java/be/pxl/ja/command/UnlockCommand.java b/src/main/java/be/pxl/ja/command/UnlockCommand.java new file mode 100644 index 0000000..f16a312 --- /dev/null +++ b/src/main/java/be/pxl/ja/command/UnlockCommand.java @@ -0,0 +1,29 @@ +package be.pxl.ja.command; + +import be.pxl.ja.GameEngine; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.util.Random; +import java.util.Scanner; + +public class UnlockCommand implements Command{ + @Override + public void execute(String input) { + /* + Scanner keyboard = new Scanner(System.in); + // keyboard.nextLine() + + System.out.println(GameEngine.crackTheCodes.get(0).getAnswer()); + + if (keyboard.nextLine().equals(GameEngine.crackTheCodes.get(0).getAnswer())){ + GameEngine.detective.getCurrentRoom().unlock(); + } else { + System.out.println("Wrong answer!"); + } + + */ + + GameEngine.detective.getCurrentRoom().unlock(); + } +} diff --git a/src/main/java/be/pxl/ja/command/WeaponsCommand.java b/src/main/java/be/pxl/ja/command/WeaponsCommand.java new file mode 100644 index 0000000..a4c6e01 --- /dev/null +++ b/src/main/java/be/pxl/ja/command/WeaponsCommand.java @@ -0,0 +1,24 @@ +package be.pxl.ja.command; + +import be.pxl.ja.GameEngine; +import be.pxl.ja.Part; +import be.pxl.ja.Room; +import be.pxl.ja.Weapon; + +public class WeaponsCommand implements Command{ + @Override + public void execute(String input) { + for (Weapon weapon : GameEngine.weapons){ + boolean isClue = false; + for (Part part : GameEngine.detective.collectedClues){ + if (weapon.getName().equalsIgnoreCase(part.getName())){ + System.out.println(weapon.getName() + " 0"); + isClue = true; + } + } + if (!isClue){ + System.out.println(weapon.getName()); + } + } + } +} diff --git a/src/test/java/CluedoTests/DescribeCommandTests.java b/src/test/java/CluedoTests/DescribeCommandTests.java new file mode 100644 index 0000000..ba5e393 --- /dev/null +++ b/src/test/java/CluedoTests/DescribeCommandTests.java @@ -0,0 +1,45 @@ +package CluedoTests; + +import be.pxl.ja.GameEngine; +import be.pxl.ja.Part; +import be.pxl.ja.Weapon; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayOutputStream; +import java.io.FileNotFoundException; +import java.io.PrintStream; +import java.util.Scanner; + +public class DescribeCommandTests { + Scanner keyboard = new Scanner(System.in); + GameEngine gameEngine = new GameEngine(keyboard); + ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + + @BeforeEach + public void setUp() throws FileNotFoundException { + gameEngine.initialize("Stef"); + } + + @Test + public void shouldShowLockedWhenRoomIsLocked() { + gameEngine.executeCommand("goto ball"); + + System.setOut(new PrintStream(outContent)); + gameEngine.executeCommand("describe"); + + Assertions.assertEquals("Ball is locked.", outContent.toString().strip()); + } + + @Test + public void shouldGiveRightDescription(){ + gameEngine.executeCommand("goto kitchen"); + GameEngine.detective.getCurrentRoom().unlock(); + + System.setOut(new PrintStream(outContent)); + gameEngine.executeCommand("describe"); + + Assertions.assertEquals("There's no blood in this room", outContent.toString().strip()); + } +} diff --git a/src/test/java/CluedoTests/GoToCommandTests.java b/src/test/java/CluedoTests/GoToCommandTests.java new file mode 100644 index 0000000..9dc7abc --- /dev/null +++ b/src/test/java/CluedoTests/GoToCommandTests.java @@ -0,0 +1,81 @@ +package CluedoTests; + +import be.pxl.ja.CluedoException; +import be.pxl.ja.GameEngine; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.FileNotFoundException; +import java.util.Scanner; + +import static org.junit.Assert.assertThrows; + +public class GoToCommandTests { + Scanner keyboard = new Scanner(System.in); + GameEngine gameEngine = new GameEngine(keyboard); + + @BeforeEach + public void setUp() throws FileNotFoundException { + gameEngine.initialize("Stef"); + } + + @Test + public void shouldStartInHall() { + Assertions.assertEquals("Hall", GameEngine.detective.getCurrentRoom().getName()); + } + + @Test + public void shouldGoToDining(){ + gameEngine.executeCommand("goto dining"); + Assertions.assertEquals("Dining", GameEngine.detective.getCurrentRoom().getName()); + } + + @Test + public void shouldGoToBall(){ + gameEngine.executeCommand("goto ball"); + Assertions.assertEquals("Ball", GameEngine.detective.getCurrentRoom().getName()); + } + + @Test + public void shouldGoToConservatory(){ + gameEngine.executeCommand("goto conservatory"); + Assertions.assertEquals("Conservatory", GameEngine.detective.getCurrentRoom().getName()); + } + + @Test + public void shouldGoToKitchen(){ + gameEngine.executeCommand("goto kitchen"); + Assertions.assertEquals("Kitchen", GameEngine.detective.getCurrentRoom().getName()); + } + + @Test + public void shouldGoToLibrary(){ + gameEngine.executeCommand("goto library"); + Assertions.assertEquals("Library", GameEngine.detective.getCurrentRoom().getName()); + } + + @Test + public void shouldGoToLounge(){ + gameEngine.executeCommand("goto lounge"); + Assertions.assertEquals("Lounge", GameEngine.detective.getCurrentRoom().getName()); + } + + @Test + public void shouldGoToStudy(){ + gameEngine.executeCommand("goto study"); + Assertions.assertEquals("Study", GameEngine.detective.getCurrentRoom().getName()); + } + + @Test + public void shouldGoToBilliard(){ + gameEngine.executeCommand("goto billiard"); + Assertions.assertEquals("Billiard", GameEngine.detective.getCurrentRoom().getName()); + } + + @Test + public void goToHallShouldThrowCluedoExceptionWithCorrectMessage(){ + CluedoException cluedoException = assertThrows(CluedoException.class, () -> gameEngine.executeCommand("goto hall")); + Assertions.assertEquals("This move is not allowed", cluedoException.getMessage()); + } +} diff --git a/target/classes/anagrams.txt b/target/classes/anagrams.txt new file mode 100644 index 0000000..3268c33 --- /dev/null +++ b/target/classes/anagrams.txt @@ -0,0 +1,25 @@ +Dave Tuner;His life isn’t boring.;adventure +Pat Hable;He knows all the letters.;alphabet +Alan Cumbe;Let’s hope you never need him.;ambulance +Nat Modbin;Great sportsman.;badminton +Fiona Clair;Lives in America.;California +Paul Simon Gachee;The best and brightest.;Champions league +Alec Cooth;Such a sweet boy!;chocolate +Trish Scam;A merry girl.;Christmas +Margot Mc Uspee;Lives in a world of her own.;computer games +Rock Fasnel;Meet him at breakfast!;cornflakes +Lou Gaide;He’s a big talker.;dialogue +Fred Finet;He’s not like you and me.;different +Danny Delis;Kids like him a lot.;Disneyland +Scot Bugidi;Your best friend’s treat.;dog biscuit +Louise Todfry;Bob the Builder’s little sister?;do-it-yourself +Ross Wantid;Not much of a climber.;downstairs +Henry Givet;He gives you all you want.;everything +Edgar Ribfie;Call him when it’s getting too hot.;fire brigade +Rolf Powet;Always there on Mother’s Day.;flowerpot +Ernie Glen;Takes you right into London.;Green Line +Marge Hurb;Not a vegetarian.;hamburger +Chet Farvor;Crossed the Channel in no time.;hovercraft +Eric Mace;Meet him on a hot summer’s day.;ice cream +Peter Mauret;Changes every day.;temperature +Igor Steplet;A spooky man.;poltergeist diff --git a/target/classes/be/pxl/ja/Assembly.class b/target/classes/be/pxl/ja/Assembly.class new file mode 100644 index 0000000..cb3fd26 Binary files /dev/null and b/target/classes/be/pxl/ja/Assembly.class differ diff --git a/target/classes/be/pxl/ja/Cluedo.class b/target/classes/be/pxl/ja/Cluedo.class new file mode 100644 index 0000000..135fce8 Binary files /dev/null and b/target/classes/be/pxl/ja/Cluedo.class differ diff --git a/target/classes/be/pxl/ja/CluedoException.class b/target/classes/be/pxl/ja/CluedoException.class new file mode 100644 index 0000000..604f7b2 Binary files /dev/null and b/target/classes/be/pxl/ja/CluedoException.class differ diff --git a/target/classes/be/pxl/ja/Detective.class b/target/classes/be/pxl/ja/Detective.class new file mode 100644 index 0000000..3d994c3 Binary files /dev/null and b/target/classes/be/pxl/ja/Detective.class differ diff --git a/target/classes/be/pxl/ja/Envelope.class b/target/classes/be/pxl/ja/Envelope.class new file mode 100644 index 0000000..2d9847e Binary files /dev/null and b/target/classes/be/pxl/ja/Envelope.class differ diff --git a/target/classes/be/pxl/ja/GameEngine.class b/target/classes/be/pxl/ja/GameEngine.class new file mode 100644 index 0000000..d972f4e Binary files /dev/null and b/target/classes/be/pxl/ja/GameEngine.class differ diff --git a/target/classes/be/pxl/ja/Mansion.class b/target/classes/be/pxl/ja/Mansion.class new file mode 100644 index 0000000..ae0be14 Binary files /dev/null and b/target/classes/be/pxl/ja/Mansion.class differ diff --git a/target/classes/be/pxl/ja/Part.class b/target/classes/be/pxl/ja/Part.class new file mode 100644 index 0000000..1898c5c Binary files /dev/null and b/target/classes/be/pxl/ja/Part.class differ diff --git a/target/classes/be/pxl/ja/Room.class b/target/classes/be/pxl/ja/Room.class new file mode 100644 index 0000000..58fd2b1 Binary files /dev/null and b/target/classes/be/pxl/ja/Room.class differ diff --git a/target/classes/be/pxl/ja/RoomLockedClientException.class b/target/classes/be/pxl/ja/RoomLockedClientException.class new file mode 100644 index 0000000..b2945f0 Binary files /dev/null and b/target/classes/be/pxl/ja/RoomLockedClientException.class differ diff --git a/target/classes/be/pxl/ja/Suspect.class b/target/classes/be/pxl/ja/Suspect.class new file mode 100644 index 0000000..d0097cb Binary files /dev/null and b/target/classes/be/pxl/ja/Suspect.class differ diff --git a/target/classes/be/pxl/ja/Weapon.class b/target/classes/be/pxl/ja/Weapon.class new file mode 100644 index 0000000..279c877 Binary files /dev/null and b/target/classes/be/pxl/ja/Weapon.class differ diff --git a/target/classes/be/pxl/ja/command/AccuseCommand.class b/target/classes/be/pxl/ja/command/AccuseCommand.class new file mode 100644 index 0000000..f8921fe Binary files /dev/null and b/target/classes/be/pxl/ja/command/AccuseCommand.class differ diff --git a/target/classes/be/pxl/ja/command/ClueCommand.class b/target/classes/be/pxl/ja/command/ClueCommand.class new file mode 100644 index 0000000..9bd7885 Binary files /dev/null and b/target/classes/be/pxl/ja/command/ClueCommand.class differ diff --git a/target/classes/be/pxl/ja/command/Command.class b/target/classes/be/pxl/ja/command/Command.class new file mode 100644 index 0000000..3fe9f3d Binary files /dev/null and b/target/classes/be/pxl/ja/command/Command.class differ diff --git a/target/classes/be/pxl/ja/command/DescribeCommand.class b/target/classes/be/pxl/ja/command/DescribeCommand.class new file mode 100644 index 0000000..3bd533f Binary files /dev/null and b/target/classes/be/pxl/ja/command/DescribeCommand.class differ diff --git a/target/classes/be/pxl/ja/command/GoToCommand.class b/target/classes/be/pxl/ja/command/GoToCommand.class new file mode 100644 index 0000000..2d76a75 Binary files /dev/null and b/target/classes/be/pxl/ja/command/GoToCommand.class differ diff --git a/target/classes/be/pxl/ja/command/HelpCommand.class b/target/classes/be/pxl/ja/command/HelpCommand.class new file mode 100644 index 0000000..5a404f4 Binary files /dev/null and b/target/classes/be/pxl/ja/command/HelpCommand.class differ diff --git a/target/classes/be/pxl/ja/command/RoomsCommand.class b/target/classes/be/pxl/ja/command/RoomsCommand.class new file mode 100644 index 0000000..66c9138 Binary files /dev/null and b/target/classes/be/pxl/ja/command/RoomsCommand.class differ diff --git a/target/classes/be/pxl/ja/command/SuspectsCommand.class b/target/classes/be/pxl/ja/command/SuspectsCommand.class new file mode 100644 index 0000000..c26dcac Binary files /dev/null and b/target/classes/be/pxl/ja/command/SuspectsCommand.class differ diff --git a/target/classes/be/pxl/ja/command/UnlockCommand.class b/target/classes/be/pxl/ja/command/UnlockCommand.class new file mode 100644 index 0000000..f0acda7 Binary files /dev/null and b/target/classes/be/pxl/ja/command/UnlockCommand.class differ diff --git a/target/classes/be/pxl/ja/command/WeaponsCommand.class b/target/classes/be/pxl/ja/command/WeaponsCommand.class new file mode 100644 index 0000000..1728105 Binary files /dev/null and b/target/classes/be/pxl/ja/command/WeaponsCommand.class differ diff --git a/target/classes/cluedo.txt b/target/classes/cluedo.txt new file mode 100644 index 0000000..76024e2 --- /dev/null +++ b/target/classes/cluedo.txt @@ -0,0 +1,25 @@ +#ROOMS +Hall +Library +Dining +Lounge +Study +Study +Billiard +Conservatory +Ball +Kitchen +#WEAPONS +Candlestick +Revolver +Knife +Lead Pipe +Rope +Spanner +#SUSPECTS +Mrs. White;62;American;Housekeeper +Mr. Green;35;French;Reverend +Mrs. Peacock;32;Canadian;Socialite +Professor Plum;36;American;Professor +Miss Scarlet;25;Italian;Actress +Colonel Mustard;61;Irish;Colonel diff --git a/target/classes/crackthecode.txt b/target/classes/crackthecode.txt new file mode 100644 index 0000000..1212750 --- /dev/null +++ b/target/classes/crackthecode.txt @@ -0,0 +1,28 @@ +#1 +6 8 2 – One Number is correct and well placed +6 1 4 – One Number is correct but wrongly placed +2 0 6 – Two Numbers are correct but wrongly placed +7 3 8 – Nothing is correct +8 7 0 – One Number is correct but wrongly placed +ANSWER: 0 4 2 +#2 +3 4 2 - One Number is correct and well placed +2 7 3 - Nothing is correct +1 6 5 - One Number is correct but wrongly placed +8 5 3 - One Number is correct and well placed +2 6 4 - Two Numbers are correct but wrongly placed +ANSWER: 8 4 6 +#3 +2 9 1 - One Number is Correct and in the Right Place +2 4 5 - One Number is Correct but in the Wrong Place +4 6 3 - Two Numbers are Correct but in the Wrong Place +5 7 8 - Nothing is Correct +5 6 9 - One Number Is Correct But in the Wrong Place +ANSWER: 3 9 4 +#4 +4 6 0 - One number is correct and in the right place +4 9 2 - One number is correct but in the wrong place +0 8 4 - Two numbers are correct but in the wrong place +5 1 6 - Nothing is correct +5 6 8 - One number is correct but in the wrong place +ANSWER: 8 2 0 diff --git a/target/test-classes/CluedoTests/DescribeCommandTests.class b/target/test-classes/CluedoTests/DescribeCommandTests.class new file mode 100644 index 0000000..28be174 Binary files /dev/null and b/target/test-classes/CluedoTests/DescribeCommandTests.class differ diff --git a/target/test-classes/CluedoTests/GoToCommandTests.class b/target/test-classes/CluedoTests/GoToCommandTests.class new file mode 100644 index 0000000..ea5705d Binary files /dev/null and b/target/test-classes/CluedoTests/GoToCommandTests.class differ