CS172 - Lab4.docx - 10.1 CS 172 Lab 4 Monster Battle In...

This preview shows page 1 - 3 out of 12 pages.

10.1 CS 172 - Lab 4 Monster Battle In this lab we will create a battle game. Two objects that inherit from an abstract Monster class will fight. Provided Code You are provided with two files. Study each file before creating your own classes. monster.py - This contains an abstract base class, Monster that can be derived from in order to have character participate in the game. Ultimately you will also put your derived class in this module. main.py - The main program. This program allows two monsters to battle and determines the winner. The Classes Your first task is to create a CustomMonster class that derives from a provided abstract Monster class. You will NOT change the code in Monster Class. You will change the code in the CustomMonster Class. Let's first look at the structure now. The CustomMonster Class: The CustomMonster class is a class that inherits from a pure abstract class which is the Monster class(all of its methods are abstract and generic) Below are the methods required to be implemented in your CustomMonster class. (In ZyBooks you will see the TODO statements as well) Let's take a look at the attributes in your CustomMonster class. self.__name : This attribute is the name of the monster. self.__maximumHealth : This attribute is the maximum health of the monster. self.__health :This attribute is the current health of the monster. self.__description: This attribute is the description of the monster. self.__basicAttackDamage : This attribute is the damage(int) that this monster deals to the other monster during its basic attack. self.__specialAttackDamage: This attribute is the damage(int) that this monster deals to the other monster during its special attack. self.__defenseDamage : This attribute is the damage(int) that this monster deals to the other monster during its defense. self.__basicAttackName : This attribute is the name of its basic attack.(str) self.__specialAttackName: This attribute is the name of its basic attack.(str) self.__basicDefenseName : This attribute is the name of its basic attack.(str) Let's take a look at the methods in your CustomMonster class. Constructor:
def __init__(self,n, health=100, description = 'Fast and Furious Fur Ball', basicAttackDamage=7, specialAttackDamage=10, defenseDamage=1, basicAttackName='scratch', specialAttackName='special scratch', basicDefenseName='duck') : The parameters of this constructor method are described as follows (with their type in parenthesis): Explanation of each parameter in your init : n (str) is the name health (int) is the starting health of the monster. This constructor input needs to be used to define the maximum health of the monster. You also need to find a way to keep track of the current health of the monster after each attack/defense. If this is confusing, think of it this way, there needs to be two attributes in your custom monster class, one for the current health of the monster, one for the maximum health of the monster and initially current health is equal to the maximum health which is equal to the health that was passed as input to constructor.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture