Question: class ShootingGame: def _ _ init _ _ ( self , target _ distance, target _ height ) : self.target _ distance = target _
class ShootingGame:
def initself targetdistance, targetheight:
self.targetdistance targetdistance
self.targetheight targetheight
def calculatetrajectoryself x angle, velocity:
# Calculate the trajectory of the shot
# Given xcoordinate, Return ycoordinate
# Step : Calculate the time of flight to reach xcoordinate
# Equation: t x velocity cosangle
# Step : Calculate the ycoordinate
# Equation: y velocity sinangle timeofflight g t
return y
def checkhittargetself angle, velocity, tolerance:
# Check if the shot hits the target
# Given tolerance, Return True or False
# Step : Calculate the ycoordinate of the shot at the target distance
# Equation: y self.calculatetrajectoryselftargetdistance, angle,
velocity
# use 'self' to access other attributes and methods inside the class
# Step : Check if the ycoordinate is within the tolerance of the target
height
# Equation: absy targetheight tolerance
return bool
def checkscoreself:
# Assign score based on whether the shot hits the target
# and the gamespecific scoring rules
pass
class BasketballShootingGame: # Basketball inherits from ShootingGame
def initself targetdistance, targetheight:
superinittargetdistance, targetheight
def checkscoreself angle, velocity, distance, tolerance: # Override
the checkscore method
Assign score based on whether the shot hits the target and the basketball
scoring rules
Input arguments:
angle shooting angle
velocity shooting velocity
distance shooting distance from the basket, a player can shoot from any
distance
tolerance tolerance for hitting the target, default value is
scoring rules:
If the shot hits the target within the tolerance and the distance is
less than meters, score
If the shot hits the target within the tolerance and the distance is
greater than or equal to meters, score
Otherwise, score
# update self.targetdistance to distance selftargetdistance
distance
# if checkhittargettolerance True and distance : score
# if checkhittargettolerance True and distance : score
# else: score
return score
class ArcheryShootingGame:
def initself targetdistance, targetheight:
superinittargetdistance, targetheight
def checkscoreself angle, velocity, tolerance:
Assign score based on whether the shot hits the target and the archery
scoring rules
Input arguments:
angle shooting angle
velocity shooting velocity
tolerance radius of the physical target
scoring rules:
the target is a circle with radius meter and is divided into
scoring zones from center to outer ring
If the shot hits center ring radius score
If the shot hits the second ring radius score
If the shot hits the third ring radius score
Otherwise, score
# if checkhittarget True: score
# if checkhittarget True: score
# if checkhittarget True: score
# else: score
return score
# Create objects for the games
# basketball game: targetdistance targetrelativeheight
# archery game: targetdistance targetrelativeheight
basketballgame Basketball
archerygame Archery
# Check the score of the shots
For basketball game: check the score of the following shots:
angle velocity, distance
basketballgame.checkscoreangle velocity, distance
For archery game: check the score of the following shots:
angle velocity
archerygame.checkscoreangle velocity
# Create another class for players to interact with the game and keep track of
their scores
class Player:
def initself name:
self.name name
self.score
def playgameself game, args:
Play the game and update the player's score
Input arguments:
game the game object eg basketballgame, archerygame
args passing multiple arguments based on the game
for basketball game: angle velocity, distance
for archery game: angle velocity
# Step : Check the score of the shot
# score game.checkscoreargs
# Step : Update the player's score
# self.score score
def showscoreself:
# Display the player's score
return 'Total Score: strselfscore
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
