Python programming

profileBellasss

I need help to write this following code in python.

1. DynamicEntity (class) - Inherits from Entity
DynamicEntity is an abstract class which provides base functionality for special types of Entities that are dynamic (e.g. can move from their original position).

set_position(self, new_position: tuple[int, int]) -> None

Updates the DynamicEntity’s position to new_position, assuming it is a valid position.

Examples
>>> dynamic_entity = DynamicEntity((1, 1))
>>> dynamic_entity.get_position()
(1, 1)
>>> dynamic_entity.set_position((2, 3))
>>> dynamic_entity.get_position()
(2, 3)
>>> dynamic_entity.get_id()
'DE'
>>> str(dynamic_entity)
'DE'
>>> dynamic_entity
DynamicEntity((2, 3))

2. Item - Inherits from Entity
Subclass of Entity which provides base functionality for all items in the game.
apply(self, player: Player) -> None
Applies the items effect, if any, to the given player.

Examples
>>> player = Player((2, 3))
>>> item = Item((4, 5))
>>> item.apply(player)
Traceback (most recent call last):
...
NotImplementedError
>>> item.get_position()
(4, 5)
>>> item.get_name()
'Item'
>>> item.get_id()
'I'
>>> str(item)
'I'
>>> item
Item((4, 5))

The Entity class example

Examples
>>> entity = Entity((2, 3))
>>> entity.get_position()
(2, 3)
>>> entity.get_name()
'Entity'
>>> entity.get_id()
'E'
>>> str(entity)
'E'
>>> entity
Entity((2, 3))

    • 2 years ago
    • 15
    Answer(0)