Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajw #21

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open

Ajw #21

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0d483ff
added files
awarbler Nov 3, 2021
0e23ee0
added files from rfk
awarbler Nov 3, 2021
13a5a39
upload action
awarbler Nov 3, 2021
b9c29bb
updated files
awarbler Nov 3, 2021
2d1b606
changed constants.py
Nov 3, 2021
52217ec
adding actor
awarbler Nov 3, 2021
d83033b
Merge branch 'master' of https://github.com/awarbler/cse210-student-b…
awarbler Nov 3, 2021
5c041c5
Updating Imported Code
Nov 3, 2021
d1e7232
add handle
awarbler Nov 3, 2021
eb08160
game runs i guess
Nov 3, 2021
b9d4393
Merge branch 'master' of https://github.com/awarbler/cse210-student-b…
Nov 3, 2021
1a80d53
handle collision test
Nov 3, 2021
88dc8bf
heres what i got
Nov 3, 2021
7bea02e
updated handle
awarbler Nov 4, 2021
27a9f91
updated
awarbler Nov 4, 2021
b386b86
added ball boundries and handle boundaries
awarbler Nov 5, 2021
f91e8c2
accident changed
awarbler Nov 5, 2021
0068d7f
changed keeps game working
awarbler Nov 5, 2021
b37ad17
cast
awarbler Nov 5, 2021
4e549ae
fixed number
awarbler Nov 5, 2021
d10e244
fixed name handle
awarbler Nov 6, 2021
9310007
handle
awarbler Nov 6, 2021
7ded095
branch
awarbler Nov 6, 2021
56fc263
master
awarbler Nov 6, 2021
edd5a56
border and brick collision updates
zrobker Nov 6, 2021
fdc2ae5
Merge branch 'master' into Zachs-Branch
awarbler Nov 6, 2021
fc29e82
Merge pull request #1 from awarbler/Zachs-Branch
awarbler Nov 6, 2021
8dd2926
clean up
awarbler Nov 6, 2021
43b2f02
Fixed Paddle Ball Colission
Nov 6, 2021
fd9dfae
added comments
awarbler Nov 6, 2021
3a6a113
added comments to point.py
awarbler Nov 6, 2021
6fa965c
added comments
awarbler Nov 6, 2021
fb4b3e5
updating comments ajw
awarbler Nov 6, 2021
38ddc1c
updating points
awarbler Nov 6, 2021
fd4e53c
Merge branch 'master' into ajw
awarbler Nov 6, 2021
bbb4fee
updated readme file
awarbler Nov 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ root (project root folder)
## Authors
---
* # TODO: Add your names and emails here
anita Woodford awoodfor@byui
Lazaro Felizardo Matola [email protected]
Xander Newlun [email protected]
Zach Robker [email protected]
18 changes: 18 additions & 0 deletions batter/game/action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Action:
"""A code template for a thing done in a game. The responsibility of
this class of objects is to interact with actors to change the state of the game.

Stereotype:
Controller

Attributes:
_tag (string): The action tag (input, update or output).
"""

def execute(self, cast):
"""Executes the action using the given actors.

Args:
cast (dict): The game actors {key: tag, value: list}.
"""
raise NotImplementedError("execute not implemented in superclass")
90 changes: 90 additions & 0 deletions batter/game/actor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
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:
_tag (string): The actor's tag.
_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."""
self._description = ""
self._text = ""
self._tag = ""
self._position = Point(0, 0)
self._velocity = Point(0, 0)

def get_description(self):
"""Gets the artifact's description.

Returns:
string: The artifact's description.
"""
return self._description

def get_position(self):
"""Gets the actor's position in 2d space.

Returns:
Point: The actor's position in 2d space.
"""
return self._position

def get_text(self):
"""Gets the actor's textual representation.

Returns:
string: The actor's textual representation.
"""
return self._text

def get_velocity(self):
"""Gets the actor's speed and direction.

