Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using IDLE define a Python Character class that represents a game character type, which is not specific to any particular character, but represents the general

Using IDLE define a Python Character class that represents a game character type, which is not specific to any particular character, but represents the general actions and attributes of any character within the game.

Then, define another Python class that inherits that Character class and represents a more specific type of character, but still a character.

Finally, demonstrate using the subclass by creating objects of the subclass type and calling all functions from those objects.

Write the definition for the Character class (the superclass)

(a) Define a constructor function with no required formal parameters (put self 1st in the parameter list for all class functions)

(b) In the body block of the constructor function, declare all class data variables.

First, declare and initialize a class data variable for the name of the character. The name will be a string.

(c) Declare and initialize another class data variable

Initialize its value to 1

1 will mean the character is alive, 0 not alive

(d) Declare/initialize another class data variable for the good or evil nature of the character.

Initialize it to an empty string (a general character is neither good nor evil. The subclass will set the value when objects are created).

It will be used to hold the string value 'good' or 'evil'

(e) Declare a class function named action with statements that print out the character's name.

2. Write another class definition for a specific type of character.

This subclass will inherit from the Character class

Name the class according to your own choice of character.

Define the variables and functions as described below

Suppose for this writeup we call the subclass Fighter.

(a) Define a constructor function.

Include a parameter to carry the value for the name variable and the 2nd parameter to carry a

value for the goodness variable.

Include a call to the superclass constructor to ensure the inherited data variables are created.

Set the value of the name and goodness variables.

Call a function to print a message about whether the subclass object is good or evil.

(b) Declare another numeric class data variable and initialize it to 0 (don't forget the 'self')

Use it as a counter variable to track the number of times something occurs.

Suppose for this writeup we call the variable mycounter

(c) Define a function named action with the same header line as the one in the Character class

This means it will override the one inherited from the Character class.

Make its statements do something of your choice, more specific than the superclass version,

matching the subclass type.

The statements in its body block do the following:

i. print out information to simulate the subclass character taking some kind of action.

Include the name of the character in the printouts

ii. track the number of times the action is taken

do this by increasing the value of a counter class variable.

iii. print out the action counter value with an informative message.

Outside your class definitions, demonstrate using the capabilities of your defined classes by writing code to do the following:

Call the constructor function of your subclass to create two objects of your subclass type.

Call all functions of each of these two objects.

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

OCA Oracle Database SQL Exam Guide Exam 1Z0-071

Authors: Steve O'Hearn

1st Edition

1259585492, 978-1259585494

More Books

Students also viewed these Databases questions

Question

Explain the different types of marketing strategies.

Answered: 1 week ago

Question

Explain product positioning.

Answered: 1 week ago

Question

Explain Industrial market segment.

Answered: 1 week ago

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago