Question

*IN PYTHON* A role-playing game or RPG is a game in which players assume the roles...

*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()
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#!/bin/python3

def showInstructions():
    #print a main menu and the commands
    print('''
RPG Game
========

Get to the Garden with a key and a potion
Avoid the monsters!

Commands:
go [direction]
get [item]
''')

def showStatus():
#print the player's current status
print('---------------------------')
print('You are in the ' + currentRoom)
#print the current inventory
print("Inventory : " + str(inventory))
#print an item if there is one
if "item" in rooms[currentRoom]:
    print('You see a ' + rooms[currentRoom]['item'])
print("---------------------------")

#an inventory, which is initially empty
inventory = []

#a dictionary linking a room to other room positions
rooms = {

            'Hall' : { 'south' : 'Kitchen',
                  'east' : 'Dining Room',
                  'item' : 'key'
                },      

            'Kitchen' : { 'north' : 'Hall',
                  'item' : 'monster'
                },
              
            'Dining Room' : { 'west' : 'Hall',
                  'south' : 'Garden',
                  'item' : 'potion'
            
                },
              
            'Garden' : { 'north' : 'Dining Room' }

         }

#start the player in the Hall
currentRoom = 'Hall'

showInstructions()

#loop forever
while True:

showStatus()

#get the player's next 'move'
#.split() breaks it up into an list array
#eg typing 'go east' would give the list:
#['go','east']
move = ''
while move == '':
    move = input('>')
  
move = move.lower().split()

#if they type 'go' first
if move[0] == 'go':
    #check that they are allowed wherever they want to go
    if move[1] in rooms[currentRoom]:
      #set the current room to the new room
      currentRoom = rooms[currentRoom][move[1]]
    #there is no door (link) to the new room
    else:
      print('You can\'t go that way!')

#if they type 'get' first
if move[0] == 'get' :
    #if the room contains an item, and the item is the one they want to get
    if 'item' in rooms[currentRoom] and move[1] in rooms[currentRoom]['item']:
      #add the item to their inventory
      inventory += [move[1]]
      #display a helpful message
      print(move[1] + ' got!')
      #delete the item from the room
      del rooms[currentRoom]['item']
    #otherwise, if the item isn't there to get
    else:
      #tell them they can't get it
      print('Can\'t get ' + move[1] + '!')

# player loses if they enter a room with a monster
if 'item' in rooms[currentRoom] and 'monster' in rooms[currentRoom]['item']:
    print('A monster has got you... GAME OVER!')
    break

# player wins if they get to the garden with a key and a shield
if currentRoom == 'Garden' and 'key' in inventory and 'potion' in inventory:
    print('You escaped the house... YOU WIN!')
    break

