-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathView.py
More file actions
63 lines (53 loc) · 2.54 KB
/
Copy pathView.py
File metadata and controls
63 lines (53 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""This is the view class which is being imported to main.py"""
import pygame
from pygame.locals import *
import random
import math
import time
import numpy as np
import copy
class PyGameWindowView(object):
""" A view of brick breaker rendered in a Pygame window """
def __init__(self,model,screen):
""" Initialize the view with a reference to the model and the screen
to use for rendering the view """
self.model = model
self.screen = screen
def print_current_info(self):
for player in self.model.players:
print "-----------------"
print player.name.upper()
print player.name + "'s score:", player.score
print player.name + "'s total time:", player.clock
def draw_tile(self,tile,x,y):
square = pygame.draw.rect(self.screen,pygame.Color(0,0,0),pygame.Rect(x,y,37,37))
self.screen.blit(tile.image,square)
def draw(self):
""" Draw the current game state to the screen """
self.screen.fill(pygame.Color(0,0,0))
self.model.current_player.inventory.define_coordinates(self.model)
if self.model.letter_chosen:
pygame.draw.rect(self.screen, (0,255,0), (self.model.letter_chosen.x-1, self.model.letter_chosen.y-1, 40, 40))
for block in self.model.blocks:
#draw each of the blank blocks in the 15 by 15 game board
pygame.draw.rect(self.screen,
pygame.Color(block.color[0],block.color[1],block.color[2]),
pygame.Rect(block.x,block.y,block.width,block.height))
pygame.draw.rect(self.screen,
pygame.Color(204,255,230),
pygame.Rect(280,280,37,37))
square = pygame.draw.rect(self.screen,pygame.Color(0,0,0),pygame.Rect(280,280,37,37))
self.screen.blit(pygame.image.load('letter_tiles/middle_star.png'),square)
for tile in self.model.current_player.inventory.letters_inhand:
#draw each of the actual letters that are in hand
self.draw_tile(tile,tile.x, tile.y)
for row in self.model.proposed_board:
for item in row:
if item:
self.draw_tile(item, item.x, item.y)
if pygame.font:
font = pygame.font.Font(None,26)
text = font.render(" Player %s's turn" % self.model.current_player.name, 1, (255,255,255))
textpos = text.get_rect(centerx=300,centery=620)
self.screen.blit(text,textpos)
pygame.display.update()