Assignment 09

------- JUMANJI!! ------

Due: Thursday, April 19, 2018 at noon, 100 points

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 player’s path can be different. You will have to randomly create each user’s 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 can’t 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.

Foreground: Programming assignments #9 and #10 are tied together. In this part (#9), you are going to build some of the classes used in the final program (#10). After building them, you will use a main function that will test the functionality of the classes that you have created. This kind of main function is called a “driver.” Again, it’s only purpose is to test your classes. When you build homework #10, you will replace this main with a “real” main that does something useful to solve the given problem. The details of that problem are going to be described in homework #10. For now, you will just build some of the classes (described below) and use a driver to test them. Notice: You are to work individually on this assignment.

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.

For the data on the cards:

wget http://web.mst.edu/~price/1570/cards.dat

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.

When you submit: The only input for this program is the names you will have to enter for each player and their color choices. So, do that. And beware of the impending rhino stampede.

As always, if you have questions, just ask your instructor.