Returns:
Point: The actor's speed and direction.
"""
return self._velocity

def set_description(self, description):
"""Updates the actor's description to the given one.

Args:
description (string): The given description.
"""
self._description = description

def set_position(self, position):
"""Updates the actor's position to the given one.

Args:
position (Point): The given position.
"""
self._position = position

def set_text(self, text):
"""Updates the actor's text to the given value.

Args:
text (string): The given value.
"""
self._text = text

def set_velocity(self, velocity):
"""Updates the actor's velocity to the given one.

Args:
position (Point): The given velocity.
"""
self._velocity = velocity
def set_tag(self, tag):
self._tag = tag
7 changes: 7 additions & 0 deletions batter/game/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os

MAX_X = 80
MAX_Y = 20
FRAME_LENGTH = 0.1
PATH = os.path.dirname(os.path.abspath(__file__))
ARTIFACTS = 30
31 changes: 31 additions & 0 deletions batter/game/control_actors_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from game import constants
from game.action import Action

class ControlActorsAction(Action):
"""A code template for controlling actors. The responsibility of this
class of objects is translate user input into some kind of intent.

Stereotype:
Controller

Attributes:
_input_service (InputService): An instance of InputService.
"""

def __init__(self, input_service):
"""The class constructor.

Args:
input_service (InputService): An instance of InputService.
"""
self._input_service = input_service

def execute(self, cast):
"""Executes the action using the given actors.

Args:
cast (dict): The game actors {key: tag, value: list}.
"""
direction = self._input_service.get_direction()
paddle = cast["paddle"][0] # there's only one in the cast
paddle.set_velocity(direction)
41 changes: 41 additions & 0 deletions batter/game/director.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from time import sleep
from game import constants

class Director:
"""A code template for a person who directs the game. The responsibility of
this class of objects is to control the sequence of play.

Stereotype:
Controller

Attributes:
_cast (dictionary): The game actors {key: name, value: object}
_script (dictionary): The game actions {key: tag, value: object}
"""

def __init__(self, cast, script):
"""The class constructor.

Args:
cast (dict): The game actors {key: tag, value: list}.
script (dict): The game actions {key: tag, value: list}.
"""
self._cast = cast
self._script = script

def start_game(self):
"""Starts the game loop to control the sequence of play."""
while True:
self._cue_action("input")
self._cue_action("update")
self._cue_action("output")
sleep(constants.FRAME_LENGTH)

def _cue_action(self, tag):
"""Executes the actions with the given tag.

Args:
tag (string): The given tag.
"""
for action in self._script[tag]:
action.execute(self._cast)
31 changes: 31 additions & 0 deletions batter/game/draw_actors_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from game.action import Action

class DrawActorsAction(Action):
"""A code template for drawing actors. The responsibility of this class of
objects is use an output service to draw all actors on the screen.

Stereotype:
Controller

Attributes:
_output_service (OutputService): An instance of OutputService.
"""

def __init__(self, output_service):
"""The class constructor.

Args:
output_service (OutputService): An instance of OutputService.
"""
self._output_service = output_service

def execute(self, cast):
"""Executes the action using the given actors.

Args:
cast (dict): The game actors {key: tag, value: list}.
"""
self._output_service.clear_screen()
for group in cast.values():
self._output_service.draw_actors(group)
self._output_service.flush_buffer()
112 changes: 112 additions & 0 deletions batter/game/handle_collisions_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import sys
import random
import sys
from game import constants
from game.action import Action
from game.point import Point

class HandleCollisionsAction(Action):
"""A code template for handling collisions. The responsibility
of this class of objects is to update the game state when actors collide.

Stereotype:
Controller
"""

def execute(self, cast):
"""Executes the action using the given actors.
Args:
cast (dict): The game actors {key: tag, value: list}.
"""
self.ball_brick_collision(cast)
self.ball_paddle_collision(cast)
self.ball_ceiling_collision(cast)
self.ball_floor_collision(cast)
self.ball_wall_collision(cast)
self.paddle_boundaries(cast)


def ball_brick_collision(self, cast):
"""The responsibility of this class of objects is to update
the game state when actors collide specifically ball to brick collision
Arg:
bricks cast[bricks]
ball cast[ball]
"""
bricks = cast["brick"]
ball = cast["ball"][0]# bball brick collision get ball position equal brick get position
for brick in bricks:
if ball.get_position().equals(brick.get_position()):
cast["brick"].remove(brick)
velocity = ball.get_velocity()
ball.set_velocity(velocity.reverse_y())

def ball_paddle_collision(self,cast):
"""The responsibility of this class of objects is to update
the game state when actors collide specifically ball to paddle collision
"""

paddle = cast["paddle"][0]
ball = cast["ball"][0]# bball brick collision get ball position equal brick get position

paddle_x_position = paddle.get_position().get_x()
paddle_y_position = paddle.get_position().get_y()
ball_x_position = ball.get_position().get_x()
ball_y_position = ball.get_position().get_y()

if (ball_y_position == paddle_y_position +2
and ball_x_position >= paddle_x_position
and ball_x_position <= paddle_x_position + len(paddle.get_text())):
velocity = ball.get_velocity()
ball.set_velocity(velocity.reverse_y())
pass
def ball_wall_collision(self, cast):
"""The responsibility of this class of objects is to update
the game state when actors collide specifically ball to wall collision
"""
ball = cast["ball"][0]
position = ball.get_position()
ball_x = position.get_x()
if ball_x >= constants.MAX_X or ball_x <= 0:
velocity = ball.get_velocity()
ball.set_velocity(velocity.reverse_x())

def ball_floor_collision(self,cast):
"""The responsibility of this class of objects is to update
the game state when actors collide specifically ball to floor collision
"""
ball = cast["ball"][0]
position = ball.get_position()
ball_y = position.get_y()
if ball_y >= constants.MAX_Y +2: # - 1 to test but +2 to run game
sys.exit()

def ball_ceiling_collision(self, cast):
"""The responsibility of this class of objects is to update
the game state when actors collide specifically ball to ceiling collision
"""

ball = cast["ball"][0]
position = ball.get_position()
ball_y = position.get_y()
if ball_y == 0:
velocity = ball.get_velocity()
ball.set_velocity(velocity.reverse_y())

def paddle_boundaries(self,cast):
"""The responsibility of this class of objects is to update
the game state when actors collide specifically paddle to wall
"""
paddle = cast["paddle"][0]
position = paddle.get_position()
paddle_x = position.get_x()
paddle_y = position.get_y()
if paddle_x + len(paddle.get_text()) >= constants.MAX_X:
velocity = paddle.get_velocity()
paddle.set_velocity(Point(0,0))
paddle.set_position(Point(paddle_x-3,paddle_y))
elif paddle_x <= 0:
paddle.set_velocity(Point(0,0))
paddle.set_position(Point(paddle_x+3,paddle_y))


38 changes: 38 additions & 0 deletions batter/game/input_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import sys
from game.point import Point
from asciimatics.event import KeyboardEvent

class InputService:
"""Detects player input. The responsibility of the class
of objects is to detect and communicate player keypresses.

Stereotype:
Service Provider

Attributes:
_screen (Screen): An Asciimatics screen.
_keys (list): Points for up, dn, lt, rt.
"""

def __init__(self, screen):
"""The class constructor."""
self._screen = screen
self._keys = {}
# self._keys[119] = Point(0, -1) # w
# self._keys[115] = Point(0, 1) # s
self._keys[97] = Point(-1, 0) # a
self._keys[100] = Point(1, 0) # d

def get_direction(self):
"""Gets the selected direction for the given player.

Returns:
Point: The selected direction.
"""
direction = Point(0, 0)
event = self._screen.get_event()
if isinstance(event, KeyboardEvent):
if event.key_code == 27:
sys.exit()
direction = self._keys.get(event.key_code, Point(0, 0))
return direction
Loading