Added text to display number of captures and whose turn it is.

This commit is contained in:
Anna Rose 2012-04-08 18:24:14 -04:00
parent 8881b1cd38
commit f5d3608ba2

27
pygo.py
View File

@ -150,7 +150,7 @@ class Goban:
continue
if not self._has_liberties(p, who):
captures[self.turn] += self._delete_group(p)
self.captures[self.turn] += self._delete_group(p)
def _valid_move(self, pos):
@ -278,6 +278,25 @@ class Goban:
return ret.convert()
def draw_info(self):
textbox = pygame.Surface((150, 300))
textbox = textbox.convert()
textbox.fill((250, 250, 250))
font = pygame.font.Font(None, 24)
heading = font.render('Captures', 1, (10, 10, 10))
black_cap = font.render('Black: {}'.format(self.captures[0]), 1, (10, 10, 10))
white_cap = font.render('White: {}'.format(self.captures[1]), 1, (10, 10, 10))
turn = font.render('Turn: {}'.format(['Black', 'White'][self.turn]), 1, (10, 10, 10))
textbox.blit(heading, (0, 0))
textbox.blit(black_cap, (0, 28))
textbox.blit(white_cap, (0, 56))
textbox.blit(turn, (0, 100))
return textbox
def main():
# Basic screen init
@ -300,6 +319,9 @@ def main():
board = goban.draw_board(board_size, img_res)
background.blit(board, (0,0))
text = goban.draw_info()
background.blit(text, (815, 25))
screen.blit(background, (0, 0))
pygame.display.flip()
@ -323,6 +345,9 @@ def main():
board = goban.draw_board(board_size, img_res)
background.blit(board, (0,0))
text = goban.draw_info()
background.blit(text, (815, 25))
screen.blit(background, (0, 0))
pygame.display.flip()