Design your own text-based adventure game

Assignment Help JAVA Programming
Reference no: EM132225807

Assignment

Part I:

Written Exercise 1: Imagine you would like to allow rooms to have a new type of exit (e.g. "up"). Identify each class and method that you would have to change in order to allow for this type of exit. Briefly describe the changes you would make in each class and method that you identified. NOTE: Do not actually make these changes yet!

Several methods in the Game class contain repeated functionality. Specifically, the printWelcome method and the goRoom methods both print a description of the current room and a list of the exits. As we have learned, having the same functionality implemented in multiple locations can lead to the introduction of errors when software is modified. Correct this problem by factoring the common functionality out of these methods into a method of its own. Then call this new method each place the description and exits are to be displayed.

Part II:

Currently the code that generates and displays the list of exits from a room is contained in the Game class. This is not a particularly good design. Each room in the game is represented by a Room object. The Room object contains fields that store the information about that room's exits. Therefore it should seem like this program would be better if the code to generate a list of the exits for a room would be contained in the Room class. Make this improvement by adding a method named getExitString to the Room class. This method should return a String listing the exits from the room. For example, if the room has exits to the north and west, this method should return a String containing: "north west".

Now that each Room is capable of generating a list of its own exits. Refactor the code in the Game class to take advantage of this functionality. I.e. anywhere the Game class generates a list of the exits from the current room, change it to use your getExitString method.

Written Exercise 2: After making the above improvements to the code, imagine again that you would like to allow rooms to have a new type of exit (e.g. "up"). Now identify each class and method that you would have to change in order to add the new type of exit. Has the design improved? Why or why not? NOTE: Do not actually make these changes at this stage!

Currently, the Game class generates the full description of the current room (including information about exits) and displays it. This is dealing with data of the Room class, so the Room class should be responsible for generating this description. Add a method called getLongDescription to the Room class that returns a String containing the description and exits of a room, and refactor the Game class to use it whenever the Game needs to print information about a Room.

Part III:

Design your own text-based adventure game, using the given zuul game as a starting point. Some possible game scenarios are described in Exercise 6.3 of the text and you will have others from your brainstorming activity. If you find it difficult to visualize this sort of game scenario, try modeling your game on some familiar real-world location. If you need additional inspiration, you can try playing the original Colossal Cave Adventure game.

Some additional specifications:
– Your game scenario must include at least six different rooms.
– There must be at least six types of exits for the rooms in your game. For example, you could use north, south, east, west, up and down. This requirement does NOT mean that each room must have 6 exits -- most or even all rooms will have fewer.
– Your game scenario must include at least four items that the player could find, pick up and potentially use.
– Your game must have some way for the player to win. Most likely, this will be by achieving some goal such as finding a particular item, surviving for some specified number of moves, whatever makes sense for your game.

Written Exercise 3: Write a brief description of your game, including the setting for the game, the items in the game, and how a player wins. Save this in a Word doc to be submitted with your assignment.

Written Exercise 4: Draw a map for your game scenario. Label the rooms and the exits (connections between rooms), and specify the locations of the items. The map can be hand-drawn

- you do not need to use a drawing program. This map must also be placed in the Word doc.

Update the comments at the beginning of the Game class and the message displayed by the printWelcome method so that they describe your game.

Change the createRoomsAndPlayer method in the Game class so that it creates the rooms and exits that you invented for your game. You do not need to add any items to your game yet. You will add items later.

Update the test methods in the GameTest class as necessary to account for your changes to the Game class. You can directly edit the code in the test class, or delete any test methods that do not pass and re-record them. Play the game for a bit - enjoy the fruits of your hard work!

Part IV
In many games (perhaps even in yours) there may be a very large number of different types of exits (e.g. "up", "down", "window", "slide", "stairway", "trapdoor", "trampoline", "fire-pole" etc...) One way to support such exits would be to make the changes that you identified in Written Exercise 2 for each imaginable type of exit. This is clearly better than it would have been before you completed Part II, but it is still not ideal. It would be better if it were possible for an exit to have any arbitrary name and that when given the name of an exit we could find the associated Room that lies beyond. This should sound like a good job for a HashMap where the name of an exit is the key and the Room lying beyond the exit is the value. Improve the design of the Room class by refactoring it so that it uses a HashMap to store the exits instead of an individual field for each exit.

