[Solved] SOLVED:Project 5 part A and B solution

30 $

File Name: SOLVED:Project_5_part_A_and_B_solution.zip
File Size: 357.96 KB

SKU: [Solved] SOLVED:Project 5 part A and B solution Category: Tag:

Or Upload Your Assignment Here:


(Part A)Game Design

OverviewProject 5 is divided into two parts. The first part (Part A) requires you to design an original adventure game. There is no coding required. You will turn in a few pages describing the various components of your game. Part B will be assigned later with detailed instructions of how to write the application. Part A is worth 10% of the project 5 grade.Adventure GamesYou will design and later implement a text-based adventure game. These games allow a single player to move through a virtual world collecting items and performing actions that lead to the possibility of winning.For example:• An astronaut moving from one planet to another.• A Walmart customer locked in a store.• A GVSU student moving through campus.• Adapted scenario from a book, movie or video game.Sample Introduction• You are at Grand Valley State University. You have to find out where your lab class is.To find this, you have to find the Student Services Building and pickup a class schedule.You then need to find the exam room. If you get there and you have found your textbook somewhere along the way, then you win.• You are lost in a dungeon. You meet a dwarf. If you find something to eat that you can give to the dwarf, then the dwarf tells you where to find a magic wand. If you use the magic wand in Mystic Cavern, the exit opens, and you get out to win.Minimum Game Requirements• At least eight rooms/locations• At least four items• At least one item too heavy to carry, 20 units or more• At least one edible item• Condition(s) that end with the player winning (required) or losing (optional)

Game DescriptionProvide the following information for your game using the provided headings in your typed document.Game SummaryProvide a brief summary of the background and goal of the game. This will serve as the introductory message of the game. An “interesting” game will have multiple locations with a variety of connections between them. Create a maze-like environment that will be challenging for the player to navigate.Room DescriptionsDescribe at least eight rooms/locations with the following information: a description, an optional item, an optional character and zero or more neighbors. Rooms can have an unlimited number of neighbors in unique directions. For example, a room could have neighbors to the “east”, “upstairs”, “outside”, “southwest” or any other direction. Write the description to be preceded by “You are” kitchenDescription: “in a kitchen with peanut butter smeared all over the counters”Item: “jar of peanut butter”Neighbor(s) “east” to Dining Room “outside” to YardItem DescriptionsDescribe at least four items including: a name (one word), a description, a weight and whether or not the item is edible. Write descriptions to be preceded by “You see” JarName: “jar”Description: “a jar of peanut butter”Weight: 4Edible: true

Basic ActionsThe basic game has the following commands. You must create two additional commends that make sense for your game• Help – displays hints and descriptions about the game• Pickup – player attempts to take the item in the room assuming the item is not too heavy.• Eat item – player attempts to eat an edible item that is currently held. Player will no longer be holding the item after eating it.• Leave item – leave the requested item in the current room. Player will no longer be holding the item but must be holding it to start.• Show – display description of the current room• Backup – return to the previous room• Inventory – display list of all items currently held by the player• Move direction – attempt to move from the current room in the requested direction.There may, or may not, be a room in the requested direction.Additional Actions – describe two additional commands (of your own design) beyond the basic actions. Perhaps you can throw something? Shrink something? Make invisible? Wave a magicwand? Say a magic word? Jump over something? Swim? Fly? Use your imagination!“Game Over” ConditionsDescribe the condition(s) where the player either wins (required) or losses (optional). For example the player has to be in a certain room holding certain item(s). Your conditions can be more complex.Game MapShow a map of the rooms and arrows indicating if they are accessible from each other. Label the arrows with the direction. Your map can be hand drawn if necessary but an electronic version will be more professional. An “interesting” game will have multiple locations with a variety of connections between them. Create a maze-like environment that will be challenging for the player to navigate.Turn InA professional document is typed and stapled with an attractive cover page that includes your name, a game title and an interesting graphic or photograph related to the game. Provide the subheadings and format described above for each category.East Kitchen DiningRoom

