The following is a list of topics we wish to address with this assignment:

  • Classes
  • More classes
  • Some classy classes
  • Showing some class
  • Everything else you have learned up to this point

Background: Jumanji is a game for those who wish to find a way to leave their world behind. Adventurers should beware; the exciting consequences of the game will vanish only when a player has reached Jumanji and called out its name! Wow. In homework #9 you will create object classes necessary for a program that will allow users to actually play Jumanji in homework #10.

In this game, there can be 2-4 players. At the beginning of the game each player will be expected to enter his/her name and choose the color of his/her game piece (red, green, blue, or orange); note that no two players can have the same colored game piece. Each player will also have a number of lives, which, in the game, can be lost!

The game board consists of winding, albeit linear, paths through a jungle. Each player will have his/her own path. There are 42 spaces on a path, numbered from 0 to 41. Each space on a path will contain 1 of 4 different kinds of entries: blank, wait for 5 or 8, jungle, or rhino. Each players path can be different. You will have to randomly create each users path according to the following specifications: there should be 5 randomly positioned wait for 5 or 8 entries, 3 randomly positioned jungle entries, and 7 randomly positioned rhino entries; all other positions should be blank.

The game also has a single deck of (at most 50) cards that the players will draw from throughout the game. Each card contains 4 things: a positive integer that will determine how many spaces a player can move along his/her path, a riddle (of at most 128 characters) about the danger they are encountering, a string (of at most 25 characters) identifying what the danger is (in case they cant solve the riddle!), and a string (of at most 20 characters) describing what will rescue them from this danger (e.g., axe). Before the players can start the game, you must create the deck of cards by reading information about the cards from a data file (cards.dat) into an array and then shuffling the deck (i.e., array) of cards; there are many ways to do that (think about it). Each line of card information in the data file contains the 4 entries for that card as described above, with each entry separated by a tab; this is called a tab-separated file. The last line in the file contains a single entry of -1, which signals the end of the data; this is called a sentinel file.

There is one other important part of the game. The players will have to roll a rescue die (die is singular for dice). It has 8 sides which are respectively labeled: "axe", "die", "open door", "racquet", "raft", "rope", "saber", and "hourglass". Not coincidentally, these are the same rescue strings that can appear on the cards.

Specifications: Here are descriptions of the classes we want you to create:

card class:

Member variables:

  • An unsigned int (this is an int that can only be 0) for the number of spaces to move
  • A string for a riddle about the danger you're encountering
  • A string for the answer to the riddle
  • A string (or some other type) to represent what will rescue you (e.g., axe)

Member functions:

  • Appropriate accessor/mutator functions
  • Constructor(s)
  • Overloaded insertion (<<) operator

cardDeck class:

Member variables:

  • An unsigned int for the actual number of cards in the deck
  • A 1D array of card

Member functions:

  • Appropriate accessor/mutator functions
  • Constructor(s)
  • Overloaded insertion (<<) operator
  • Function to read in the card info from a file
  • Function to shuffle the 1D array
  • Function to get the next available card in the array (i.e., throughout the game players will repeatedly need to draw a card from the top of the deck); if this function is called and you have reached the bottom of the deck, you should re-shuffle the deck and draw from the beginning of the newly shuffled deck (i.e., array)

path class:

Member variables:

  • A 1D array of entries that can be blank, wait for 5 or 8, jungle, or rhino
  • An unsigned int that represents the current position in the array; initially this is 0

Member functions:

  • Appropriate accessor/mutator functions
  • Constructor(s)
  • Overloaded insertion (<<) operator

player class:

Member variables:

  • A string for the user's name
  • The player's game piece color (i.e., red, green, blue, or orange)
  • The player's number of lives; initially this is 3
  • The player's path (which is of type path)

Member functions:

  • Appropriate accessor/mutator functions
  • Constructor(s)
  • Overloaded insertion (<<) operator
  • Function to move the player a specified number of spaces in his path; note that you shouldn't be able to move beyond the bounds of the path!

Note: You can create additional member functions for each of these classes and you can create additional classes. But you must create the things listed above. Also, for the insertion ops, make them so that the information fits on one line if possible. For the path, you might shoot for this format as an example:

path:
13 : rhino
14 : wait for 5 or 8
17 : jungle
-- etc -- (leave out specifying blanks)

There is a LOT of code that we are NOT specifying for you. It is up to you how you want to implement what's going on here. Be cool...and write good code!

Now, in order to test your homework #9 functionality, we want you to write your main() function as a driver (as previously discussed). Specifically, your main( ) should do the following:

1. Prompt for and get input for the names of 4 players. For testing purposes, use BoJack, Todd, Mr. Peanutbutter, and your own name. Let the players pick whatever colors (red, green, blue, or orange) they want for their game pieces but remember that no two players can have the same color.

2. Initialize a Player object for each of the 4 players and output all their information including their paths. Note: For a path, you don't have to output the entries for all 42 spaces; just output what is in the non-BLANK entries.

3. Initialize and output the shuffled deck of cards. Output everything that is on each card.

4. Do the following 3 times:

Have each player (in the order they were originally entered) do the following:

a. Roll a 6-sided die (i.e., sides are numbered 1-6).
b. Move that many spaces forward on the player's path.
c. Output what entry that space of the path has on it (i.e., blank, wait for 5 or 8, jungle, or rhino).
d. Select the next available card from the deck and output the info that is on it.
e. Roll the rescue die and output what label it shows.
f. Tell whether the rescue die label matches the rescue string on the card.

We might point out that you should not open this file with an editor you don't know really well. Some editors can change a file simply by opening it. As stated, the "fields" of this data file are tab-character delimited. You don't want to risk messing that up.

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.