CS 313E: Bulko
Programming Assignment 2:
Due Date: September 22, 11:59 pm
A role-playing game or RPG is a game in which players assume the roles of characters in
a fictional setting. The popularity of the epic saga told in J.R.R. Tolkien's The Hobbit
and The Lord of The Rings greatly influenced the genre, as seen in the game Dungeons
& Dragons and all of its subsequent variants.
In most RPGs, a player creates a character of a specific archetype or class, such as
"Fighter", "Wizard", or "Thief". (Note: do not confuse a "character class" with a Python
class; although we will define character classes using Python classes, they do not mean the same
thing, so it might be a little confusing.) The class defines a set of characteristics, constraints, and
behavior that apply to all characters of that class. For example, a Thief has the ability to move
with great stealth; however, in order to do that effectively, the Thief cannot wear bulky, noisy
armor or carry large weapons.
In this assignment, you will create a very simple RPG. You will define two character classes,
define characteristics and actions associated with those classes, and create one character of
each class. You will define types of weapons and armor suitable for your characters to use.
Finally, you will have your two characters battle each other!
Define a Python class called Weapon. When a Weapon object is created, it should include as
a parameter a String that identifies the weapon type. Each weapon type will do a specific
amount of damage when it strikes an opponent.
Valid weapon types and the damage done by each are:
- "dagger": 4 points of damage
- "axe": 6 points of damage
- "staff": 6 points of damage
- "sword": 10 points of damage
- "none": bare hands; default 1 point of damage
Define a Python class called Armor. When an Armor object is created, it should include as
a parameter a String that identifies the armor type. Each armor type offers a specific
amount of protection (the "Armor Class" or AC) when an opponent attacks the character wearing
Valid armor types and the AC associated with each are:
- "plate": plate armor with AC 2
- "chain": chain mail with AC 5
- "leather": leather mail with AC 8
- "none": no armor worn; default AC 10
Define a Python class called RPGCharacter.
Define a subclass of RPGCharacter called Fighter. Fighters possess the following
- The maximum Health a Fighter can have at any time is 40 points. If a
character's health drops below zero, the character is said to be "defeated".
- The maximum Spell Points a Fighter can have at any time is 0. Spell Points
are used to cast magic spells; Fighters cannot use magic.
- Fighters are allowed to use any weapon type.
- Fighters are allowed to wear any type of armor.
Define a subclass of RPGCharacter called Wizard. Wizards possess the following
- The maximum Health a Wizard can have at any time is 16 points.
- The maximum Spell Points a Wizard can have at any time is 20.
- Wizards can only fight with a "dagger", a "staff", or their bare hands.
- Wizards cannot wear armor. It interferes with their ability to cast spells.
When a character is created, it should include as a parameter a String that identifies the
character's name. Creation of a character should also initialize the following characteristics:
- No armor being worn
- No weapon being wielded
- Current Health equal to the maximum Health for its class
- Current Spell Points equal to the maximum Spell Points for its class
A character of any class can perform the following actions:
- He/she can wield a weapon. Define a method wield that takes
a weapon object as a parameter. If the weapon type is allowed for that character's class,
the method should print the message, "NAME is now wielding a(n)
WEAPONTYPE"; otherwise, it should print "Weapon not allowed
for this character class."
- He/she can unwield a weapon. Define a method unwield
that sets the character's current weapon to "none" and prints the message,
"NAME is no longer wielding anything."
- He/she can put on armor. Define a method putOnArmor that takes
an armor object as a parameter. If the armor type is allowed for that character's class,
the method should print the message, "NAME is now wearing
ARMORTYPE"; otherwise, it should print "Armor not allowed
for this character class."
- He/she can take off armor. Define a method takeOffArmor
that sets the character's current armor to "none" and prints the message,
"NAME is no longer wearing anything."
- He/she can fight another character. Define a method fight that
takes a character object as a parameter. The method should:
- print the message, "NAME attacks OPPONENTNAME with a(n)
- deduct the amount of damage done by the weapon type from the opponent's
- print the message, "NAME does DAMAGE damage to
- print the message, "OPPONENTNAME is now down to
- check to see if the opponent has been defeated. (See below.)
A wizard (and only a wizard) can also perform the following action:
- He/she can cast a spell. Define a method castSpell that
takes as parameters a String (the Spell Name) and a character object (the target of
- A spell has a Spell Name, a cost in Spell Points, and an effect in
Health Points. A spell is always targeted at a specific character, possibly even the
caster him/herself. When the spell is cast, the caster consumes the cost in Spell Points, and
the target is affected by the effect in Health.
- The three different spells available are:
- "Fireball": cost = 3, effect = 5.
- "Lightning Bolt": cost = 10, effect = 10.
- "Heal": cost = 6, effect = -6. (That means the
target's Health increases by 6 points.)
- When a character casts a spell, the method should:
- print the message, "NAME casts SPELLNAME at TARGETNAME".
- if the Spell Name is not one of the three listed, print the message,
"Unknown spell name. Spell failed." and return.
- if the number of Spell Points possessed by the caster is less than the cost of the
spell, print the message, "Insufficient spell points" and
- adjust the target's Health based on the effect of the spell. Note that casting a
Heal spell can never raise the target's Health above its
- adjust the caster's Spell Points based on the cost of the spell.
- if the spell was a Heal spell, print the message,
"CASTER heals TARGET for ### health points". Otherwise,
print the message, "CASTER does ### damage to TARGET",
followed by "TARGET is now down to ### health", and then
check to see if the target was defeated. (See below.)
Two other methods you must define are:
Test your program thoroughly with your own characters and sequence of actions. However, to
make it easier to grade your assignment, turn in your code using the following main program:
For debugging purposes, here is the expected output that this main program should produce:
Disclaimer for serious RPG gamers: this RPG has been stripped down for the purpose of
keeping the homework assignment simple. Consequently, several standard features common to RPGs
have been omitted; for example:
- "Armor class" is defined, but we don't do anything with it.
- Battle is not random: attacks always hit and do the maximum damage.
- Spells always hit and do the maximum damage.
- Characters don't have a formal inventory.
- Characters don't have levels.
However, this doesn't prevent you from adding these features yourself if you want to create your own
fun RPG! Sorry, no extra credit for doing this, though. :-)
Turning in the Assignment:
The program that you will write should appear in a file called RPG.py. There is no
input data file for this assignment. Submit the file via Canvas before the deadline shown at
the top of this assignment.