Step 1: Create a New BlueJ ProjectStep 2: Create a class called Item (5 pts)Implement a class to maintain information about an item including: a one-word name (String), alonger description of the item (String), a weight (int) and whether it is edible (Boolean).• provide appropriate names and data types for each of the instance variables.• public Item (String n, String d, int w, boolean e) – initializeinstance variables.• provide get and set methods for each instance variable.• public boolean isEdible () – return true if the item is edible.• Test this class thoroughly using a main method before moving on.Step 3: Create a class called Room (15 pts)Implement a class to maintain information about a room including: a description of the room(String), an Item, and a list of all adjacent Rooms (HashMap). Rooms can have an unlimitednumber of neighbors in unique directions. For example, a room could have neighbors to the“north”, “upstairs”, “outside”, “southwest” or any other direction. Allowing an unknownnumber of neighbors requires a dynamic data structure. You will use a HashMap that isdescribed later in this document.• provide appropriate names and data types for each of the instance variables.• public Room (String d, Item i) – a constructor that is passed the descriptionand an optional item.• provide get methods for the description, and item• public void addItem (Item i) – add an item to the room. If an item isalready in the room it gets replaced.• public boolean hasItem () – return true if the room has an item.CIS162Project5–Summer2015Page2of8• public void addNeighbor (String dir, Room r) – add the providedroom and corresponding direction to the HashMap of neighbors (see below).• public Room getNeighbor (String dir) – return the adjacent room in therequested direction. Return null if there is no neighbor in that direction.• public Item removeItem () – remove and return the item. To remove the item,set the instance variable to null. Warning: this can be a bit tricky!• public String getLongDescription () – return a String that begins with“You are” followed by the room description. If there is an item in the room, include“You see” followed by the item description.• Test this class thoroughly using a main method before moving on.Step 4: Create a class called Game (40 pts)This class is the most complex you have written so far! It is responsible for keeping track of theitems being held by the player and the current location. The game maintains a current messagethat GUI is responsible for displaying. There are no println statements anywhere in thisclass except maybe the main method used for testing.• Define an instance variable that holds an ArrayList of Items for what the playerpicks up along the way. Define instance variables for each Room and Item specified inthe game design. You will need an additional Room instance variable for the player’scurrent location and a String to maintain the current message.• public Game () – instantiate the ArrayList of Items. Create all of the rooms byinvoking the helper method defined next. Set the current location to the starting locationof the game and the message to the introduction message.• private void createRooms () – this helper method instantiates the items androoms. Identify all of the room neighbors. See the section below for more informationabout creating rooms.• private void setIntroMessage () – this helper method initializes the game’smessage with an introduction to the game. DO NOT print the message.• public String getMessage () – return the game’s message for another objectto display (e.g. the GUI). DO NOT print the message. This is one line of code.• public void help () – update the game’s message with hints, suggestions andreminders about the game objective. DO NOT print the message.• public void show () – update the game’s message with the current room’s longdescription. DO NOT print the message.• public void move (String direction) – update the current location withthe neighbor in the requested location. If not possible, the message should explain theplayer can not move in that direction. See the sample code below for moving from oneroom to another.• public void inventory () – update the game’s message with a list of all itemsthe player is holding. If holding nothing, the message should explain.• public void eat (String item) – update the game’s message with one of thefollowing options: 1) “you are not holding an item” , 2) “item is not edible”, or 3) “Yum,CIS162Project5–Summer2015Page3of8that was a tasty item!”• public boolean gameOver () – determine if the game has been won or lost. Ifeither, update the game’s message with the news and return true. Otherwise, returnfalse with no change to the message. This method is invoked in the GUI class todetermine when the game is over.• public void pickup () – if appropriate, remove the item from the current roomand add it to the player’s inventory. Update the game message with one of the followingoptions: 1) there is no item in the room to take, 2) the item is too heavy to take, or 3) youare now holding the item.• private Item searchInventory (String name) – this helper methodchecks if the player is holding the requested item name. If found, return the Item. Ifnot, return null.• public void leave (String item) – if appropriate, remove the item from theinventory and add it to the current room. Update the game’s message with one of thefollowing options: 1) you are not holding that item, 2) the room already has an item andcan not be replaced, or 3) you have successfully dropped the item in the room.• public void backup () – if possible, return to the previous room. Update thegame message with one of the following options: 1) long description of the new currentroom, or 2) an explanation that the player cannot retreat from here. The player can onlyretreat one step before moving forward again. This is accomplished with an additionalinstance variable of type Room that maintains the previous location or null asappropriate. There is no retreat from the starting location.• public static void main (String args[]) – provide a main method thatinstantiates a Game object and tests all methods. Include a series of method calls thatallows the player to win the game. See the next section of Software Testing for moreinformation.Step 5: Software Testing (5 pts)Software developers must plan from the beginning that their solution is correct. BlueJ allowsyou to instantiate objects and invoke individual methods. You can carefully check each methodand compare actual results with expected results. However, this gets tedious. Another approachis to write a main method that calls all the other methods. See Listings 4.1 and 4.3.Main MethodWrite a main method in the Game class to automatically play a game until the player wins andalso demonstrates all game methods work. Here is a minimal example that does not test allmethods as required.public static void main (String args[]){Game g = new Game();System.out.println(g.getMessage());g.pickup();System.out.println(g.getMessage());g.move(“south”);System.out.println(g.getMessage());CIS162Project5–Summer2015Page4of8g.leave(“book”);System.out.println(g.getMessage());g.move(“north”);System.out.println(g.getMessage());g.move(“south”);System.out.println(g.getMessage());g.pickup();System.out.println(g.getMessage());if(g.gameOver()){System.out.println(g.getMessage());}Sample OutputYour game will look different but the following example provides a flavor of what the messagesshould look like. Provide a blank line between each message for readability.Welcome to GVSU! Home of the Lakers. “In Search of Louie” is a new andincredibly boring adventure game.You are outside the main entrance of the universityYou see a red Nike shoeYou are holding a red Nike shoeYou are in a computing labThere is nothing to take.You are in the computing admin officeYou see a dusty old bookYou are holding a dusty old bookYou are holding:a red Nike shoea dusty old bookYou are in the magic treasure roomYou see a very large treasure chestThe treasure is too heavy to pick up!CIS162Project5–Summer2015Page5of8Step 6: Create a GUI class (15 pts)Now that you have the Game working it is time to create a more interesting graphical userinterface for someone to use.• Use the GUI class from project 4 to get started.• Define an instance variable of type Game and instantiate it in the constructor• Define JButtons for each valid direction in your game (i.e. North, Upstairs, Inside)• Define JButtons for each action• Define a JTextArea to display the messages called resultsGUI Constructor• Instantiate each JButton in the constructor• Create a JPanel to hold all of the action buttons and place it in the SOUTH region ofthe JFrame.• Create a JPanel to hold all of the direction buttons and place it in the EAST region ofthe JFrame. Use a BoxLayout for the panel to allow the buttons to stack vertically (seeSection 7.11).JPanel directionPanel = new JPanel();directionPanel.setLayout(new BoxLayout(directionPanel,BoxLayout.Y_AXIS));directionPanel.add(new JLabel(“Directions”));directionPanel.add(eastButton);• Register the buttons with the ActionListener• Instantiate the JTextArea. The following statements allow the results text area toscroll and display the text more attractively. Place the results text area in the CENTERregion of the JFrame.results = new JTextArea(30,60);JScrollPane scrollPane = new JScrollPane(results);// allow word wrapresults.setLineWrap(true);results.setWrapStyleWord(true);// allows auto scrolling within the JTextAreaDefaultCaret caret = (DefaultCaret) results.getCaret();caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);actionPerformed• public void actionPerformed(ActionEvent e) – add if statements foreach of the button clicks and invoke the appropriate game method. For example:if (buttonPressed == help){myGame.help();}• For the eat action, prompt the player using a JOptionPane and then use the returnedString. For example:CIS162Project5–Summer2015Page6of8if (buttonPressed == eat){String message = “What do you want to eat?”;String toEat = JOptionPane.showInputDialog(null, message);myGame.eat(toEat);}• At the end of the method, display each game message in the results JTextArea.results.append(myGame.getMessage());• Add an if statement for the quitItem JMenuItem. Java applications are terminatedwith a call to System.exit(1).Additional Methods and Requirements• private void gameOver() – disable all buttons. This helper method is calledwhen the GUI determines the game is over by asking the Game object.• private void newGame() – instantiate a new game, reset the results JTextAreawith the initial game message, enable all buttons. Invoked this method when the playerselects the menu item.myGame = new Game();results.setText(myGame.getMessage());• Create File menu items for “New Game” and “Quit”. Reuse the code from Project 4.• Enhance the appearance of the GUI by providing color and borders to the Action andDirection panels (see Section 7.12).Sample GUIYour GUI will have different directions and additional actions.CIS162Project5–Summer2015Page7of8Using HashMapsA Hashmap is a special type of ArrayList that uses words, called a key, as the index insteadof integers. The book does not cover HashMaps but the following code should be sufficient for abasic understanding. You must adapt these examples in the Room methods.// define a HashMap with pairs of words and RoomsHashMap <String, Room myNeighbors;// instantiate the HashMap in the Room constuctormyNeighbors = new HashMap <String, Room ();// add Kitchen to the “north”myNeighbors.put(“north”, Kitchen);// Get the room (if any) found to the “east”Room next = myNeighbors.get(“east”);Creating RoomsCreating the rooms, items and relationships is accomplished by instantiating objects and usingtheir methods. For example:shoe = new Item(“shoe”, “a red Nike shoe”, 10);outside = new Room(“outside the main entrance of GVSU”, shoe, null);theater = new Room(“in a lecture theater”);outside.addNeighbor(“east”, theater);outside.addNeighbor(“south”, lab);outside.addNeighbor(“west”, pub);currentLocation = outside;Moving from Room to RoomMoving from one location to another involves updating the current location if there is a neighborin the requested direction. Here is an example for the Game method.public void move(String direction){Room nextRoom = currentLocation.getNeighbor(direction);if (nextRoom == null){msg = “You can’t go in that direction”;}else{currentLocation = nextRoom;msg = currentLocation.getLongDescription();}}CIS162Project5–Summer2015Page8of8Grading CriteriaThere is a 50% penalty on programming projects if your solution does not compile.• Stapled cover page with your name and signed pledge. (-5 pts if missing)• Project requirements as specified above. (90 pts)• Elegant source code that follows the GVSU Java Style Guide. (10 pts)Late PolicyProjects are due at the START of the class period. However, you are encouraged to complete aproject even if you must turn it in late.• The first 24 hours (-20 pts)• Each subsequent weekday is an additional -10 pts• Weekends are free days and the maximum late penalty is 50 pts.Turn InA professional document is stapled with an attractive cover page. Do not expect the lab to havea working stapler!1. Cover page – Provide a cover page that includes your name, a title, and an appropriatepicture or clip art for the project.2. Signed Pledge – The cover page must include the following signed pledge: “I pledge thatthis work is entirely mine, and mine alone (except for any code provided by myinstructor). ” You are responsible for understanding and adhering to the School of CIS Guidelines for Academic Honesty.3. Time Card – The cover page must also include a brief statement of how much time you spent on the project. For example, “I spent 7 hours on this project from January 22-27 reading the book, designing a solution, writing code, fixing errors and putting together the printed document.”4. Steps to winning the game – provide a step-by-step sequence that the player can take to win the game. This will allow the instructor to grade the game more easily. For example:a. Move Northb. Pickupc. Move Northd. Leave “wand”5. Sample Output – cut and paste the results from the Game’s main method showing the series of actions that lead to victory.6. Source code – a printout of your elegant source code for the Item, Room, Game and GUI classes.7. Compress the BlueJ project folder and submit the compressed file to Blackboard

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] SOLVED:Project 5 part A and B solution
30 $