Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 1: Weapons (6 marks) In order to survive in the Hungry Games, our tributes would need to be well versed with different weapons.

imageimageimageimage

Task 1: Weapons (6 marks) In order to survive in the Hungry Games, our tributes would need to be well versed with different weapons. In order to do so, we would need a magical spell from which we can create weapons of varying capabilities. a. Create a class, Weapon, inherited from the Thing class. The constructor should take in 3 parameters, the name of the weapon, min_dmg and max_dmg, which describes the damage capabilities of the weapon. Note that the name of the weapon is the type of the weapon in string, so multiple weapons may share the same name because they are of the same type. >>> sword = Weapon ("sword", 3, 10) >>> isinstance (sword, Weapon) True >>> isinstance (sword, Thing) True b. Implement the methods, min_damage () and max_damage(), which would return the minimum and maximum damage for a weapon respectively. >>> sword.min_damage () 3 >>> sword.max_damage () 10 c. Implement a method, damage (), which would return a value between min_dmg and max_dmg inclusive. HINT: You may use the random.randint(min, max) method to generate a random integer between min and max inclusive. >>> sword. damage () # Should return a value between 3 and 10 5 Task 2: Ammunition (4 marks) As melee weapons require the user to be up close before they can damage the enemy, being only skilled with melee weapons would expose our tributes to additional threats. It is thus important that we have ranged weapons. However, the biggest drawback of ranged weapons is that they require a supply of ammo in order to be effective. Sure, you can try and hit someone with your bow, but clearly that would not be very smart... In this task, we will model the ammunition with the Ammo class. a. Create a class Ammo, inherited from the Thing class. The constructor should take in 3 parameters, the name of the ammo, the weapon that this ammo is for, as well as the quantity of this ammo (which is the number of shots avaliable initially). CS1010A, Semester I, 2023/2024-Mission 12 3 b. Create a method get_quantity (), that would return the number of shots available in this ammo object. c. Create a method weapon_type(), that would return the name of the type of the weapon that this ammo is supposed to work with. Recall that a weapon's type is simply its name. Hence an ammo can work with different weapon objects as long as they share the same name. d. Create a method remove_all(), that would set the number of shots in the ammo to be 0. Task 3: Ranged Weapon (8 marks) Now that we have a way to create Ammo, it is now time to create a Ranged Weapon. The RangedWeapon class will be a subclass of the Weapon class. a. Create a class RangedWeapon, which inherits from the Weapon class. The constructor should take in 3 parameters, the name of the weapon, min_dmg and max_dmg, which describes the damage capabilities of the weapon. The RangedWeapon should have a property, shots, that keeps track of the current ammo supply. A newly created RangedWeapon start with 0 shots. Note that since the type of a weapon is simply its name, it is not unusual to have multiple weapons that share the same name. >>> bow = RangedWeapon ("bow", 1, 4) >>> isinstance (bow, RangedWeapon) True >>> isinstance (bow, Weapon) True b. Create a method shots_left(), that returns the ammo supply for the current ranged weapon. c. Create a method load(ammo), that would take in an Ammo object. If the ammo object is meant for the weapon, the shots count for the weapon would be increased by the ammo's quantity, and the ammo quantity will be reduced to 0 (Hint: you can use remove_all() to set the quantity of the Ammo to 0) However, if the ammo is of the wrong type, there is no effect on either the Ammo or the RangedWeapon. d. Override the damage () method for RangedWeapon such that it behaves in the following manner: (i) Returns 0 if the ranged weapon does not have any shots left (ii) Otherwise, decrease the number of shots left by 1, and returns a value between min_dmg and max_dmg inclusive. You should call its superclass's damage () method here.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Heres the implementation of the requested Weapon class python import random c... 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

Business Communication Essentials a skill based approach

Authors: Courtland L. Bovee, John V. Thill

6th edition

978-0132971324

More Books

Students also viewed these Programming questions

Question

What is parallel construction, and why is it important?

Answered: 1 week ago