Add a comment
Know the answer?
Add Answer to:
*IN PYTHON* A role-playing game or RPG is a game in which players assume the roles...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ programming question, please help! Thank you so much in advance!!! In this exercise, you will...

    C++ programming question, please help! Thank you so much in advance!!! In this exercise, you will work with 2 classes to be used in a RPG videogame. The first class is the class Character. The Character class has two string type properties: name and race. The Character class also has the following methods: a constructor Character(string Name, string Race), that will set the values for the name and the race variables set/get functions for the two attributes a function print(),...

  • UML CLASS DIAGRAM This is a Design Exercise. You will need to make classes that could...

    UML CLASS DIAGRAM This is a Design Exercise. You will need to make classes that could be used to stage a battle as described below. You have been tasked to create a number of items that can be used in an online game. All items can be used on a game character who will have a name, a number of health-points and a bag to hold the items.   Here are examples of items that can be made: Item type of...

  • IS 331 NJIT Assignment 5 Steps to complete in Microsoft Access Use the sample solution to...

    IS 331 NJIT Assignment 5 Steps to complete in Microsoft Access Use the sample solution to assignment 4 (below) as the conceptual model, develop a logical model (relational model) based on it. Specify all the integrity constraints in English. For each table in the Assignment 4 solution, write a relation in the form TableName(PK attribute, attribute 1, attribute 2, etc) For each relationship connection between the tables, write a constraint in the form CONSTRAINT foreign_key REFERENCES reference_table_name For any N:M...

  • C++ Inheritance Problem Step a: Suppose you are creating a fantasy role-playing game. In this game...

    C++ Inheritance Problem Step a: Suppose you are creating a fantasy role-playing game. In this game we have four different types of Creatures: Humans, Cyberdemons, Balrogs, and elves. To represent one of these Creatures we might define a Creature class as follows: class Creature { private: int type; // 0 Human, 1 Cyberdemon, 2 Balrog, 3 elf int strength; // how much damage this Creature inflicts int hitpoints; // how much damage this Creature can sustain string getSpecies() const; //...

  • (a) FileIO In the FileIO class add a public static method named writeCharacter. This method takes...

    (a) FileIO In the FileIO class add a public static method named writeCharacter. This method takes as input a Character to write, and a String which is the filename to write to. Within this writeCharacter method, use the FileWriter and BufferedWriter objects to write the character’s information back to a file. Make sure to catch the IOException when writing a file, and throw an IllegalArgumentException with an appropriate error message. If you prefer, you can also use the throws statement...

  • Write three object-oriented classes to simulate your own kind of team in which a senior member...

    Write three object-oriented classes to simulate your own kind of team in which a senior member type can give orders to a junior member type object, but both senior and junior members are team members. So, there is a general team member type, but also two specific types that inherit from that general type: one senior and one junior. Write a Python object-oriented class definition that is a generic member of your team. For this writeup we call it X....

  • Zybooks 11.12 LAB*: Program: Online shopping cart (continued) Python 3 is the code needed and this...

    Zybooks 11.12 LAB*: Program: Online shopping cart (continued) Python 3 is the code needed and this is in Zybooks Existing Code # Type code for classes here class ItemToPurchase: def __init__(self, item_name="none", item_price=0, item_quantity=0): self.item_name = item_name self.item_price = item_price self.item_quantity = item_quantity # def __mul__(self): # print_item_cost = (self.item_quantity * self.item_price) # return '{} {} @ ${} = ${}' .format(self_item_name, self.item_quantity, self.item_price, print_item_cost) def print_item_cost(self): self.print_cost = (self.item_quantity * self.item_price) print(('{} {} @ ${} = ${}') .format(self.item_name, self.item_quantity, self.item_price,...

  • CIS4100 Final Project Description The Objective of this Final Project is to implement the theoretical concepts...

    CIS4100 Final Project Description The Objective of this Final Project is to implement the theoretical concepts covered in the course. You are required to build the classes and test all the functions as described. Each class should have its own .h (specification) and .cpp (implementation) files, then test all the classes in the main.cpp The Diagram below shows the classes inheritance relationships: The assigned Types are as follow: Type 1 Type 2 Type 3           PitBull Lion Tiger The class...

  • In Java plz due today Assignment 4 - Email, Shwitter and Inheritance Select one option from...

    In Java plz due today Assignment 4 - Email, Shwitter and Inheritance Select one option from below. All (both) options are worth the same number of points. The more advanced option(s) are provided for students who find the basic one too easy and want more of a challenge. OPTION A (Basic): Message, EMail and Tweet Understand the Classes and Problem Every message contains some content ("The British are coming! The British are coming!"). We could enhance this by adding other...

  • Please use Java only. Write the class TopResult, which keeps track of the best (highest numbered ...

    Please use Java only. Write the class TopResult, which keeps track of the best (highest numbered or highest ordered) result it has seen so far. The class will be a generic type, so the type of results it sees depends on how it is declared. TopResult Task: There are a number of situations in which we want to keep track of the highest value we've seen so far - a highest score, a most recent entry, a name which is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT