Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using python 3 Create a file called enemy.py. Inside of this file will be a class called Enemy This class should have one class variable

using python 3 image text in transcribed
Create a file called "enemy.py". Inside of this file will be a class called "Enemy" This class should have one class variable called "startHealth". Remember that class variables are different from instance variables. Set the value of startHealth to 5_000 (remember that an underscore in a number is used for digit separation to make a number easier to read by yourself and other developers) This class should have two instance variables called "health" and "defense". Create a constructor for this class that has two parameters, the mandatory "self" parameter and a parameter called "defense". Set the instance variable defense to the value in the parameter defense and set the health instance variable to the value held by the startHealth class variable. Do not add anything to the constructor that is unnecessary. Turn the defense instance variable into a property. Do NOT turn the health variable into a property. The defense accessor should just return the _defense value but the mutator is going to do something unique. Whatever value is given to the mutator, we need to take the factorial of that value and set _defense to that result. For example, if the mutator is called with a value of 5, the actual value set to _defense should be 120 (which is 5! (i.e.5*4*3*2*1). You will need to calculate the factorial of the value you are given and set the _defense to that. Create a function inside of the Enemy class called "takeDamage". This function should take in a parameter called "amount". The purpose of this function is to reduce the health of the enemy by the quotient of the amount and the enemy's defense. In other words, take the parameter amount, divide it by the enemy's defense and subtract that much from the enemy's health. No value is returned from this function Create a function inside of the Enemy class called "isDead". This function should examine the enemy's health and return true if the health is less than or equal to zero, or false otherwise. Finally, create a function inside of the Enemy class called "getimageName". This function should take in a string and a number. If the number is divisible by 2 append the word "hit" to the string parameter, otherwise append the word "normal" to the string parameter. Return the resulting string parameter

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

AutoCAD Database Connectivity

Authors: Scott McFarlane

1st Edition

0766816400, 978-0766816404

More Books

Students also viewed these Databases questions

Question

1. Define and explain culture and its impact on your communication

Answered: 1 week ago