Objectives:

To gain experience with dynamic memory allocation, inheritance, polymorphism, and class composition.

Description:

For this project you are going to make some sort of adventure game. The plot of your game is up to you. You may have a warrior who wonders around in a dungeon fighting monsters, or a series of items to collect in order to achieve a goal. Be creative. I'm hoping you will have some fun designing your own plot, so come up with something you don't mind reusing for future projects (we will be adding to the game throughout the term).

The game will basically be played on a 2D grid. Each location on the grid will be a location that the character can visit. Different events may take place at various locations. What happens at each location is up to you. However, there needs to be tasks for the player to accomplish at multiple locations in order to win the game.

Requirements:

You must write a series of classes to complete the project.

CLASS #1: The Player class. You can probably reuse your class from Project 2 here (plus any additions specific for your game). At a minimum, you need to have a class which describes the character playing the game.

CLASS #2: The Location class. This should be a generic class that will serve as the base for other classes. At a minimum, it should have an attribute called visited, that tracks whether or not the player has been to a particular location. The constructor of this class should set this value to false. You may have certain events that only occur the first time the player visits a location. For instance, if there is an item in a location that the player retrieves, then the item should not be in the location the next time the player is there. This variable will help you to determine when a player has visited a location. This class should also have a virtual function called visit. This function will be overloaded in the derived classes.

CLASSES #3-5: You should have at least three other classes that inherit from the location class. These classes describe different activities which the player can do at various locations in your game. For instance, you may have a location where the player fights a monster, or has to answer a riddle. Each of these classes describes a unique type of location with a specific event that can occur in the game. Each of these classes should overload the visit method inherited from the Location class to describe the event specific to the class.

CLASS 6: The Game class. You should have a class that is composed of a two dimensional dynamically allocated array of pointers to Locations. This class should have a method to read a data file and a method called playGame, which actually plays the game. Feel free to add other attributes and methods to this class as you feel they are needed. The read data file method should read a data file (in the format described below) and then dynamically allocate the locations array to the appropriate size. The playGame method should allow players to travel around in the game world and do the actions specific to each location. This method is also responsible for determining when the game ends.

You must write separate .h files for each class.

You should also use good commenting and code style. Expect points to be deducted from your score if you do not comment your code and use good coding practices.

You may not use global variables or GOTO statements.

That is it for the requirements, the rest is up to you. Feel free to add to the classes as much as you want to make your game fun and exciting. At a minimum, there must be at least four things for the player to do to win the game.

The Data File:

The purpose of the data file is to make it easy to modify and/or change your game. The data file should begin with two numbers that tell how many rows and how many columns will be in the two dimensional array of pointers to locations in the Game class. Following that, will be the actual data about the specific locations. Here is an example of what a data file might look like:

3 4
o castle o goblin
crystal o o goblin
o goblin o goblin

The first line (with 3 4) tells the program to expect 3 rows and 4 columns of data to follow. After this is the data about each location. The "o" just means that it is a basic location with no special action (CLASS #2). Castle, Goblin, and Crystal are all special locations that have an event for the player to perform (CLASSES #3-5). You should replace the words castle, crystal, and goblin with the actual names of the classes you created for your project. As your program reads this data file, it should dynamically create objects of the appropriate types and place these objects into the two dimensional array in the appropriate locations.

Your data file does not have to look anything like the example above. Feel free to make it more complex if it would improve your game in some way.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.