Question

In: Computer Science

Please include all text files !! Welcome to the second individual assignment in ITEC-3860! The goal...

Please include all text files !!

Welcome to the second individual assignment in ITEC-3860! The goal from these series of individual assignments is to warm up your programming skills for the final project deliverable for your text-based adventure game. In games of this sort, the player wanders around from one location to another, picking up objects, and solving simple puzzles. The program you will create for this assignment is considerably less elaborate than the final project deliverable and it therefore limited in terms of number of rooms, items, monsters etc. Even so, you can still write a program that captures much of the spirit and flavor of the final game. ( text based adventure game )

This handout contains what you need to know about the second individual deliverable along with a number of hints and strategic suggestions.

Assumptions:

  1. Player is able to navigate between rooms
  2. Map information (including rooms’ descriptions, connections) are being retrieved from text file
  3. If you have not retrieve navigation command from text file in the first assignment I didn’t take points off but I will in the second assignment. So, make sure to get this feature implemented. Your navigation commands (N, E, S, W) should be retrieved from text file.
  4. Your code is keeping track of visited rooms

Goal: implement the items and puzzle feature as directed below.

Items feature:

Now that the player is able to navigate between different rooms, for the second assignment deliverable your goal is to allow the player to interact with 3 different items of your choice in three different rooms. Interaction behaviuor with items should include the exact following commands:

  1. Examine item-name: this command will allow the player to retrieve the description of the examined item. Your game should display the description of the examined item to the console/GUI.
  2. Pick item-name: this command will add the item to the player inventory.
    1. Your game should display that the item has been added to the player inventory by displaying the following message to the console/GUI “Item-name has been picked up from the room and successfully added to the player inventory.
    2. Upon picking up an item from a room, the item should disappear from the room and the player should not see the item again when visiting the same room.
  3. Drop item-name: this command should allow the player to access any item in the inventory and drop it in the current room.
    1. When an item is dropped, it should be dropped in the current room and be available for the player to interact with again for reexamine and re-pickup.
    2. Upon dropping an item, your game should display the following message to the console/GUI “Item-name has been dropped successfully from the player inventory and placed in room-name”

Hint: The items will move around in the game as the player picks them up or drops them off. Therefore, your implementation must therefore provide a facility (internal data structure) for storing objects in a room and in the player’s inventory of items. The easiest approach is to use an ArrayList, which makes it easy to add and remove items.

Under the assumption that you have followed the suggested text file structure (You are allowed to use different structure as long as you are able to fulfill the requirements) your text file for this deliverable could look like the one in the figure below:

You will need to consider adding another text file that holds the items information The entries in the items text file can consist of three lines indicating the word used to refer to the item, the description of the item that appears when you encounter it, and the room number in which the item  is initially located. For example, this file indicates that the keys are in room 3, the lamp is room 8, and the rod is in room 12.

Puzzle feature:

Your goal is to allow the player to interact with one puzzle of your choice in any of the rooms. The interaction behavior with the puzzle should include the following commands:

  1. One the player enters a room with a puzzle, the game must display the puzzle description to the console/GUI and wait for the player to enter an answer.
  2. Each puzzle has number of attempts allowed
  3. If the player enters the correct answer, the game must display “you solved the puzzle correctly!” and the puzzle must disappear from the room. Note, the puzzle should disappear from the game and never show up again while navigating between rooms.
  4. If the player enters wrong answer, the game will subtract 1 attempt from the allowed attempt and allow the player to provide an answer again. The game must display “the answer you provided is wrong, you still have number-of-attempt. Try one more time”
  5. If the player is not able to solve the puzzle correctly after the given number of attempts, the game will display “failed to solve” message to the player and the puzzle must disappear from the game and never show up again while navigating between rooms.

Hit: in the text file, you can link the puzzle to the room similar to items. You need to consider adding puzzle text file to hold the following information puzzle name, description, answer, number of attempts etc.

Important notes:

  1. Please note that this is not a programming class where I am expected to trouble shoot your code. However, I found over the years of teaching this class that students need similar programming exercise to review their programming skills in preparation for the final project deliverable. To help you I will discuss possible solutions in the class and show you sample code and record some videos and you will put time and efforts to get your code up and running properly.
  2. Use either JAVA Eclipse or IntelliJ
  3. Grading code takes lots of time so keep your code clean, organized and understandable by adding comments. The more organized your code is the quicker I can grade and the faster you will get a feedback.
  4. Don’t fix the file path in your code
  5. If your code doesn’t run you will get ‘0’ for this assignment. If your code runs but have partial behaviuor you will get partial credits. e.g. your code runs and allows me to navigate between rooms but doesn’t keep track of visited rooms, then I will take points off for this missing requirements.

The third assignment will add more to the first and second assignment. Therefore, it is important to finish this assignment on time and as directed. Otherwise, you will fall behind quickly.

Solutions

Expert Solution

Working code implemented in Java and appropriate comments provided for better understanding.

Note: I am not able to share text files. That's why I am sharing all text files through a link.

Link: https://gofile.io/d/dm6Jhx

Mirror Link: https://anonymousfiles.io/L5cK8uEJ/

Here I am attaching code for these files:

  • Driver.java
  • Help.java
  • Item.java
  • Map.java
  • Navigation.java
  • Player.java
  • Puzzle.java
  • Room.java

Driver.java:

import java.util.*;
import java.io.*;

/**
*
* This class reads the file "RoomMap2.txt", "Items.txt", & "Puzzles.txt" & guides the player through a each room.
*
* Purpose: Methods and attributes needed to create a new player of
* Player class. Read the text file, adds the each object into the
* arraylist, & allows the player to choose which direction they want to go.
*
*/
public class Driver
{
   public static void main(String[] args)
   {
       //new Player object
       Player player = new Player();
       //open text file
       File roomFile = new File("RoomMap.txt");
       //open a Scanner to read data from File
       Scanner roomReader = null;
       try
       {
           roomReader = new Scanner(roomFile);
       }
       catch (FileNotFoundException e)
       {
           System.out.println("The RoomMap.txt file has not been found");
       }
       // read one value at a time
       while(roomReader != null && roomReader.hasNext())
       {
           //assign values to attributes
           String roomNum = roomReader.nextLine();
           String desc = roomReader.nextLine();
           String visitedString = roomReader.nextLine();
           boolean visited = Boolean.parseBoolean(visitedString);
           String itemString = roomReader.nextLine();
           boolean item = Boolean.parseBoolean(itemString);
           String puzzleString = roomReader.nextLine();
           boolean puzzle = Boolean.parseBoolean(puzzleString);
           String north = roomReader.nextLine();
           String east = roomReader.nextLine();
           String south = roomReader.nextLine();
           String west = roomReader.nextLine();
           //create a new object & add it to the arraylist
           Room room = new Room(roomNum, desc, visited, item, puzzle, north, east, south, west);
           Map.addRoom(room);
       }
       //open text file
       File itemFile = new File("Items.txt");
       //open a Scanner to read data from File
       Scanner itemReader = null;
       try
       {
           itemReader = new Scanner(itemFile);
       }
       catch (FileNotFoundException e)
       {
           System.out.println("The Items.txt file has not been found");
       }
       // read one value at a time
       while (itemReader != null && itemReader.hasNext())
       {
           // assign values to attributes
           String itemName = itemReader.nextLine();
           String itemDesc = itemReader.nextLine();
           String itemLocation = itemReader.nextLine();
           // create a new object & add it to the arraylist
           Item item = new Item(itemName, itemDesc, itemLocation);
           Item.addItem(item);
       }
       //open text file
       File puzzleFile = new File("Puzzles.txt");
       // open a Scanner to read data from File
       Scanner puzzleReader = null;
       try
       {
           puzzleReader = new Scanner(puzzleFile);
       }
       catch (FileNotFoundException e)
       {
           System.out.println("The Puzzles.txt file has not been found");
       }
       // read one value at a time
       while (puzzleReader != null && puzzleReader.hasNext())
       {
           // assign values to attributes
           String puzzleLocation = puzzleReader.nextLine();
           String question = puzzleReader.nextLine();
           String answer = puzzleReader.nextLine();
           String attempts = puzzleReader.nextLine();
           // create a new object & add it to the arraylist
           Puzzle puzzle = new Puzzle(puzzleLocation, question, answer, attempts);
           Puzzle.addPuzzle(puzzle);
       }
       // open text file
       File helpFile = new File("Help.txt");
       // open a Scanner to read data from File
       Scanner helpReader = null;
       try
       {
           helpReader = new Scanner(helpFile);
       }
       catch (FileNotFoundException e)
       {
           System.out.println("The Help.txt file has not been found");
       }
       // read one value at a time
       while (helpReader != null && helpReader.hasNext())
       {
           // assign values to attributes
           String command = helpReader.nextLine();
           // create a new object & add it to the arraylist
           Help help = new Help(command);
           Help.addCommands(help);
       }
       // open text file
       File navFile = new File("Navigation.txt");
       // open a Scanner to read data from File
       Scanner navReader = null;
       try
       {
           navReader = new Scanner(navFile);
       }
       catch (FileNotFoundException e)
       {
           System.out.println("The Navigation.txt file has not been found");
       }
       // read one value at a time
       while (navReader != null && navReader.hasNext())
       {
           // assign values to attributes
           String roomNav = navReader.nextLine();
           String beginningLine = navReader.nextLine();
           String nav = navReader.nextLine();
           String middleLine = navReader.nextLine();
           String header = navReader.nextLine();
           String north = navReader.nextLine();
           String east = navReader.nextLine();
           String south = navReader.nextLine();
           String west = navReader.nextLine();
           String endingLine = navReader.nextLine();
           // create a new object & add it to the arraylist
           Navigation navi = new Navigation(roomNav, beginningLine, nav, middleLine, header, north, east, south, west, endingLine);
           Navigation.addNavigation(navi);
       }
       Scanner keyboard = new Scanner(System.in);
       //starting point
       int roomId = 0;
       boolean done = false;
       player.help.askHelp();
       //repeats the program
       while(!done)
       {
           while (Map.getRoomItems().get(roomId).hasPuzzle())
           {
               for (int i = 0; i < Puzzle.getPuzzleItems().size(); i++)
               {
                   if (Map.getRoomItems().get(roomId).getRoomNum().equals(Puzzle.getPuzzleItems().get(i).getPuzzleLocation()))
                   {
                       System.out.println(Puzzle.getPuzzleItems().get(i).getQuestion());
                       String input = keyboard.next();
                       player.puzzle.solvePuzzle(input);
                   }
               }
           }
           //states which room the player is currently in based on the roomId
           System.out.println("You are currently in Room #" + Map.getRoomItems().get(roomId).getRoomNum());
           player.navigation.getNavigation(roomId);
           //asks which direction the player would like to go
           String input = keyboard.next();
           if (input.equalsIgnoreCase("c"))
           {
               player.help.askHelp();
           }
           else if (input.equalsIgnoreCase("examine"))
           {
               String input2 = keyboard.next();
               if (input2.equalsIgnoreCase("room"))
               {
                   player.map.examineRoom(input2);
               }
               else if (input2.equalsIgnoreCase("inventory"))
               {
                   player.examineInventory(input2);
               }
               else
               {
                   player.item.examineItem(input2);
               }
           }
           else if (input.equalsIgnoreCase("pickup"))
           {
               String input2 = keyboard.next();
               player.item.pickUp(input2);
           }
           else if(input.equalsIgnoreCase("drop"))
           {
               String input2 = keyboard.next();
               player.item.drop(input2);
           }
           else if (input.equalsIgnoreCase("n"))
           {
               String direction = Map.getRoomItems().get(roomId).getNorth();
               //checks to see if the player can go north
               player.map.getRoom(direction);
           }
           else if (input.equalsIgnoreCase("e"))
           {
               String direction = Map.getRoomItems().get(roomId).getEast();
               //checks to see if the player can go east
               player.map.getRoom(direction);
           }
           else if (input.equalsIgnoreCase("s"))
           {
               String direction = Map.getRoomItems().get(roomId).getSouth();
               //checks to see if the player can go south
               player.map.getRoom(direction);
           }
           else if (input.equalsIgnoreCase("w"))
           {
               String direction = Map.getRoomItems().get(roomId).getWest();
               //checks to see if the player can go west
               player.map.getRoom(direction);
           }
           else if (input.equalsIgnoreCase("quit"))
           {
               System.out.println("You have successfully quit the game.");
               done = true;
           }
           else
           {
               System.out.println("Invalid input. Please try again.");
           }
           //this room has officially been visited
           Map.getRoomItems().get(roomId).setVisited(true);
           //assigns a new roomId based on the new location of the player
           roomId = Player.getPlayerLocation();
       }
       keyboard.close();
   }
}


Help.java:

import java.util.ArrayList;

/**
* Class: Help
*
* @author Taylor Williams
* @version 2.0
* Course: ITEC 3860 Spring 2020
* Written: Maqrch 14, 2020
*
* This class describes the commands & helpful tips the player might need
*/
public class Help
{
   private String help;
   private static ArrayList<Help> commands = new ArrayList<Help>();
  
   /**
   *
   */
   public Help()
   {
       super();
       // TODO Auto-generated constructor stub
   }
  
   /**
   * @param help
   */
   public Help(String help)
   {
       super();
       this.help = help;
   }

   /**
   * @return the help
   */
   public String getHelp()
   {
       return help;
   }

   /**
   * @param help the help to set
   */
   public void setHelp(String help)
   {
       this.help = help;
   }
  
   //adds Help objects into the arraylist
   public static void addCommands(Help h)
   {
       commands.add(h);
   }
  
   public static ArrayList<Help> getCommands()
   {
       return commands;
   }
  
   public void askHelp()
   {
       for (int i = 0; i < getCommands().size(); i++)
       {
           System.out.println(getCommands().get(i).getHelp());
       }
       System.out.println("Type \"C\" at anytime to see your commands.");
   }
}

Item.java:

import java.util.ArrayList;

/**
* Class: Item
*
* This class describes the common attributes and
* methods of the Items being collected into an inventory
*/
public class Item
{
   private String itemName;
   private String itemDesc;
   private String itemLocation;
   private static ArrayList<Item> itemItems = new ArrayList<Item>();
   //counts items
   private int count;
  
   /**
   *
   */
   public Item()
   {
       super();
       // TODO Auto-generated constructor stub
   }
  
   /**
   * @param itemName
   * @param itemDesc
   * @param itemLocation
   */
   public Item(String itemName, String itemDesc, String itemLocation)
   {
       super();
       this.itemName = itemName;
       this.itemDesc = itemDesc;
       this.itemLocation = itemLocation;
   }

   /**
   * @return the itemName
   */
   public String getItemName()
   {
       return itemName;
   }
  
   /**
   * @param itemName the itemName to set
   */
   public void setItemName(String itemName)
   {
       this.itemName = itemName;
   }
  
   /**
   * @return the itemDesc
   */
   public String getItemDesc()
   {
       return itemDesc;
   }
  
   /**
   * @param itemDesc the itemDesc to set
   */
   public void setItemDesc(String itemDesc)
   {
       this.itemDesc = itemDesc;
   }

   /**
   * @return the itemLocation
   */
   public String getItemLocation()
   {
       return itemLocation;
   }

   /**
   * @param itemLocation the itemLocation to set
   */
   public void setItemLocation(String itemLocation)
   {
       this.itemLocation = itemLocation;
   }
  
   //adds Item objects into the arraylist
   public static void addItem(Item i)
   {
       itemItems.add(i);
   }
  
   //removes Item objects from the arraylist
   public static void removeItem(Item i)
   {
       itemItems.remove(i);
   }
  
   //returns Item objects
   public static ArrayList<Item> getItemItems()
{
return itemItems;
}
  
   //examines items
   public void examineItem(String item)
   {
       for (int i = 0; i < getItemItems().size(); i++)
       {
           if (item.equalsIgnoreCase(getItemItems().get(i).getItemName()))
           {
               System.out.println(getItemItems().get(i).getItemDesc());
           }
       }
       for (int i = 0; i < Player.getInventory().size(); i++)
       {
           if (item.equalsIgnoreCase(Player.getInventory().get(i).getItemName()))
           {
               System.out.println(Player.getInventory().get(i).getItemDesc());
           }
       }
   }
  
   //removes Item objects from the itemItems arraylist and adds them into the Inventory arraylist
   public void pickUp(String item)
   {
       count = 0;
       for (int i = 0; i < getItemItems().size(); i++)
       {
           if (item.equalsIgnoreCase(getItemItems().get(i).getItemName()))
           {
               Player.getInventory().add(getItemItems().get(i));
               removeItem(getItemItems().get(i));
               for (i = 0; i < Player.getInventory().size(); i++)
               {
                   if (item.equalsIgnoreCase(Player.getInventory().get(i).getItemName()))
                   {  
                       System.out.println(Player.getInventory().get(i).getItemName() + " has been picked up from the room and successfully added to the player inventory.");
                   }
               }
               for (i = 0; i < getItemItems().size(); i++)
               {
                  
                   if (Map.getRoomItems().get(Player.getPlayerLocation()).hasItem())
                   {
                       if (Map.getRoomItems().get(Player.getPlayerLocation()).getRoomNum().equals(getItemItems().get(i).getItemLocation()))
                       {
                           count++;
                       }
                       if (count == 0)
                       {
                           Map.getRoomItems().get(Player.getPlayerLocation()).setItem(false);
                       }
                   }
               }
               if(getItemItems().size() == 0)
               {
                   Map.getRoomItems().get(Player.getPlayerLocation()).setItem(false);
               }
           }
       }
   }
  
   //removes Item objects from the arraylist
   public void drop(String item)
   {
       count = 0;
       for (int i = 0; i < Player.getInventory().size(); i++)
       {
           if (item.equalsIgnoreCase(Player.getInventory().get(i).getItemName()))
           {
               addItem(Player.getInventory().get(i));
               Player.getInventory().get(i).setItemLocation(Map.getRoomItems().get(Player.getPlayerLocation()).getRoomNum());
               Player.getInventory().remove(i);
               for (i = 0; i < getItemItems().size(); i++)
               {
                   if (item.equalsIgnoreCase(getItemItems().get(i).getItemName()))
                   {
                       System.out.println(getItemItems().get(i).getItemName() + " has been dropped successfully from the player inventory and placed in the " + Map.getRoomItems().get(Player.getPlayerLocation()).getDesc());
                   }
                   if (Map.getRoomItems().get(Player.getPlayerLocation()).hasItem() == false)
                   {
                       if (Map.getRoomItems().get(Player.getPlayerLocation()).getRoomNum().equals(getItemItems().get(i).getItemLocation()))
                       {
                           count++;
                       }
                       if (count > 0)
                       {
                           Map.getRoomItems().get(Player.getPlayerLocation()).setItem(true);
                       }
                   }
               }
           }
       }
   }
}

Map.java:

import java.util.*;

/**
*
* Purpose: Methods and attributes needed to create a Map of Room class items.
*
*/
public class Map
{
   //actual Map data
   private static ArrayList<Room> roomItems = new ArrayList<Room>();
  
   //adds Room objects into the arraylist
   public static void addRoom(Room r)
{
       roomItems.add(r);
}
  
   //returns Room objects
   public static ArrayList<Room> getRoomItems()
{
return roomItems;
}
  
   //gets the information of the specific room
   public void getRoom(String direction)
   {
       if (direction.equals("0"))
       {
           //invalid direction
           System.out.println("Sorry! You cannot go in this direction! Try typing in a different direction.");
       }
       else if (direction != "0")
       {
           //-1 because the arraylist starts at index 0
           int location = Integer.parseInt(direction)-1;
           if(roomItems.get(location).isVisited())
           {
               //previously visited room
               System.out.println("This room looks familliar...");
           }
           if(direction.equals(roomItems.get(location).getRoomNum()))
           {
               //updates player location
               Player.setPlayerLocation(location);
           }
       }
   }
  
   //lists what is in the room
   public void examineRoom(String item)
   {
       if (item.equalsIgnoreCase("room"))
       {
           System.out.println("You are in the: " + Map.getRoomItems().get(Player.getPlayerLocation()).getDesc());
           if (Map.getRoomItems().get(Player.getPlayerLocation()).hasItem())
           {
               System.out.println("The item(s) in this room: ");
               System.out.print("[");
               for (int i = 0; i < Item.getItemItems().size(); i++)
               {
                  
                   if (Map.getRoomItems().get(Player.getPlayerLocation()).getRoomNum().equals(Item.getItemItems().get(i).getItemLocation()))
                   {
                      
                       System.out.print(" \"" + Item.getItemItems().get(i).getItemName() + "\"");
                   }
               }
               System.out.println(" ]");
           }
           else
           {
               System.out.println("This room is empty.");
           }
       }
   }
}

Navigation.java:

import java.util.ArrayList;

/**
* Class: Navigation
*
* This class describes the navigation pane that shows
* where the player can go based on their location
*/
public class Navigation
{
   private String roomNav;
   private String beginningLine;
   private String nav;
   private String middleLine;
   private String header;
   private String north;
   private String east;
   private String south;
   private String west;
   private String endingLine;
   private static ArrayList<Navigation> directions = new ArrayList<Navigation>();
  
   /**
   *
   */
   public Navigation()
   {
       super();
       // TODO Auto-generated constructor stub
   }

   /**
   * @param roomNav
   * @param beginningLine
   * @param nav
   * @param middleLine
   * @param header
   * @param north
   * @param east
   * @param south
   * @param west
   * @param endingLine
   */
   public Navigation(String roomNav, String beginningLine, String nav, String middleLine, String header, String north,
           String east, String south, String west, String endingLine)
   {
       super();
       this.roomNav = roomNav;
       this.beginningLine = beginningLine;
       this.nav = nav;
       this.middleLine = middleLine;
       this.header = header;
       this.north = north;
       this.east = east;
       this.south = south;
       this.west = west;
       this.endingLine = endingLine;
   }

   /**
   * @return the roomNav
   */
   public String getRoomNav()
   {
       return roomNav;
   }

   /**
   * @param roomNav the roomNav to set
   */
   public void setRoomNav(String roomNav)
   {
       this.roomNav = roomNav;
   }

   /**
   * @return the beginningLine
   */
   public String getBeginningLine()
   {
       return beginningLine;
   }

   /**
   * @param beginningLine the beginningLine to set
   */
   public void setBeginningLine(String beginningLine)
   {
       this.beginningLine = beginningLine;
   }

   /**
   * @return the nav
   */
   public String getNav()
   {
       return nav;
   }

   /**
   * @param nav the nav to set
   */
   public void setNav(String nav)
   {
       this.nav = nav;
   }

   /**
   * @return the middleLine
   */
   public String getMiddleLine()
   {
       return middleLine;
   }

   /**
   * @param middleLine the middleLine to set
   */
   public void setMiddleLine(String middleLine)
   {
       this.middleLine = middleLine;
   }

   /**
   * @return the header
   */
   public String getHeader()
   {
       return header;
   }

   /**
   * @param header the header to set
   */
   public void setHeader(String header)
   {
       this.header = header;
   }

   /**
   * @return the north
   */
   public String getNorth()
   {
       return north;
   }

   /**
   * @param north the north to set
   */
   public void setNorth(String north)
   {
       this.north = north;
   }

   /**
   * @return the east
   */
   public String getEast()
   {
       return east;
   }

   /**
   * @param east the east to set
   */
   public void setEast(String east)
   {
       this.east = east;
   }

   /**
   * @return the south
   */
   public String getSouth()
   {
       return south;
   }

   /**
   * @param south the south to set
   */
   public void setSouth(String south)
   {
       this.south = south;
   }

   /**
   * @return the west
   */
   public String getWest()
   {
       return west;
   }

   /**
   * @param west the west to set
   */
   public void setWest(String west)
   {
       this.west = west;
   }

   /**
   * @return the endingLine
   */
   public String getEndingLine()
   {
       return endingLine;
   }

   /**
   * @param endingLine the endingLine to set
   */
   public void setEndingLine(String endingLine)
   {
       this.endingLine = endingLine;
   }  
  
   //adds Navigation objects into the arraylist
   public static void addNavigation(Navigation n)
   {
       directions.add(n);
   }
  
   public static ArrayList<Navigation> getDirections()
   {
       return directions;
   }
  
   public void getNavigation(int roomId)
   {
       System.out.println(getDirections().get(roomId).getBeginningLine());
       System.out.println(getDirections().get(roomId).getNav());
       System.out.println(getDirections().get(roomId).getMiddleLine());
       System.out.println(getDirections().get(roomId).getHeader());
       System.out.println(getDirections().get(roomId).getNorth());
       System.out.println(getDirections().get(roomId).getEast());
       System.out.println(getDirections().get(roomId).getSouth());
       System.out.println(getDirections().get(roomId).getWest());
       System.out.println(getDirections().get(roomId).getEndingLine());
   }
}

Player.java:

import java.util.ArrayList;

/**
* Class: Player
*
* This class gives the player access to the map, items, an item inventory. The player also sets/gets their current location,
* gets info from the inventory, picks up/drops/examines items, & solves puzzles
*/
public class Player
{
   private static int roomId;
   //inventory of items
   private static ArrayList<Item> inventory = new ArrayList<Item>();
   //has access to the Item class
   Item item = new Item();
   //has access to the Help class
   Help help = new Help();
   //has access to the Navigation class
   Navigation navigation = new Navigation();
   //has access to the Map class
   Map map = new Map();
   //has access to the Puzzle class
   Puzzle puzzle = new Puzzle();
  
   //places the player inside the specific room
   public static void setPlayerLocation(int x)
   {
       roomId = x;
   }
  
   //locates the player
   public static int getPlayerLocation()
   {
       return roomId;
   }
  
   //gets items in inventory
   public static ArrayList<Item> getInventory()
{
return inventory;
}
  
   //lists the items int the inventory (if there are any)
   public void examineInventory(String item)
   {
       if (item.equalsIgnoreCase("inventory"))
       {
           if (getInventory().size() == 0)
           {
               System.out.println("Your inventory is empty.");
           }
           else
           {  
               System.out.println("The item(s) in your inventory: ");
               System.out.print("[");
               for (int i = 0; i < getInventory().size(); i++)
               {
                   System.out.print(" \"" + getInventory().get(i).getItemName() + "\"");
               }
               System.out.println(" ]");
           }
       }
   }
}

Puzzle.java:

import java.util.ArrayList;

/**
* Class: Puzzle
*
* This class describes the common attributes and
* methods of the Puzzles being collected into an inventory
*/
public class Puzzle
{
   private String puzzleLocation;
   private String question;
   private String answer;
   private String attempts;
   private static ArrayList<Puzzle> puzzleItems = new ArrayList<Puzzle>();
  
   /**
   *
   */
   public Puzzle()
   {
       super();
       // TODO Auto-generated constructor stub
   }

   /**
   * @param puzzleLocation
   * @param question
   * @param answer
   * @param attempts
   */
   public Puzzle(String puzzleLocation, String question, String answer, String attempts)
   {
       super();
       this.puzzleLocation = puzzleLocation;
       this.question = question;
       this.answer = answer;
       this.attempts = attempts;
   }

   /**
   * @return the puzzleLocation
   */
   public String getPuzzleLocation()
   {
       return puzzleLocation;
   }

   /**
   * @param puzzleLocation the puzzleLocation to set
   */
   public void setPuzzleLocation(String puzzleLocation)
   {
       this.puzzleLocation = puzzleLocation;
   }

   /**
   * @return the question
   */
   public String getQuestion()
   {
       return question;
   }

   /**
   * @param question the question to set
   */
   public void setQuestion(String question)
   {
       this.question = question;
   }

   /**
   * @return the answer
   */
   public String getAnswer()
   {
       return answer;
   }

   /**
   * @param answer the answer to set
   */
   public void setAnswer(String answer)
   {
       this.answer = answer;
   }

   /**
   * @return the attempts
   */
   public String getAttempts()
   {
       return attempts;
   }

   /**
   * @param attempts the attempts to set
   */
   public void setAttempts(String attempts)
   {
       this.attempts = attempts;
   }
  
   public static ArrayList<Puzzle> getPuzzleItems()
{
return puzzleItems;
}
  
   //adds Puzzle objects into the arraylist
   public static void addPuzzle(Puzzle p)
   {
       puzzleItems.add(p);
   }
  
   //removes Puzzle objects from the arraylist
   public static void removePuzzle(Puzzle p)
   {
       puzzleItems.remove(p);
   }
  
   public void solvePuzzle(String answer)
   {
       for (int i = 0; i < getPuzzleItems().size(); i++)
       {
           int attempts = Integer.parseInt(getPuzzleItems().get(i).getAttempts());
           if (answer.equalsIgnoreCase(getPuzzleItems().get(i).getAnswer()))
           {
               System.out.println("You solved the puzzle correctly!");
               removePuzzle(getPuzzleItems().get(i));
               Map.getRoomItems().get(Player.getPlayerLocation()).setPuzzle(false);
           }
           else
           {
               attempts--;
               String attempted = Integer.toString(attempts);
               getPuzzleItems().get(i).setAttempts(attempted);
               if (attempts > 0)
               {
                   System.out.println("The answer you provided is wrong, you still have " + attempts
                           + " more attempt(s). Try one more time");
               }
               else
               {
                   System.out.println("Failed to solve");
                   removePuzzle(getPuzzleItems().get(i));
                  
                   Map.getRoomItems().get(Player.getPlayerLocation()).setPuzzle(false);
               }
           }
       }
   }
}

Room.java:

/**
* Class: Room
*
* This class describes the common attributes and
* methods of the Room being collected into an inventory
*/
public class Room
{
   private String roomNum;
   private String desc;  
   private boolean visited;
   private boolean item;
   private boolean puzzle;
   private String north;
   private String east;
   private String south;
   private String west;
  
   /**
   *
   */
   public Room()
   {
       super();
   }
  
   /**
   * @param roomNum
   * @param desc
   * @param visited
   * @param north
   * @param east
   * @param south
   * @param west
   */
   public Room(String roomNum, String desc, boolean visited, boolean item, boolean puzzle, String north, String east, String south,
           String west)
   {
       super();
       this.roomNum = roomNum;
       this.desc = desc;
       this.visited = false;
       this.item = item;
       this.puzzle = puzzle;
       this.north = north;
       this.east = east;
       this.south = south;
       this.west = west;
   }

   /**
   * @return the roomNum
   */
   public String getRoomNum()
   {
       return roomNum;
   }

   /**
   * @param roomNum the roomNum to set
   */
   public void setRoomNum(String roomNum)
   {
       this.roomNum = roomNum;
   }

   /**
   * @return the desc
   */
   public String getDesc()
   {
       return desc;
   }

   /**
   * @param desc the desc to set
   */
   public void setDesc(String desc)
   {
       this.desc = desc;
   }

   /**
   * @return the visited
   */
   public boolean isVisited()
   {
       return visited;
   }

   /**
   * @param visited the visited to set
   */
   public void setVisited(boolean visited)
   {
       this.visited = visited;
   }

   /**
   * @return the item
   */
   public boolean hasItem()
   {
       return item;
   }

   /**
   * @param item the item to set
   */
   public void setItem(boolean item)
   {
       this.item = item;
   }
  
   /**
   * @return the puzzle
   */
   public boolean hasPuzzle()
   {
       return puzzle;
   }

   /**
   * @param puzzle the puzzle to set
   */
   public void setPuzzle(boolean puzzle)
   {
       this.puzzle = puzzle;
   }
  
   /**
   * @return the north
   */
   public String getNorth()
   {
       return north;
   }

   /**
   * @param north the north to set
   */
   public void setNorth(String north)
   {
       this.north = north;
   }

   /**
   * @return the east
   */
   public String getEast()
   {
       return east;
   }

   /**
   * @param east the east to set
   */
   public void setEast(String east)
   {
       this.east = east;
   }

   /**
   * @return the south
   */
   public String getSouth()
   {
       return south;
   }

   /**
   * @param south the south to set
   */
   public void setSouth(String south)
   {
       this.south = south;
   }

   /**
   * @return the west
   */
   public String getWest()
   {
       return west;
   }

   /**
   * @param west the west to set
   */
   public void setWest(String west)
   {
       this.west = west;
   }
}

Sample Output Screenshots:

Related Solutions

In Python This assignment involves the use of text files, lists, and exception handling and is...
In Python This assignment involves the use of text files, lists, and exception handling and is a continuation of the baby file assignment. You should now have two files … one called boynames2014.txt and one called girlnames2014.txt - each containing the top 100 names for each gender from 2014. Write a program which allows the user to search your files for a boy or girl name and display where that name ranked in 2014. For example … >>>   Enter gender...
This assignment involves the use of text files, lists, and exception handling and is a continuation...
This assignment involves the use of text files, lists, and exception handling and is a continuation of the baby file assignment. You should now have two files … one called boynames2014.txt and one called girlnames2014.txt - each containing the top 100 names for each gender from 2014. Write a program which allows the user to search your files for a boy or girl name and display where that name ranked in 2014. For example … >>> Enter gender (boy/girl): boy...
fix all errors in code below: PLEASE DO ASAP, THIS IS IN MATLAB %Welcome Message fprintf('****Welcome...
fix all errors in code below: PLEASE DO ASAP, THIS IS IN MATLAB %Welcome Message fprintf('****Welcome to Comida Mexicana De Mentiras****\n'); flag =0; while flag ==1 % Asking the user for the order choice = input('Please enter your order \n 1. Burrito Bowl \n 2.Burrito \n 3. Tacos \n Enter 1 or 2 or 3: ','s'); switch choice case choice==1 % For Burrito Bowl BaseCost = 4; [Protein, PC] = proteinChoice(); [FinalAmount,~]= AmountCalculator(BaseCost,PC); displayMessage("Burrito Bowl",Protein,FinalAmount); case choice==2 end end %...
Please Answer all question and please in detail. The assignment should include an abstract, introduction, conceptual...
Please Answer all question and please in detail. The assignment should include an abstract, introduction, conceptual building of sustainable financial management and sustainable financial growth, results and discussions sections, the project should also include conclusion section. 1. Examining the existing various corporate sustainable reporting disclosure and how they contributes to shared value creation and firms value. 2. Improving financial decision making by linking sustainability issues to financial decisions and key value drivers, such as capital budgeting, the cost of capital,...
Please write code in C++ and include all header files used not bits/stdc: (Same number subsequence)...
Please write code in C++ and include all header files used not bits/stdc: (Same number subsequence) Write an O(n) program that prompts the user to enter a sequence of integers ending with 0 and finds longest subsequence with the same number. Sample Run Enter a series of numbers ending with 0: 2 4 4 8 8 8 8 2 4 4 0 The longest same number sequence starts at index 3 with 4 values of 8
Instructions: You are not required to use R markdown for the lab assignment. Please include ALL...
Instructions: You are not required to use R markdown for the lab assignment. Please include ALL R commands you used to reach your answers in a word or pdf document. Also, report everything you are asked to do so. Problem 3 : In lab lecture notes and demo code, I simulated random samples from Exp(1) to verify classical central limit theorem numerically. I also stressed that no matter what type of random samples you use, the standardized partial sum Sn...
Instructions: You are not required to use R markdown for the lab assignment. Please include ALL...
Instructions: You are not required to use R markdown for the lab assignment. Please include ALL R commands you used to reach your answers in a word or pdf document. Also, report everything you are asked to do so. Problem 1 : Consider a binomial random variable X ∼ Bin(100, 0.01). 1. Report P(X = 7), P(X = 8), P(X = 9), try to use one ONE R command to return all these three values. 2. Find the probability P(0...
Can you please write a pseudocode for the following: #include <stdio.h> int main(){    printf("Welcome to...
Can you please write a pseudocode for the following: #include <stdio.h> int main(){    printf("Welcome to my Command-Line Calculator (CLC)\n");    printf("Developer: Your name will come here\n");    printf("Version: 1\n");    printf("Date: Development data Will come here\n");    printf("----------------------------------------------------------\n\n");    //choice stores users input    char choice;    //to store numbers    int val1,val2;    //to store operator    char operation;    //flag which leths the loop iterate    //the loop will break once the flag is set to 0...
Accounting II AC2034 ASSIGNMENT 2 PAYROLL Please Note: This assignment is an INDIVIDUAL assignment The payroll...
Accounting II AC2034 ASSIGNMENT 2 PAYROLL Please Note: This assignment is an INDIVIDUAL assignment The payroll records of Acme Company provided the following information for the weekly pay period ended March 20, 2020: Employee     Employee     Hours Worked         Rate of Pay Hospital        Union             Earnings to End    Name                No            For Week                                          Insurance     Dues             of Previous Week Bugs Bunny       40                    40                            $34                   $30.00        $12.00           $43,000 Sylvester            50                    42                              36            ...
Please convert this files and includes full process of each converting Binary to decimal: Please include...
Please convert this files and includes full process of each converting Binary to decimal: Please include STEP by STEP: Decimal to binary 33 254 300 512 513
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT