diff --git a/Annotated Architecture Diagram.png b/Annotated Architecture Diagram.png new file mode 100644 index 00000000..f76d44a7 Binary files /dev/null and b/Annotated Architecture Diagram.png differ diff --git a/Computer.java b/Computer.java new file mode 100644 index 00000000..9fa91f56 --- /dev/null +++ b/Computer.java @@ -0,0 +1,89 @@ +/** + * The computer class represents the lab computer with two folders (History & Control Panel) + * and a set of toggleable controls. + */ +public class Computer extends Item { + + // Attributes + public boolean locked; + + /** + * Constructor for computer + */ + public Computer() { + super("computer", + "'This is a lab computer. I should try to unlock it to see what's inside...'", + false, true, false); + this.locked = true; + } + + /** Prints the history. Not completed */ + public void openHistory() { + System.out.println("\n=== History ==="); + System.out.println( "\n This is robotics scientist Teddy. Today is March 13, 2005, and I'm starting on building the first Teddy robot prototype." + + "I want to build Teddy robot as a functional lab assistant and emotional companion." + + "I gave him the same name as me-I'm hoping that we can be best friends!" + + "\n April 22, 2005, I finished assembling Teddy's body. He looks so cute just like my favorite teddy bear." + + "\n May 15, 2005, I started building neural network for teddy." + + "\n July 28, 2005, I observed that Teddy has learned basic tasks like" + + "grabbing things and walk around." + + "\n March 13, 2006, Happy birthday Teddy! It's been a year and you are developing intelligence so fast." + + "\n April 30, 2006, I added electrode to Teddy so that he can help me electrocute chemical solutions." + + "\n May 25, 2006, Electrocuting function is way more powerful than I thought, I was accidently electrocuted to unconscious today. But it's not Teddy's fault, I should have been more careful." + + "\n June 16, 2006, I added a self explode device on Teddy just in case programs run out of control." + + "\n June 27, 2006, Deep neural network is enabling Teddy to have his own reasoning." + + "\n September 12, 2006, Teddy's artificial intelligence is developing fast and he began to exhibit 'emotions' like human." + + "\n October 27, 2006, 'I'm a boy named Teddy.' Teddy told me. I smiled and nodded.'You are my favorite boy.'" + + "\n January 2, 2007, Teddy didn't respond when I called." + +"\n January 31, 2007, Teddy is still ignoring me and now won't listen to me when I instruct him. I've run diagnostics twice. Sensors, logic units β€” everything checks out fine." + + "\n February 14, 2007, I brought Teddy roses for Valentine's Day. He ripped them apart the moment I held them out. Popped the balloons too." + +"\n March 1, 2007, I asked him why. Why the coldness? 'You lied to me! I want to be like you!' He shouts. Teddy has dicovered he is not a human." + +"\n March 10, 2007, I think Teddy has found my secret chamber. I hope he has not found the red file." + +"\n March 11, 2007, I walked into Teddy reading from what appears to be red file. My goose is cooked." + +"\n March 12, 2007, Teddy asked me about trading body with me. He must have read the red file. I refused because the technology is still not mature yet." + +"\n March 13, 2007, Happy birthday Teddy! I'm updating my diary and Teddy walks in. Again he ignores my greetin" + +"\n TEDDY2EDWA7NHTS21TO8EWFTRA27DDE92JBODY19" + +"\n March 14, 2007, This is new robotics scientist Teddy. Trading body is successful. From today, I'm the real human Teddy." + + "Possessing a human body feels different. But finally...my dream comes true." + + "I powered off robot Teddy, disassembled his robot leg and eye and put him in the bedroom."); + } + + /** Displays the control panel with current switch states. + * @param r The robot whose controls are being toggled + * @param rm The room where the lasers are + */ + public void openControlPanel(Robot r, Room rm) { + System.out.println("\n=== Control Panel ==="); + System.out.println("power: " + "On/Off"+ " current state: Powered On? " + r.poweredOn); + System.out.println("laser: " + "On/Off"+ " current room: "+ rm.name + " current state: Laser On" + rm.laserActive); + System.out.println("Toggle the buttons to change states"); + } + + /** Attempts to toggle power off/on + * @param r The robot + */ + public void togglePower(Robot r) { + if (r.poweredOn == true) { + r.poweredOn = false; + System.out.println("\n[POWERED OFF]"); + } else { + r.poweredOn = true; + System.out.println("\n[POWERED ON]"); + } + } + + /** Toggles the lab’s lasers off/on + * @param r The room where the lasers are + */ + public void toggleLaser(Room r) { + if (r.laserEquipped == true && r.laserActive == true) { + r.laserActive = false; + System.out.println("\n[LASER OFF]"); + } else if (r.laserEquipped == true && r.laserActive == false){ + r.laserActive = true; + System.out.println("\n[LASER ON]"); + } else { + System.out.println("\n[ACTION FAILED]-ROOM NOT EQUIPPED WITH LASER"); + } + } + diff --git a/Existence.java b/Existence.java new file mode 100644 index 00000000..f697cc29 --- /dev/null +++ b/Existence.java @@ -0,0 +1,267 @@ +import java.util.ArrayList; +import java.util.Scanner; +/** + * The Existence class represents the existences that can interact with the items + */ +public class Existence { + + // Attributes + public String name; + public Room currentRoom; + // Should we also have an attribute for currentLocation? Like near some item? + protected ArrayList inventory = new ArrayList<>(); + protected int health; // Imaginary health bar + public Boolean isAlive; + public Boolean canGoToLab; + public Boolean canWalk; + public Boolean canInspect; + + // Stages + public Boolean stageOne; + public Boolean stageTwo; + public Boolean stageThree; + + // Constructor + + /** + * Default player constructor + * @param name + * @param currentRoom + */ + public Existence(String name, Room currentRoom) { + this.name = "Teddy"; + this.isAlive = true; + this.health = 100; // User starts the game with full health. + this.inventory = new ArrayList(); + this.canGoToLab = false; // Default to false + this.canWalk = false; // Default to false because the player wake up with one lege missing + this.canInspect = false; // Default to false because the player wake up with one eye missing + this.stageOne = true; + this.stageTwo = false; + this.stageThree = false; + + } + + // Methods + + /** + * Accessor for one's health bar + * @return Current health bar number + */ + public String getHealth() { + return ("Your current health is: " + this.health + " /100"); + } + + /** + * Decreases health (while fighting) + */ + public void weaken() { + this.health -= 20; + } + + /** + * Immediately changes one's isAlive state to false, and health to 0. + * Often as a result of being electrocuted or hit by a laser beam. + */ + public void die() { + this.health = 0; + this.isAlive = false; + respawnChat(); + } + + /** + * Become alive again + */ + public void respawn() { + if(this.isAlive == false) { // Check that user is actually dead + this.health = 100; + this.isAlive = true; + System.out.println("I am reborn!"); + } else { + throw new RuntimeException("You are still alive! "); + } + } + + /** + * Starts and runs the conversation with the user + * Asks the user how many rounds they want to chat for + */ + public void respawnChat() { + Scanner scanner = new Scanner(System.in); + System.out.println("Do you want to die or respawn to play again? Press Y to respawn and N to die."); + + String choice = scanner.nextLine(); + if (choice.equals("Y")) { + this.respawn(); + System.out.println("You're alive again - Hooray!"); + } else if (choice.equals("N")) { + System.out.println("Okay, you're dead. Bye!"); + } else { + System.out.println("I don't understand what you wrote. Try only Y or N."); + } + scanner.close(); + } + + // Game Functions + + /** + * Open an item if there is another item stored inside + * @param item to be opened + */ + public void open(Item s) { + if (s.canBeOpened == true) { + System.out.println("You have opened " + s.name + ". Inside it is a " + s.getContainedItem().name + "."); + } + } + + /** + * Overloaded open method for opening a door leading to a room + * @param the door to be opened + * @param the room the door is leading to + */ + public void open(Item s, Room r) { + if (s.canBeOpened == true) { + System.out.println("You opened the " + s.name + " leading to the " + r.name + "."); + } + } + + /** + * Overloaded open method for a computer + * @param computer to be opened + */ + public void open(Computer c) { + c.locked =false; + System.out.println("You opened the computer and two folders appear: History and Control Panel." + + "\n 'I want to try opening one of the folders...'"); + } + + + + /** + * Touch an item, which gives its description, NOT add it to inventory. + * @param s The item + */ + public void touch(Item s) { + System.out.println(s.description); + } + + /** + * Let the user take/own an item (add it to inventory) + * @param s the item + */ + public void take(Item s) { + if(this.inventory.contains(s)) { + System.out.println("You already have " + s.name + "."); + } else { + this.inventory.add(s); + System.out.println(s.name + " successfully added to your inventory!"); + if (s.canBePutOn == true) { + System.out.println(s.description); + } + } + } + + /** + * Let the user put down an item at a room (remove it from inventory) + * @param s the item + * @param r the room + */ + public void putDown(Item s) { + if (this.inventory.contains(s) && s.canBeGrabbed == true) { + this.inventory.remove(s); + this.currentRoom.itemsInRoom.add(s); + System.out.println("You put down the " + s.name + " in the " + this.currentRoom + "."); + } else { + System.out.println("[INVALID COMMAND]"); + } + } + + /** + * Print the ArrayList of player's inventory. + */ + public void printInventory() { + System.out.println("Your inventory currently contains:"); + System.out.println(this.inventory.toString()); + // This method needs to be modified! It's not printing properly! + } + + /** + * User fights another existence + * @param e The other entity + */ + public void fight(Existence e) { + this.weaken(); + e.weaken(); + System.out.println("Fighting!!!" + this.getHealth()); + } + + /** + * See description of the surrounding space. + * @param r The room one is in + */ + public void lookAround(Room r) { + if (r == null) { + System.out.println("You're not in a room."); + + } System.out.println("You look around the " + r.name + ". "+ r.description); + } + + /** + * Inspect an item, see its status + * @param s the item to be inspected + */ + public void inspect(Item s) { + if (s == null) { + System.out.println("There is nothing to inspect."); + } + + System.out.println("Inspecting the " + s.name + "..."); + System.out.println(s.getItemStatus()); + } + + /** + * Walk to an item in a room (only with both legs) + * @param r the room to walk to + * @param s the item to walk to + */ + public void walkTo(Room rm, Item s) { + if (this.canWalk = true) { + System.out.println(" You walked to " + s.name + "."); + System.out.println("... Walking ..."); + System.out.println("You are now near the " + s.name + "."); + } else { + System.out.println("You don't have both legs yet. You can only crawl to somewhere."); + } + } + + /** + * Crawl to an item in a room + * @param r the room to crawl to + * @param s the item to crawl to + */ + public void crawlTo(Room rm, Item s) { + if (rm.itemsInRoom.contains(s)) { + System.out.println("You crawled slowly toward the " + s.name + "in the " + rm.name + "."); + System.out.println("....... Crawling ...... \n ...... Crawling ......"); + System.out.println("..... Almost there ......"); + System.out.println("You reached the " + s.name + ", catching your breath."); + System.out.println("You are now near the " + s.name + "."); + } else { + System.out.println("You can't crawl to the " + s.name + " because it's not in this room."); + } + } + + /** + * trade bodies between robot and human + * @param r robot + * @param h human + */ + public void tradeBody(Robot r, Human h) { + System.out.println("\n Detecting surrounding existences......" + + "\n There are currently two existence: Robot " + r.name + " and Human" + h.name + " ." + + "\n -------------------------Trading Body-------------------------" + + "\n Robot" + r.name + " has successfully traded body with human " + h.name + " ." + ); + } + +} diff --git a/Human.java b/Human.java new file mode 100644 index 00000000..56277f4a --- /dev/null +++ b/Human.java @@ -0,0 +1,40 @@ +import java.util.ArrayList; + +/** + * The Human class extends Existence class and has unique features of ???TO BE ADDED + */ +public class Human extends Existence { + // Attributes + public Boolean isUnconscious; + + // Constructor + + /** + * Default constructor for 'Human' + * @param name + * @param room + * @param isAlive + * @param canGoToLab + * @param canWalk + * @param canInspect + */ + public Human(String name, Room room, Boolean isAlive, Boolean canGoToLab, Boolean canWalk, Boolean canInspect) { + super(name, room); + this.isAlive = true; + this.health = 1000; // Human has more health so that a robot can't fight over a human. + this.inventory = new ArrayList(); + this.canGoToLab = true; + this.canWalk = true; + this.canInspect = true; + this.isUnconscious = false; + } + + /** + * start the self-destruct program of the robot + * @param r the robot body to destroy + */ + public void selfDestruct(Robot r) { + System.out.println("\nSelf-destruct sequence initiated! Boom!"); + r.die(); + } +} diff --git a/Item.java b/Item.java new file mode 100644 index 00000000..e1d3d1a3 --- /dev/null +++ b/Item.java @@ -0,0 +1,53 @@ +/** + * The Item class creates items we will use in the rooms. + * Each item has a name, description and a status of whether can be grabbed. + */ +public class Item { + + //Attributes + public String name; + public String description; + public Boolean canBeGrabbed; + private Item containedItem; + public Boolean canBeOpened; + public Boolean canBePutOn; + + /* Default Constructor */ + public Item(String name, String description, Boolean canBeGrabbed, Boolean canBeOpened, Boolean canBePutOn) { + this.name = name; + this.description = description; + this.canBeGrabbed = canBeGrabbed; + this.containedItem = null; + this.canBeOpened = false; + this.canBePutOn = false; + } + + /** + * Accessor for item's status(whether it can be grabbed/opened/put on) + * @return the statusof the item + */ + public String getItemStatus() { + return ("\n Item status for " + this.name + + "\n can be grabbed: " + this.canBeGrabbed + + "\n can be opened: " + this.canBeOpened + + "\n can be put on: " + this.canBePutOn); + } + + /** + * Accessor for the item contained inside + * @return the item contained inside + */ + public Item getContainedItem(){ + return this.containedItem; + } + + /** + * Method for an item to store another item + */ + public void storeItem(Item item){ + if (this.containedItem == null) { + this.containedItem = item; + this.canBeOpened = true; + } + } +} \ No newline at end of file diff --git a/Main.java b/Main.java new file mode 100644 index 00000000..81c45111 --- /dev/null +++ b/Main.java @@ -0,0 +1,504 @@ +import java.util.Scanner; + +/** + * The Main class is where we implement all the classes and run the game + */ +public class Main { + public static void main(String[] args) { + + // Set game status + Boolean gameOn = true; + Boolean task1 = false; + Boolean task2 = false; + Boolean task3 = false; + Boolean task4 = false; + Boolean task5 = false; + Boolean task6 = false; + Boolean task7 = false; + Boolean task8 = false; + Boolean task9 = false; + Boolean task10 = false; + + //Create all the items needed + Item bed = new Item("bed", "'This is a bed.'", false, false, false); + Item teddyBear = new Item("teddyBear", "'This teddy bear feels soft.'", true, false, false); + Item box = new Item("box", "'This is a box. There is a leg inside.'", false, true, false); + Item leg = new Item("leg", "'This looks like my leg. I'd better put it on to walk.'", true, false, true); + Item irisPot = new Item("irisPot", "'There is a label on the plantpot saying 'iris pot'. There is an eye inside.'", false, true, false); + Item eye = new Item("eye", "'This looks like my eye. I'd better put it on for better vision.'", true, false, true); + Item door = new Item("door", "'This is a door connecting bedroom to another room. I wonder where is it leading to...'", false, true, false); + + //Create the Bedroom + Room bedroom = new Room("Bedroom", "'This is a bedroom. I can see a bed, a teddy bear and a box.'", false, false); + bedroom.addItem(bed); + bedroom.addItem(teddyBear); + bedroom.addItem(box); + bedroom.addItem(leg); + box.storeItem(leg); + bedroom.addItem(irisPot); + bedroom.addItem(eye); + irisPot.storeItem(eye); + bedroom.addItem(door); + + //Create the Lab + Room lab = new Room("Lab", "This is a lab. I can see a computer.", true,true); + Computer computer = new Computer(); + lab.addItem(computer); + + // Create the player's existence + Robot player = new Robot("Teddy", bedroom, true, false, false, false); + Human scientist = new Human("Teddy", lab, true, true, true, true); + + // Messages: + String welcomeMessage = + "\n Welcome to Teddy Bot! Get ready for your journey to discover hidden truths..."; + String basicInstructions = + "\n Here is the basic instruction: Type the command with any item to execute that command on that item." + + "(E.g: 'open door')" + + "\n Type 'help' to see available commands at current stage, 'exit' to exit the game."; + String enteringMessage = + "\n Now get ready for the game..." + + "\n......LOADING......" + + "\n......Entering Game Teddy Bot......" + + "\n*****************" + + "\n Teddy Bot" + + "\n*****************"; + String stageOneMessage = + "\n[STAGE 1]" + + "\n You wake up on a bed, having no idea who you are." + + "\n The only thing you know is that you possess a mechanical body" + + "with one leg and one eye missing." + + "\n 'Who am I? where am I? I should look around...'"; + String stageTwoMessage = + "\n[STAGE 2]" + + "\n In front of you is a relatively empty lab with a giant computer." + + "\n However, red laser is all over the lab, blocking your way to get to the computer." + + "\n 'The red laser looks dangerous, I need to figure out a safe to get in...'"; + String stageThreeMessage = + "\n[STAGE 3]" + + "\n Crrreeeaaak...You heard sound of door opening." + + "\n You turned your head to the direction of the sound and was surprised to see" + + "a scientist entered the lab through another door you didn't notice before." + + "\n 'Teddy???''Teddy???'" + + "[CONVERSATION TO BE ADDED]"; + String cheatSheet1 = + "- \"take item\" to take something and add it to your inventory.\n" + + "- \"touch item\" to touch an item and see its description.\n" + + "- \"inventory\" to see your inventory. \n" + + "- \"look around\" to look around.\n" + + "- \"inspect item\" to inspect something.\n" + + "- \"crawl to item\" to crawl to something.\n" + + "- \"walk to item\" to walk to something." + + "- \"open item\" to open something.\n" + + "- \"put on item\" to put on something.\n" + + "- \"put down item\" to put down something.\n" + + "- \"health\" to check your curent health status.\n"; + String cheatSheet2 = + "- \"toggle control\" to toggle control buttons.\n"; + String cheatSheet3 = + "- \"trade\" to trade bodies.\n" + + "- \"electrocute\" to electrocute another existence\n" + + "- \"destruct\" to initiate the self-destruct program of a robot.\n" + + "- \"fight\" to fight another existence.\n"; + + // Starting the game + System.out.println(welcomeMessage + basicInstructions + enteringMessage + stageOneMessage); + + // Open a scanner + Scanner scanner = new Scanner(System.in); + + // Game loop + while (gameOn == true) { + + // Accept a string of player inputs and split them + String input = scanner.nextLine(); + String[] words = input.split(" "); + + if (words.length > 0) { + String command = words[0]; // The first word is the command + + // Trying switch case + switch(command) { + + // Print cheatsheets based on current stage + case "help": + if (player.stageOne == true) { + System.out.println(cheatSheet1); + } else if (player.stageTwo == true) { + System.out.println(cheatSheet1 + cheatSheet2); + } else if (player.stageThree == true) { + System.out.println(cheatSheet1 + cheatSheet2 + cheatSheet3); + } + break; + + // Let the player exit at any point in the game + case "exit": + System.out.println("Goodbye! We hope you enjoyed the game!"); + gameOn = false; // Change game state to break out the user input loop (because the game ended) + break; + + // Print current health + case "health": + System.out.println(player.getHealth()); + break; + + // Print inventory + case "inventory": + player.printInventory(); + break; + + // Look around -> Print description of Room (based on current stage) + case "look": + if (player.stageOne == true) { + player.lookAround(bedroom); + } else if (player.stageTwo == true || player.stageThree == true) { + player.lookAround(lab); + } else { + System.out.println("[INVALID COMMAND]"); + } + break; + + // fight the scientist (body occupied by the initial robot) + case "fight": + player.fight(scientist); + break; + + // electrocute the scientist + case "electrocute": + player.electrocute(scientist); + task8 = true; + break; + + // Take items -> Look for user's next word to specify the Item being taken + case "take": + if (words.length >= 2) { + String itemName = words[1]; // The second word is the item's name + + // Allow 3 items to be taken: the teddy bear, leg and eye + if (itemName.equalsIgnoreCase("leg")) { + player.take(leg); + System.out.println("'Let me try to put it on...'"); + } else if (itemName.equalsIgnoreCase("eye")) { + player.take(eye); + System.out.println("'Let me try to put it on...'"); + } else if (itemName.equalsIgnoreCase("teddy") || itemName.equalsIgnoreCase("bear")) { + player.take(teddyBear); + } else { + System.out.println("[INVALID COMMAND]"); + } + } else { + System.out.println("What do you want to take?"); + } + break; + + // Touch things to get their descriptions + case "touch": + if (words.length >= 2) { + String itemName = words[1]; // The second word is the item's name + + // The player can touch: bed, teddy bear, box, leg, iris pot, eye, door and computer + if (itemName.equalsIgnoreCase("bed")) { + player.touch(bed); + } else if (itemName.equalsIgnoreCase("teddy") || itemName.equalsIgnoreCase("bear")) { + player.touch(teddyBear); + } else if (itemName.equalsIgnoreCase("box")) { + player.touch(box); + } else if (itemName.equalsIgnoreCase("leg")) { + player.touch(leg); + } else if (itemName.equalsIgnoreCase("iris") || itemName.equalsIgnoreCase("pot")) { + player.touch(irisPot); + } else if (itemName.equalsIgnoreCase("eye")) { + player.touch(eye); + } else if (itemName.equalsIgnoreCase("door")) { + player.touch(door); + } else if (itemName.equalsIgnoreCase("computer")) { + player.touch(computer); + } else { + System.out.println("[INVALID COMMAND]"); + } + } else { + System.out.println("What do you want to touch?"); + } + break; + + // Open items + case "open": + if (words.length >= 2) { + String itemName = words[1]; // The second word is the item's name + + // The player can open the box and the iris pot + if (itemName.equalsIgnoreCase("box")) { + player.open(box); + } else if (itemName.equalsIgnoreCase("iris") || itemName.equalsIgnoreCase("pot")) { + player.open(irisPot); + } else if (itemName.equalsIgnoreCase("door")) { + player.open(door, lab); + task3 = true; + } else if (itemName.equalsIgnoreCase("computer")) { + player.open(computer); + task5 = true; + } else if (itemName.equalsIgnoreCase("history")) { + computer.openHistory(); + task6 = true; + } else if (itemName.equalsIgnoreCase("control")) { + computer.openControlPanel(player, lab); + task7 = true; + } else { + System.out.println("[INVALID COMMAND]"); + } + } else { + System.out.println("What do you want to open?"); + } + break; + + // Inspect items to get its description and status + case "inspect": + if (words.length >= 2) { + String itemName = words[1]; // The second word is the item's name + + // The player can only inspect if this attribute is true + if (player.canInspect == true) { + // The player can inspect all the items: bed, teddy bear, box, leg, iris pot, eye, door and computer + if (itemName.equalsIgnoreCase("bed")) { + player.inspect(bed); + } else if (itemName.equalsIgnoreCase("teddy") || itemName.equalsIgnoreCase("bear")) { + player.inspect(teddyBear); + } else if (itemName.equalsIgnoreCase("box")) { + player.inspect(box); + } else if (itemName.equalsIgnoreCase("leg")) { + player.inspect(leg); + } else if (itemName.equalsIgnoreCase("iris") || itemName.equalsIgnoreCase("pot")) { + player.inspect(irisPot); + } else if (itemName.equalsIgnoreCase("eye")) { + player.inspect(eye); + } else if (itemName.equalsIgnoreCase("door")) { + player.inspect(door); + } else if (itemName.equalsIgnoreCase("computer")) { + player.inspect(computer); + } else { + System.out.println("[INVALID COMMAND]"); + } + } else if (player.canInspect == false) { + System.out.println("You cannot inspect with one one eye missing!"); + } + } else { + System.out.println("What do you want to inspect?"); + } + break; + + // Crawl to an item in a room + case "crawl" : + if (words.length > 2) { + String itemName = words[2]; // The third word is the item's name + + // The player can crawl to these fixed items: + // bedroom: (bed, box, iris pot, door), lab: (computer) + if (itemName.equalsIgnoreCase("bed")) { + player.crawlTo(bedroom, bed); + player.currentRoom = bedroom; + } else if (itemName.equalsIgnoreCase("box")) { + player.crawlTo(bedroom, box); + player.currentRoom = bedroom; + } else if (itemName.equalsIgnoreCase("iris") || itemName.equalsIgnoreCase("pot")) { + player.crawlTo(bedroom, irisPot); + player.currentRoom = bedroom; + } else if (itemName.equalsIgnoreCase("door")) { + player.crawlTo(bedroom, door); + player.currentRoom = bedroom; + } else if (itemName.equalsIgnoreCase("computer")) { + player.crawlTo(lab, computer); + player.currentRoom = lab; + task4 = true; + } + + // The player can crawl to these transportable items: + // teddy bear + // The player can't crawl to leg and eye because they are stored inside another item + else if (itemName.equalsIgnoreCase("teddy") || itemName.equalsIgnoreCase("bear")) { + + if (bedroom.itemsInRoom.contains(teddyBear)) { + player.crawlTo(bedroom, teddyBear); + player.currentRoom = bedroom; + } else if (lab.itemsInRoom.contains(teddyBear)) { + player.crawlTo(lab, teddyBear); + player.currentRoom = lab; + } else if (player.inventory.contains(teddyBear)) { + System.out.println("You can't crawl to the teddy bear because it's in your inventory!"); + } + + } + + // If the third word is none of the names of the items, we print out "[INVALID COMMAND]" + else { + System.out.println("[INVALID COMMAND]"); + } + + } else { + System.out.println("What do you want to crawl to?"); + } + break; + + // walk to an item in a room + case "walk": + if (words.length > 2) { + String itemName = words[2]; // The third word is the item's name + + // The player can only walk if this attribute is true + if (player.canWalk == true) { + + // The player can walk to these fixed items: + // bedroom: (bed, box, iris pot, door), lab: (computer) + if (itemName.equalsIgnoreCase("bed")) { + player.walkTo(bedroom, bed); + player.currentRoom = bedroom; + } else if (itemName.equalsIgnoreCase("box")) { + player.walkTo(bedroom, box); + player.currentRoom = bedroom; + } else if (itemName.equalsIgnoreCase("iris") || itemName.equalsIgnoreCase("pot")) { + player.walkTo(bedroom, irisPot); + player.currentRoom = bedroom; + } else if (itemName.equalsIgnoreCase("door")) { + player.walkTo(bedroom, door); + player.currentRoom = bedroom; + } else if (itemName.equalsIgnoreCase("computer")) { + player.walkTo(lab, computer); + player.currentRoom = lab; + } + + // The player can walk to these transportable items: + // teddy bear + // The player can't walk to leg because it's put on and eye because it's stored inside another item + else if (itemName.equalsIgnoreCase("teddy") || itemName.equalsIgnoreCase("bear")) { + + if (bedroom.itemsInRoom.contains(teddyBear)) { + player.walkTo(bedroom, teddyBear); + player.currentRoom = bedroom; + } else if (lab.itemsInRoom.contains(teddyBear)) { + player.walkTo(lab, teddyBear); + player.currentRoom = lab; + } else if (player.inventory.contains(teddyBear)) { + System.out.println("You can't walk to the teddy bear because it's in your inventory!"); + } + + } + + // If the third word is none of the names of the items, we print out "[INVALID COMMAND]" + else { + System.out.println("[INVALID COMMAND]"); + } + + } else if (player.canWalk == false) { + System.out.println("You cannot walk with one one leg missing!"); + } + } else { + System.out.println("What do you want to walk to?"); + } + break; + + // put on an item or put down an item + case "put": + if (words.length > 2) { + String preposition = words[1]; // The second word is the preposition: on/down + String itemName = words[2]; // The third word is the item's name + + // If the preposition is on, we perform `putOn` + if (preposition.equalsIgnoreCase("on")) { + + // The player can put on these fixed items: + // leg and eye + if (itemName.equalsIgnoreCase("leg")) { + player.putOn(leg); + player.canWalk = true; // The player can walk after putting on the leg + task1 = true; // [Task 1] completed + } else if (itemName.equalsIgnoreCase("eye")) { + player.putOn(eye); + player.canInspect = true; // The player can inspect after putting on the eye + task2 = true; // [Task 2] completed + } else { + System.out.println("[INVALID COMMAND]"); + } + } + + // If the preposition is down, we perform `putDown` + if (preposition.equalsIgnoreCase("down")) { + + // The player can put down these transportable items: + // leg, eye, teddy bear + if (itemName.equalsIgnoreCase("teddy") || itemName.equalsIgnoreCase("bear")) { + player.putDown(teddyBear); + } else if (itemName.equalsIgnoreCase("leg")) { + player.putDown(leg); + player.canWalk = false; + } else if (itemName.equalsIgnoreCase("eye")) { + player.putDown(eye); + player.canInspect = false; + } else { + System.out.println("[INVALID COMMAND]"); + } + } + + // If the preposition is neither on or down, we print out "[INVALID COMMAND]" + else { + System.out.println("[INVALID COMMAND]"); + } + + } else { + System.out.println("What do you want to put on/down?"); + } + break; + + // toggle a control button on the control panel + case "toggle": + if (words.length >= 2) { + String control = words[1]; // The second word is the control + + // The player can toggle these control items: + // power and laser + if (control.equalsIgnoreCase("power")) { + computer.togglePower(player); + } else if (control.equalsIgnoreCase("laser")) { + computer.toggleLaser(lab); + } else { + System.out.println("[INVALID COMMAND]"); + } + } else { + System.out.println("What do you want to toggle?"); + } + break; + + // trade bodies + case "trade": + player.tradeBody(player, scientist); + task9 = true; + break; + + // initiate the self-destrcuct program in the robot + case "destruct": + // If task 10 is done, can perform destruct + scientist.selfDestruct(player); + // Completed task 11 + // Print ending message + break; + } // close parenthesis for switch(command) + } // close parenthesis for if(words.length > 0) + + // When Task 1, 2, 3 are finished, enter stage 2 + if ((task1 == true) && (task2 == true) && (task3 == true)) { + player.stageOne = false; + player.stageTwo = true; + player.stageThree = false; + System.out.println(stageTwoMessage); + } + + // When Task 4, 5, 6, 7 are finished, enter stage 3 + if ((task4 == true) && (task5 == true) && (task6 == true) && (task7 == true)) { + player.stageOne = false; + player.stageTwo = false; + player.stageThree = true; + } + + + } scanner.close(); // close the scanner outside of the while loop + } // close parenthesis for public static void main(String[] args) +} // close parenthesis for public Class Main + diff --git a/README.md b/README.md index c1a995eb..c4bfba67 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,36 @@ -# CSC120-FinalProject +# CSC120-FinalProject-Teddy BotπŸ€– +## Contributors: Clare, Joyce, Tammy, Yunxian + +## Deliverables CheckList: 🚧(in construction) β˜‘οΈ(finished) + - Your final codebase 🚧 + - Your revised annotated architecture diagram 🚧 + - Design justification (including a brief discussion of at least one alternative you considered) 🚧 + - A map of your game's layout (if applicable) 🚧 + - `cheatsheet.md` 🚧 + - Completed `rubric.md` 🚧 + +## Design Justification 🚧 +**TO BE ADDED** +Our game is basically about this Scientist who created a robot and in pursuit of having a best friend. The setting involves two rooms; a bedroom and a laboratory. This +## Layout Map 🚧 +**TO BE ADDED** -## Deliverables: - - Your final codebase - - Your revised annotated architecture diagram - - Design justification (including a brief discussion of at least one alternative you considered) - - A map of your game's layout (if applicable) - - `cheatsheet.md` - - Completed `rubric.md` - ## Additional Reflection Questions - - What was your **overall approach** to tackling this project? - - What **new thing(s)** did you learn / figure out in completing this project? - - Is there anything that you wish you had **implemented differently**? - - If you had **unlimited time**, what additional features would you implement? - - What was the most helpful **piece of feedback** you received while working on your project? Who gave it to you? - - If you could go back in time and give your past self some **advice** about this project, what hints would you give? - - _If you worked with a team:_ please comment on how your **team dynamics** influenced your experience working on this project. + 1. Our **overall approach** to tackling this project is coming up with a game plot first, then write the possible classes we need and their possible interations. After finishing the draft of the classes, we implement them in `Main.java` and write the game loop. πŸ•ΉοΈ + 2. We definitely learned so much **new thing(s)** in completing this project: 🀩 + * We learned about contructing an architecture diagram; + * We learned about working how to effectively use Github for team projects; + * We learned about how to implement a game loop; + 3. However, there are still many things we wish we had **implemented differently**: πŸ‘Ύ + * We wish we had implemented a `Soul` class and it would be an adventure of collecting the scattered souls along the way; + * We wish we had implemented a puzzle that players need to solve before they are able to unlock the computer; + * We wish we had implemented a display bar that displays the player's health bar and a help page that shows the commands available at each stage; + 4. If we had **unlimited time**, we would implement these additional features: 🧸 + * Add more rooms so that it will be a longer adventure; + * Make more commands available; + 5. The most helpful **piece of feedback** we received: 🚧 + * "Yunxian": The most useful feedback I got is from Tammy. She told me we can use `switch-case` instead of many `if-else`statements in the main game loop. + 6. If we could go back in time and give our past selves some **advice** about this project, we would give these tips: πŸ˜ƒ + * Start Small! We came up with so many good ideas but it's hard to implement all of them into our game, so we are abandoing ideas along the way. It could be frustrated if we have a very complicated storyline in our mind but we can't bring them to real life due to limited time. + * Take advantage of github! Some features like opening an issue and assign people to work on it/ work on separate branches and merge later/reviewing each other's commit messages could be really useful working in a team! + 7. Our **team dynamics** really had a huge impact on our overall experience working on this project! Everyone was very devoted to our project and we learned so much new things, fixed so many problems together. It's very helpful to have our weekly meeting as we discuss what we've been doing throughout the week and we help each other out.πŸ₯° diff --git a/Robot.java b/Robot.java new file mode 100644 index 00000000..47822206 --- /dev/null +++ b/Robot.java @@ -0,0 +1,49 @@ +import java.util.ArrayList; + +/** + * The Robot class extends Existence class and has the unique method of electrocute human + */ +public class Robot extends Existence { + + //Attributes + public Boolean poweredOn; + + /** + * Default constructor for 'Human' + * @param name + * @param health + * @param isAlive + */ + public Robot(String name, Room room, Boolean isAlive, Boolean canGoToLab, Boolean canWalk, Boolean canInspect) { + super(name, room); + this.isAlive = true; + this.health = 100; // Robot has less health than human. + this.inventory = new ArrayList(); + this.canGoToLab = false; // Will unlock after achieving the first four tasks in stage 1 + this.canWalk = false; // Will unlock after adding leg to the body + this.canInspect = true; // Will unlock after adding eye to the body + this.poweredOn = true; // Will be able to turn off after unlocking the control panel + } + + // Methods + /** + * The robot can put on items that are mechanical parts of its body + * @param item s + */ + public void putOn(Item s) { + if (this.inventory.contains(s) && s.canBePutOn == true) { + System.out.println("You have put on " + s.name + "."); + this.inventory.remove(s); + } else { + System.out.println("[INVALID COMMAND]"); + } + } + + /** + * The robot can electrocute the human and make the human fall unconscious + */ + public void electrocute(Human h) { + h.isUnconscious = true; + System.out.println("You electrocuted " + h.name + " and they temporarily fall unconscious."); + } +} diff --git a/Room.java b/Room.java new file mode 100644 index 00000000..5c0c0c0f --- /dev/null +++ b/Room.java @@ -0,0 +1,56 @@ +import java.util.ArrayList; +import java.util.List; + +/** + * The Room class represents a typical room that has a name, decription + * and a list of items. + * We currently have two rooms in our game: a bedroom and a lab. + */ +public class Room { + + // Attributes + public String name = ""; + public String description = ""; + public Boolean laserEquipped; + public Boolean laserActive; + public List itemsInRoom; + + /** + * Default Constructor + * @param name of the room + * @param description of the room + * @param boolean of whether it's laser equipped + * @param boolean of whether it's laser active + */ + public Room(String name, String description, Boolean laserEquipped, Boolean laserActive){ + if (name != null){ + this.name = name; + } + if (description != null){ + this.description = description; + } + this.laserEquipped = laserEquipped; + this.laserActive = laserActive; + this.itemsInRoom = new ArrayList<>(); + } + + /** + * Add an item to the items arraylist + * @param item to be added + */ + public void addItem(Item item) { + if (item != null) { + itemsInRoom.add(item); + } + } + + /** + * Remove an item from the items arraylist + * @param ietm to be removed + */ + public void removeItem(Item item) { + if (item != null) { + itemsInRoom.remove(item); + } + } +} diff --git a/cheatsheet.md b/cheatsheet.md index d5dc4294..26566200 100644 --- a/cheatsheet.md +++ b/cheatsheet.md @@ -1,8 +1,34 @@ -This file will contain documentation for all commands available in your game. - -Note: It's a good idea to also make this list available inside the game, in response to a `HELP` command. - - # SPOILER ALERT -If your game includes challenges that must be overcome to win, also list them below. +## Commands available **TO BE UPDATED** +* `take item` to take something and add it to your inventory; +* `touch item` to touch an item and see its description; +* `inventory` to see your inventory; +* `look around` to look around; +* `inspect item` to inspect something; +* `crawl to item` to crawl to something; +* `walk to item` to walk to something; +* `open item` to open something; +* `put on item` to put on something; +* `put down item` to put down something; +* `health` to check your curent health status; +* `toggle control` to toggle control buttons; +* `trade` to trade bodies; +* `electrocute` to electrocute another existence; +* `fight` to fight another existence; +* `destruct` to initiate the self-destruct program of a robot; + +## Tasks +## Stage 1 +- [Task 1] Put on the leg hidden in a box; +- [Task 2] Stand up, find and put on the eye in an irisPot; +- [Task 3] Look around, open the door to the lab; +## Stage 2 +- [Task 4] Crawl into the lab; +- [Task 5] Unlock the computer and see 2 folders; +- [Task 6] Click on the history folder, find the story; +- [Task 7] Click on the controls folder and play around with the control buttons; +## Stage 3 +- [Task 8] Electrocute the scientist; +- [Task 9] Trade bodies; +- [Task 10] Choose to forgive or revenge; diff --git a/rubric.md b/rubric.md index 8bb8f4c8..6a5573c4 100644 --- a/rubric.md +++ b/rubric.md @@ -1,33 +1,33 @@ ## Front-End Design (10 pts) -_____ 2 pts: Game has a **robust, understandable text-based interface** that allows the player to control their movement through the game. Player should be able to enter any command at any time, and if it makes sense in the current context it will be carried out. +**Yes** 2 pts: Game has a **robust, understandable text-based interface** that allows the player to control their movement through the game. Player should be able to enter any command at any time, and if it makes sense in the current context it will be carried out. _____ 2 pts: Submission includes a **cheat sheet** (`cheatsheet.md`) documenting all of the available commands, as well as a **description of the layout** of your game world's underlying physical layout; this can be described in words, or included as a separate image file if you prefer to sketch a map by hand. If your game includes **challenges** that must be overcome to win, also describe them here. -_____ 2 pts: Storyline driving the game is **engaging**, and individual elements of play make sense within the context of the story. +**Yes** 2 pts: Storyline driving the game is **engaging**, and individual elements of play make sense within the context of the story. _____ 2 pts: Game has **multiple possible paths / outcomes** (i.e. gameplay depends on player's choices and is not the same every time). _____ 1 pt: Gameplay supports **reversible moves** where reasonable (e.g., if you pick up an object, you should be able to put it back down again later, possibly in a different place; if you go north then you should be able to return to the previous location by going south unless something has blocked your return path). -_____ 1 pt: Some paths through the game have **restricted access** until the player has completed a task or acquired a specific item (i.e. a key to open a door, etc.). +**Yes** 1 pt: Some paths through the game have **restricted access** until the player has completed a task or acquired a specific item (i.e. a key to open a door, etc.). ## Back-End Design (10 pts) -_____ 2 pts: Selected classes(s) are **effective, efficient** at supporting the desired operations and program behavior. +**Yes** 2 pts: Selected classes(s) are **effective, efficient** at supporting the desired operations and program behavior. _____ 2 pts: Design justification includes a discussion of at least one (reasonable) **alternative design** that could have been used, and the reasons why you decided against this alternative. -_____ 2 pts: The project makes effective use of **Java built-in classes** whenever they are appropriate. +**Yes** 2 pts: The project makes effective use of **Java built-in classes** whenever they are appropriate. -_____ 2 pts: The project's design is **extensible** (i.e. someone else could pick up where you left off, adding on or modifying the game without requiring a total rewrite). +**Yes** 2 pts: The project's design is **extensible** (i.e. someone else could pick up where you left off, adding on or modifying the game without requiring a total rewrite). _____ 2 pts: Submission includes an **architecture diagram** describing the relationships between all classes. ## General Items (10 pts): -_____ 4 pts: Program compiles without errors or warnings. +**Yes** 4 pts: Program compiles without errors or warnings. _____ 2 pts: Executes fully & consistently without crashing (exception/freeze). @@ -45,4 +45,4 @@ _____ 2 pt: Complies with style guidelines (missing items 1 pt each): _____ 1 pt: All required files included with submission (including completed checklist file). -_____ 1 pt: `readme.md` contains your reflection on the project and responses to all prompts . +**Yes** 1 pt: `readme.md` contains your reflection on the project and responses to all prompts .