Play the game to check that it still works - take a deep breath and relax a bit!

Part VI:
You game scenario requires that there be items positioned throughout the world that the player can pick up and possibly use. An item sounds like something that should be represented by an object! So create an Item class to represent the items in your game. You will need to decide what fields your Item class needs to have, what parameters the constructor will require and what methods the class will have. At a minimum, items will have a name and a description. However, items may have any other attributes that make sense for your game (e.g. weight, colour, value, destructive power
..)

Now that there is a class for representing Items we need a way to allow the rooms to contain an item. Modify the Room class so that one item can be added to or removed from the room. You will need to think about what fields and methods to add to the Room class. Also think about what the methods that you add should do when an attempt is made to add an item to a room that already contains an item, or an attempt is made to remove an item from a room that does not contain an item.

Now that a room can contain an item, when the player enters a room he/she should be told about the item in that room (if there is one). Modify the appropriate code so that if the player enters a room containing an item, the name and description of the item are displayed along with the description of the room and the list of exits.

Edit the code in the Game class so that the items for your game are created and added to the appropriate rooms at the start of the game. Recall that your game must include at least four items. Be sure to test any methods that you add or modify.

Play the game to ensure that your items are appearing in the rooms - enjoy the coolness of what you are creating!

Part VII:
Now that rooms can contain items and a player will know when they enter a room with an item, it would be nice if the player could pick up and carry items. Add functionality to the Player class that will allow the player to pick up and drop items. The player should be able to carry any number (i.e. a collection) of items.

Update your tests for the Player class to test the addition and removal of items.

Modify the Game class so that it will recognize the command take. When the user enters the "take" command, the item in the current room, if there is one, should be added to the items that the player is carrying and a message should be printed indicating that the player has taken the item. If there is no item in the current room the take command should print an error message. Be sure to test any methods that you add or modify. (Hint: Remember that one task of the Game constructor is to "teach" the CommandReader what words are valid commands. Thus, you will need to make a change in Game's constructor if you want to introduce a new command.)

Play the game to be sure the take command works!

Modify the Game class so that it will recognize the command inventory. When the user types "inventory" the game prints the names of the items that the player is currently carrying. You should think carefully about where the list of item names should be generated. (Consider the fact that the player is carrying the items, and think about how the list of exits for a room is generated and displayed.)
Play the game to be sure the inventory command works!

Add support to the game for a drop command so that the player can drop an item by name (e.g. "drop book"). The dropped item should appear in the current room. If the current room already contains an item, the drop command should print an error message indicating that the room is full and the player should continue to carry the item.
Play the game to be sure the drop command works!

Notice that when you use the help command take, inventory and drop do not appear as command words. Modify the printHelp method of the Game class so that it automatically displays any new command words that are added to the game. Hint: there is a helpful method in the CommandReader class.

Play the game to be sure the modified help command works - celebrate!
THIS IS END OF THE REQUIRED PART OF THE ASSIGNMENT. Below are bonus enhancements:
If you completed all of the above parts, you may complete any or all of the following exercises for extra credit. You must explicitly state which (if any) of these bonus problems you have done.

Include a description of the bonus exercises that you have completed with the written exercises. Problems worth at most 2 extra points:
– Exercise 6.41 in the text.
– Exercise 6.42 in the text. Problems worth at most 4 extra points:
– Exercise 6.23 in the text.
– Exercise 6.43 in the text.
– Exercise 6.44 in the text.
– Exercise 6.45 in the text.
– Allow each room to contain a collection of items (rather than just one).
– Modify the game so that only a list of the names of the items in a room are displayed when the player enters. Then add a look command that allows the player to look at an item in the current room by name. For example, if the player types look book and there is an item named "book" in the current room, your game should display the description of that item. If there is no such item, your game should display an error message. If the player enters the look command with no second word, it should display the entire description of the room, its exits and the names of any items again.

Problems worth at most 6 extra points:
– Exercise 6.26 in the text.
– Exercise 6.47 in the text.
– Modify your game to allow the player to win (as you described in your game scenario). Problems worth at most 8 extra points:
– Do Exercise 6.48 in the text. Note that you must do Exercise 6.47 before doing this one. Hints:
You can add the following method to the Room class to randomly choose an exit for the character when it moves. Note that exits is the field (of type HashMap) that contains the exits for the room - if you used a different field name, use that name instead.
/
choose a potential exit at random
/
public String randomExit() {
Object [] dirs = exits.keySet().toArray();
int index = (int) (Math.random() dirs.length); return (String) dirs[index];
}

Your test cases for character movement do not need to check the location of the character after moving (because characters may move randomly).

Variable bonus points:
if some other game modification or extension makes more sense for your game scenario, you may make this modification or extension for extra credit with approval of your tutor. You must also thoroughly describe this modification or extension in your written game description.

Workshop activities

Your workshop activity this week is to start work on your assignment.

Your tutor will lead a brainstorming exercise to come up with ideas for your theme. Start work on your assignment.

Once you have the game working (to the end of Section 6.13 / 8.13), work out what enhancements will suit your game theme.

Attachment:- Topic.rar

Reference no: EM132225807

Questions Cloud

Pick one of hofstede variables : Pick one of Hofstede's variables and explain why you agree or don't agree that it describes today's workplace culture in China.
Find the possible value of a location : Is it appropriate to build a forecasting model to find the possible value of a location?
Rivalry in the business jet market : How intense is the competitive rivalry in the business jet market? What is the evidence?
Strategy for coping with a threatening environment : Is changing the organization's domain a feasible strategy for coping with a threatening environment?
Design your own text-based adventure game : CSC72003 - Programming - southern cross university - Identify each class and method that you would have to change in order to allow for this type of exit
Construct a plan that ensures a virtual team : Your new team for Health Care, Inc may consist of team members from different locations. Construct a plan that ensures a virtual team's performance
Linear program will have how many constraints : If a transportation problem has 4 origins and 5 destinations, the linear program will have how many constraints?
Write program to input a list of names and account balances : Write a program to input a list of names and account balances from the keyboard and write them into a file called "out.txt"
Provide a brief background of the team and leader : Provide a brief background of the team and leader you are evaluating. What actions, behaviors, characteristics make this team successful?

Reviews

len2225807

2/1/2019 9:01:31 PM

This week we will be working through something different – the beginnings of your project for your major assignment. To do this, you will work through part of one of the chapters of our recommended text (provided on MySCU from an earlier edition) and implement a text-based game, using your own theme. Note that the provided text is Chapter 6 (beginning to 6-6.14) and in the latest version of the text this is Chapter 8. If you download the provided chapter, you will be using the correct material.

Write a Review

JAVA Programming Questions & Answers

  Create a java program that manipulates an array

In the main method, have the user input the size of an array. Create an integer array of that size. Then call the methods outlined in the following steps.

  Explain security and permissions for the android platform

Briefly explain security and permissions for the Android Platform. Briefly describe some of the Android Platform Services. Describe the Android Platform Differences (complete, open, and free).

  Creates a new magazinenode object and adds it to the end

The public variables are accessed by the MagazineList class.

  Create a program that accepts a 10-digit phone number

Create a program that accepts a 10-digit phone number (no 1 in front) and tells the user if the message is a toll-free number.

  The class overloaded constructor receives a 2-dim int array

The class overloaded constructor receives a 2-dim int array as a parameter and assigns its values to a private 2-dim int array. Have another method that prints the whole 2-dim table.

  Demonstrate your knowledge in a pragmatic way

Summarize everything that we have addressed in the XML Applications course, and provide a mechanism to demonstrate your knowledge in a pragmatic way.

  Programming sorting algorithms

Describe an approach to modifying the Sorts.java program so that after calling a sorting method the program prints out the number of swaps needed by the sorting method.

  Implement a stack in javascript

The Pop function should always return the element on the top of the stack and at the same time removing it from the top of the stack.

  Design a single class that expresses the commonality

Design a single class that expresses the commonality of these concepts.

  Write a genetic algorithm in java to solve knapsack problem

The assignment is to write a genetic algorithm in Java to solve the Knapsack Problem. Define the problem as a genetic algorithm

  Scenario - clinic management system

Change the category of a doctor - Clinic Management System - Java client application that perform

  Demonstrate the use of array or arraylist

It will calculate the additional amount of sales that each salesperson must achieve to match or exceed the higher of the two earners. The application should ask for the name of each salesperson being compared.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd