From f5d3608ba256ee71503eb2278ef36092a7c92f85 Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Sun, 8 Apr 2012 18:24:14 -0400 Subject: [PATCH] Added text to display number of captures and whose turn it is. --- pygo.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/pygo.py b/pygo.py index 4fa6391..60047ab 100755 --- a/pygo.py +++ b/pygo.py @@ -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()