Homework X, Title.
Create a data type to support the Ability statistic in for an implementation of a game using The Simple Game System 2E-R5
When you finish this homework, you should have:
- Refreshed your programming ability.
- Refreshed your knowledge of enumerated types.
- Demonstrated your ability to overload operators for enumerated types.
The Simple Game System is a set of RPG rules developed by Chris Gonnerman. This short set of rules allows players to participate in easy to play shared story based adventures. We will be using these rules to motivate some of our exercises this semester. The rules are available at the above we site, with a local copy here.
For your first exercise you will implement the ability statistic as a strong enumerated type, along with operations on this type. Since we might incorporate this code in future projects, you must comply with the following specifications.
- Your type should be called
AbilityT and be declared in the files
AbilityT.cpp. This must be a strong enumerated type (see the book page 19).
- You must supply the constant
FIRST_ABILITY. This is the first value of an ability and it must represent a positive ability, most likely strong.
- You must represent both abilities and disabilities (as defined in the rules) in this type. In addition you must provide an ability
- You must provide the following functions:
- This function returns the name of the corresponding ability.
- It should return NONE if the ability is none or invalid.
- The string should match those in the game description, but be all lower case.
AbilityT StringToAbilityT(const std::string &)
- This function returns an ability that matches the supplied string.
- The case of the letters in the string does not matter.
- If the string does not match any ability/disability, AbilityT::NONE should be returned.
- You must provide overloaded stream insertion and extraction operators to read/write your data type. These read/write a string from/to the supplied stream.
- You must provide an
AbilityT + size_t operator.
- Any positive ability plus 1 returns the corresponding negative ability.
strong + 1 = weak
- Any positive ability plus 2 returns the next positive ability.
strong + 2 = tough (or some other positive ability)
- Any negative ability plus 1 returns the next positive ability.
weak + 1 = tough (or some other positive ability)
- Any overflow results in none
strong + 1000 = none
- Any invalid argument results in none.
bob + 1 = none
- Any missing rules are covered by the test cases.
- You must provide pre/post increment operators, ++a, and a++
- These produce
- If a is positive, the next positive ability or none.
strong++ = tough
attractive++ = none
- If a is negative, the next negative ability or none.
weak++ = sickly
ugly++ = none
- You must provide a unary minus operator, -a.
- If a is positive, it returns the corresponding negative ability.
-strong = weak
- If a is negative, it returns the corresponding positive ability.
-weak = strong
- none is greater than any other ability.
I can't figure out a good way to test without the following restriction. I don't like it, but please put your abilities in the order listed in the document (strong, weak, tough, sickly, clever, ..., none).
Please use the following
I believe that AbilityTest is a good test of this class. If I find any errors I will correct them. Your code should compile and run with the provided files. If it is correct, it should produce no output.
You will probably want to comment out sections of this driver as you develop your code. That is fine, but I will replace your driver with mine when I test the code. In the end your code must work with this driver or you will receive a 0 with no make up.
You must use a strong enumerated type. Failure to do so will result is a 0, with no make up.
You must compile with the provided compiler flags. Failure to do so will result in a 0 with no make up.
The test file takes precedence over this write up. If you find a conflict, please inform me before the due date.
A single tar file containing the source code and Makefile for this program.
Submit the assignment to the D2L folder Homework 2 by the due date.