Homework 4, Welcome to DandyLand.
Short Description:
Write a basic version of DandyLand
This assignment is worth 40 points.
Goals
When you finish this homework, you should have:
- Worked with a scoped enumerated class.
- Worked with both unique and shared pointers.
- Overloaded the assignment operator and the ++ operator.
- Developed a working base for the next few homework assignments.
Formal Description
Write a basic version of DandyLand.
This version should be based on the following.
- Use the file GameConstants.h for constant values.
- Implement a scoped or strong enumeration
LandT
- This should represent the different types of land available.
- It should include UNKNOWN as the last enumerator.
- The integer constant
LAND_TYPE_COUNT
should represent the number of land types.
- Implement a version of the ++ operator
- UNKNOWN is returned as UNKNOWN
- All other values are transformed to the next, to the right, in the list.
- See the table below
- Implement
string LandTToString(LandT l)
- For a given LandT, this returns the associated string.
- Start with an upper case
- Everything else lower case.
- Unknown is returned as "Unknown".
- See the table below
- Implement an overloaded stream insertion operator that uses the above routine.
- Implement
LandT IntToLandT(int)
- The input is transformed to the range [0, LAND_TYPE_COUNT)
- It is then mapped to a LandT
- Implement
char LandTToSymbol(LandT l)
- that takes a LandT and returns the appropriate symbol
- See the table below
- Implement
LandT SymbolToLandT(char c)
that does the opposite of the previous function.
Land Type | Enumerator | ++ | String | Symbol |
Mountain | MOUNTAIN | FOREST | Mountain | M |
Forest | FOREST | PRAIRIE | Forest | F |
Prairie | PRAIRIE | UNKNOWN | Prairie | P |
Unknown | UNKNOWN | UNKNOWN | Unknown | ? |
- This should be implemented in LandT.h and LandT.cpp
- Implement a warehouse.
- Implement this in WarehouseT.h and WarehouseT.cpp
- This is a simple container.
- It holds integer values for Wood, Food, Gold, Construction, Coins, and Victory.
- Implement a const getter for each
- Implement a setter for each
- If the user attempts to change the size to be negative
- Throw a out_of_range exception
- The text "Can not have negative xxxxx."
- Where xxxxx is the name of the item.
- Use
SectorT
- SectorT.h
- SectorT.cpp
- Note, this will be replaced in the future.
- Note, this is really a place holder. I am sure that there are incorrect computations.
- Implement a
MapT
- This has a dependent data type
PointT
.
- This is a pair of a character and an integer.
- The character is the column of a point on the map.
- A-Z ( our maps will be no more than 26 characters wide)
- The integer is the row of a point on the map.
- PointT('A',0) is the upper left point.
- Implement the following utility functions (Not members of MapT)
-
PointT Up(PointT p)
- return the point one row up.
- Up('B',3) is ('B',2)
- This function will wrap, assume there are 7 rows.
- Up('B',0) is ('B',6)
-
PointT Down(PointT p)
- return the point one row down.
- Down('B',2) is ('B',3)
- This function will wrap, assume there are 7 rows.
- Down('B',6) is ('B',0)
-
PointT Left(PointT p)
- return the point one column to the left.
- Left('B',3) is ('A',3)
- This function will wrap, assume there are 5 columns.
- Left('A',4) is ('E',4)
-
PointT Right(PointT p)
- return the point one column to the right.
- Right('B',3) is ('C',3)
- This function will wrap, assume there are 5 columns.
- Right('E',4) is ('A',4)
- Implement an overloaded stream insertion operator.
- Please add the following
typedef std::shared_ptr<SectorT> SectorPtr;
- The map
- The map must be implemented as a 2D array of shared pointers to a SectorT
- The map must be stored in a unique_pointer.
- This can be accomplished as a one dimensional array of size
width x height
- To access point (x, y) use the equation
x + y*width
- Provide ALL required functions for a class with dynamic memory
- Some of these will be removed in the future.
- But I want to see you implement these.
- Provide the following functions
-
MapT(std::string FileName)
- Open the file and read in the map.
- If the file does not exist throw and invalid_argument exception
- Text "Invalid file name "+FileName
- Otherwise allocate the array shared_pointers to the sectors
- Then loop through and create a sector of the appropriate type.
- Caution, use
make_shared(ch)
, where ch is the character from the file for the sector.
- This should also mark the initial sector as found and deploy the initial population to that sector.
-
void PrintMap(void) const
- Prints the map, including the border.
-
int Width(void)const
- Returns the width of the map.
-
int Height(void)const
- Returns the height of the map.
-
SectorPtr Sector(PointT)
- Returns the shared pointer to a specified location.
-
PointT NormalizePoint(PointT p)
- This is a utility function to bring a point into the right range.
- It is part of the map because it needs the width and height.
- I am not sure it should be here, but put it here for now.
- I have changed the specification slightly from my implementation.
Please use this Makefile
Required Files
A single tar file containing the source code and Makefile for this program. Please do not include any executable or object code.
If you need to communicate any information, please put it in a file called ReadMe in this tar file.
Submission
Email your tar file as an attachment to the homework 4 D2L folder by the due date.