Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Advanced level school Python programming. need helps A programmer is writing a program to implement a role-playing computer game using ObjectOriented Programming (OOP). The players

image text in transcribed

image text in transcribed

image text in transcribed

Advanced level school Python programming. need helps

A programmer is writing a program to implement a role-playing computer game using ObjectOriented Programming (OOP). The players have to collect Food items. A Food item has the following attributes: - name : STRING - value : INTEGER and the following methods: - get_name ( ) - get_value ( ) A player takes on the role of a Person. A Person has the following attributes: - name : STRING - health : INTEGER which is initialised at a value of 100 - strength : INTEGER which is initialised at a value of 100 and the following methods: - get_name ( ) - get_health() - get_strength ( ) - eat (Food) adds the value of the Food to the strength. The code should display the new strength of the player. - attack (opponent) where opponent is another Person. For the attack method: - A random integer r between 1 and 10 (inclusive) is generated. - If the strength of the player is less than r, then the player does not have enough strength to attack and there is no change to the health of the opponent. - If the strength of the player is at least r, then the attack is successful and the health of the opponent is decreased by r. - If the health of the opponent is now negative, then the opponent has been defeated. - The strength of the player is decreased by r. The are two sub-classes of the Person class - Healer and Warrior. The Healer sub-class has one additional method: - heal (patient) where patient is another Person. For the heal method: - A random integer r between 1 and 10 (inclusive) is generated. - If the strength of the player is less than r, then the player does not have enough strength to heal and there is no change to the health of the patient. - If the strength of the player is at least r, then the healing is successful and the health of the patient is increased by r, up to a maximum of 100 . The attack method for a Warrior is twice as effective. This means that if the player has enough strength to attack, the health of the opponent is decreased by 2r, while the strength of the player is decreased by r. Task 2.1 Write program code to define the class Food. Task 2.2 Write program code to define the class Person. The code should display appropriate messages about the outcome of attack, including the new value of the health of the opponent. Task 2.3 Use appropriate inheritance to write program code to define the class Healer. The code should display appropriate messages about the outcome of heal, including the new value of the health of the patient. Task 2.4 Use appropriate inheritance and polymorphism to write program code to define the class Warrior. Test your code with the following steps in order: - Create a Food item with name 'Cheese' and value 10. - Create a Warrior with name 'Sam'. - Create a Healer with name 'Alex'. - Create a Person with name 'Jan'. - 'Jan' attacks 'Sam'. - 'Sam' attacks 'Jan'. - 'Alex' heals 'Jan'. - 'Sam' eats 'Cheese

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

Microsoft Visual Basic 2005 For Windows Mobile Web Office And Database Applications Comprehensive

Authors: Gary B. Shelly, Thomas J. Cashman, Corinne Hoisington

1st Edition

0619254823, 978-0619254827

More Books

Students also viewed these Databases questions

Question

Define the term budget. How are budgets used in planning?

Answered: 1 week ago