Question: Using Python, create an actor model/module, including a control_actors_action.py file for the game Batter aka Brick Breaker: Here's what I have so far (I have
Using Python, create an actor model/module, including a control_actors_action.py file for the game "Batter" aka "Brick Breaker":

Here's what I have so far (I have the drawn objects, points, etc so far, just need to control how movement works for actors with a velocity greater than zero):
actor.py:
from game import constants
from game.point import Point
class Actor:
"""A visible, moveable thing that participates in the game. The
responsibility of Actor is to keep track of its appearance, position
and velocity in 2d space.
Stereotype:
Information Holder
Attributes:
_text (string): The textual representation of the actor.
_position (Point): The actor's position in 2d space.
_velocity (Point): The actor's speed and direction.
"""
def __init__(self):
"""The class constructor.
Args:
self (Actor): an instance of Actor.
"""
self._text = ""
self._position = Point(0, 0)
self._velocity = Point(0, 0)
def get_position(self):
"""Gets the actor's position in 2d space.
Args:
self (Actor): an instance of Actor.
Returns:
Point: The actor's position in 2d space.
"""
return self._position
def get_text(self):
"""Gets the actor's textual representation.
Args:
self (Actor): an instance of Actor.
Returns:
string: The actor's textual representation.
"""
return self._text
def get_velocity(self):
"""Gets the actor's speed and direction.
Args:
self (Actor): an instance of Actor.
Returns:
Point: The actor's speed and direction.
"""
return self._velocity
def move_next(self):
"""Moves the actor to its next position according to its velocity. Will
wrap the position from one side of the screen to the other when it
reaches the boundary in either direction.
Args:
self (Actor): an instance of Actor.
"""
def set_position(self, position):
"""Updates the actor's position to the given one.
Args:
self (Actor): An instance of Actor.
position (Point): The given position.
"""
self._position = position
def set_text(self, text):
"""Updates the actor's text to the given value.
Args:
self (Actor): An instance of Actor.
text (string): The given value.
"""
self._text = text
def set_velocity(self, velocity):
"""Updates the actor's velocity to the given one.
Args:
self (Actor): An instance of Actor.
position (Point): The given velocity.
"""
self._velocity = velocity
move_actors_action.py:
from game import constants
from game.action import Action
from game.point import Point
class MoveActorsAction(Action):
"""A code template for moving actors. The responsibility of this class of
objects is move any actor that has a velocity more than zero.
Stereotype:
Controller
Attributes:
_input_service (InputService): An instance of InputService.
"""
def execute(self, cast):
"""Executes the action using the given actors.
Args:
cast (dict): The game actors {key: tag, value: list}.
"""
for group in cast.values():
for actor in group:
if not actor.get_velocity().is_zero():
self._move_actor(actor)
def _move_actor(self, actor):
"""Moves the given actor to its next position according to its
velocity. Will wrap the position from one side of the screen to the
other when it reaches the edge in either direction.
Args:
actor (Actor): The actor to move.
"""
position = actor.get_position()
velocity = actor.get_velocity()
x1 = position.get_x()
y1 = position.get_y()
x2 = velocity.get_x()
y2 = velocity.get_y()
x = 1 + (x1 + x2 - 1) % (constants.MAX_X - 1)
y = 1 + (y1 + y2 - 1) % (constants.MAX_Y - 1)
position = Point(x, y)
actor.set_position(position)
Thanks in advance!
Overview Batter is a game in which the player seeks to bat the ball back towards the top of the screen to break the bricks. Miss the ball and its game over! Rules Batter is played according to the following rules. 1. The bricks are arranged in 4 rows and 70 columns at the top of the screen. 2. The bat (or paddle) is positioned near the bottom of the screen. 3. The player can move the bat left or right within the boundaries of the screen. 4. The ball moves of its own accord, bouncing off the bat, bricks and walls. 5. If the bat misses the ball the game is over. Interface *********** ***** ******************************************************* ****************** ************************************************************ ************* ************************* ************** Overview Batter is a game in which the player seeks to bat the ball back towards the top of the screen to break the bricks. Miss the ball and its game over! Rules Batter is played according to the following rules. 1. The bricks are arranged in 4 rows and 70 columns at the top of the screen. 2. The bat (or paddle) is positioned near the bottom of the screen. 3. The player can move the bat left or right within the boundaries of the screen. 4. The ball moves of its own accord, bouncing off the bat, bricks and walls. 5. If the bat misses the ball the game is over. Interface *********** ***** ******************************************************* ****************** ************************************************************ ************* ************************* **************
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
