Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*IN PYTHON* A role-playing game or RPG is a game in which players assume the roles of characters in a fictional setting. The popularity of

*IN PYTHON*

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!

Weapons:

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

Armor:

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 the armor.

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

Characters:

Define a Python class called RPGCharacter.

Define a subclass of RPGCharacter called Fighter. Fighters possess the following characteristics:

  • 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 characteristics:

  • 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

Actions:

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) WEAPONTYPE".
    • deduct the amount of damage done by the weapon type from the opponent's current health.
    • print the message, "NAME does DAMAGE damage to OPPONENTNAME".
    • print the message, "OPPONENTNAME is now down to CURRENTHEALTH health".
    • 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 the spell).
  • 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 return.
    • 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 maximum.
    • 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:

  • __str__ for a character object should return a string, so that print(characterName) would print out the following:
     Name of character Current Health: ## Current Spell Points: ## Wielding: "xxxxx" Wearing: "xxxxx" Armor Class: ## 
  • checkForDefeat should take a character object as a parameter, and if the character's current Health is less than or equal to zero, print the message, "NAME has been defeated!"

main program was given

def main(): plateMail = Armor("plate") chainMail = Armor("chain") sword = Weapon("sword") staff = Weapon("staff") axe = Weapon("axe") gandalf = Wizard("Gandalf the Grey") gandalf.wield(staff) aragorn = Fighter("Aragorn") aragorn.putOnArmor(plateMail) aragorn.wield(axe) print(gandalf) print(aragorn) gandalf.castSpell("Fireball",aragorn) aragorn.fight(gandalf) print(gandalf) print(aragorn) gandalf.castSpell("Lightning Bolt",aragorn) aragorn.wield(sword) print(gandalf) print(aragorn) gandalf.castSpell("Heal",gandalf) aragorn.fight(gandalf) gandalf.fight(aragorn) aragorn.fight(gandalf) print(gandalf) print(aragorn) main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions

Question

What are the characteristics of structured cabling systems?

Answered: 1 week ago

Question

=+How sensitive is Pats decision?

Answered: 1 week ago