Skip to content

Commit

Permalink
created a basic view class for a Pygame window
Browse files Browse the repository at this point in the history
  • Loading branch information
paulruvolo committed Mar 2, 2018
1 parent 247ba70 commit 068b5d9
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion brick_breaker.py
Expand Up @@ -15,6 +15,27 @@
from pygame.locals import *
import time

class PyGameWindowView(object):
""" A view of brick breaker rendered in a Pygame window """
def __init__(self, model, size):
""" Initialize the view with a reference to the model and the
specified game screen dimensions (represented as a tuple
containing the width and height """
self.model = model
self.screen = pygame.display.set_mode(size)

def draw(self):
""" Draw the current game state to the screen """
self.screen.fill(pygame.Color(0,0,0))
for brick in self.model.bricks:
pygame.draw.rect(self.screen,
pygame.Color(255, 255, 255),
pygame.Rect(brick.x,
brick.y,
brick.width,
brick.height))
pygame.display.update()

class BrickBreakerModel(object):
""" Encodes a model of the game state """
def __init__(self):
Expand Down Expand Up @@ -47,16 +68,17 @@ def __str__(self):
pygame.init()

size = (640, 480)
screen = pygame.display.set_mode(size)

model = BrickBreakerModel()
print(model)
view = PyGameWindowView(model, size)

running = True
while running:
for event in pygame.event.get():
if event.type == QUIT:
running = False
view.draw()
time.sleep(.001)

pygame.quit()

0 comments on commit 068b5d9

Please sign in to comment.