commit 225f09c98f304820525a6701f1a8f44603e36f8a Author: Anna Wiggins Date: Sun Apr 8 01:06:10 2012 -0400 Initial commit - So far we can print the board. diff --git a/pygo.py b/pygo.py new file mode 100755 index 0000000..d60a32c --- /dev/null +++ b/pygo.py @@ -0,0 +1,139 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# A GTK Python GO client + +import os +import pygame +from pygame.locals import * + +def load_png(name): + """ Load image and return image object""" + fullname = os.path.join('res', name) + + try: + image = pygame.image.load(fullname) + if image.get_alpha() is None: + image = image.convert() + else: + image = image.convert_alpha() + + except pygame.error, message: + print 'Cannot load image:', fullname + raise SystemExit, message + + return image + + +def build_img_res(): + ret = {} + + ret['w'] = load_png('go_w.png') + ret['wT'] = load_png('go_wT.png') + ret['b'] = load_png('go_b.png') + ret['bT'] = load_png('go_bT.png') + + for d in ('u', 'd', 'l', 'r', 'm', 'dl', 'dr', 'ul', 'ur', 'h'): + ret[d] = load_png('go_' + d + '.png') + ret[d + 'c'] = load_png('go_' + d + 'c.png') + + return ret + + +class GobanSquare: + """A single square on the go board""" + + def __init__(self, pos): + self.x, self.y = pos + self.state = 'empty' + + if (self.x, self.y) == (1,1): + self.default_draw_code = 'ul' + elif (self.x, self.y) == (1,19): + self.default_draw_code = 'ur' + elif (self.x, self.y) == (19,1): + self.default_draw_code = 'dl' + elif (self.x, self.y) == (19,19): + self.default_draw_code = 'dr' + elif (self.x, self.y) in [(4,4), (4,16), (16,4), (16,16)]: + self.default_draw_code = 'h' + elif self.x == 1: + self.default_draw_code = 'u' + elif self.y == 1: + self.default_draw_code = 'l' + elif self.x == 19: + self.default_draw_code = 'd' + elif self.y == 19: + self.default_draw_code = 'r' + else: + self.default_draw_code = 'm' + + + def get_draw_code(self): + if self.state == 'empty': + return self.default_draw_code + if self.state == 'marked': + return self.default_draw_code + 'c' + if self.state == 'white': + return 'w' + if self.state == 'black': + return 'b' + + return None + + + +def draw_board(goban, size, img_res): + board = pygame.Surface((size,size)) + + inc = size / 19; + i = 0 + for row in goban: + j = 0 + for square in row: + s = pygame.transform.scale(img_res[square.get_draw_code()], (inc, inc)) + board.blit(s, (j*inc,i*inc)) + j += 1 + i += 1 + + return board.convert() + + +def main(): + # Basic screen init + pygame.init() + screen = pygame.display.set_mode((800, 800)) + pygame.display.set_caption('pyGo') + + # Create the background object, make it blank + background = pygame.Surface(screen.get_size()) + background = background.convert() + background.fill((250, 250, 250)) + + # Build the dict of image objects + img_res = build_img_res() + + # Build the 361 board sprites + goban = [] + for i in range(19): + goban.append([]) + for j in range(19): + goban[i].append(GobanSquare((i+1, j+1))) + + board = draw_board(goban, 800, img_res) + background.blit(board, (0,0)) + + screen.blit(background, (0, 0)) + pygame.display.flip() + + while True: + event = pygame.event.wait() + + if event.type == QUIT: + return + + screen.blit(background, (0,0)) + pygame.display.flip() + + +if __name__ == '__main__': main() diff --git a/readme.markdown b/readme.markdown new file mode 100644 index 0000000..b903a16 --- /dev/null +++ b/readme.markdown @@ -0,0 +1,8 @@ +## Installation + +### Dependencies + +You will need: + +pygame +SDL_ttf diff --git a/res/go_b.png b/res/go_b.png new file mode 100644 index 0000000..f73d1a6 Binary files /dev/null and b/res/go_b.png differ diff --git a/res/go_bT.png b/res/go_bT.png new file mode 100644 index 0000000..21be3c1 Binary files /dev/null and b/res/go_bT.png differ diff --git a/res/go_d.png b/res/go_d.png new file mode 100644 index 0000000..f14f6b1 Binary files /dev/null and b/res/go_d.png differ diff --git a/res/go_dc.png b/res/go_dc.png new file mode 100644 index 0000000..5b77365 Binary files /dev/null and b/res/go_dc.png differ diff --git a/res/go_dl.png b/res/go_dl.png new file mode 100644 index 0000000..ce5e48d Binary files /dev/null and b/res/go_dl.png differ diff --git a/res/go_dlc.png b/res/go_dlc.png new file mode 100644 index 0000000..46b5d61 Binary files /dev/null and b/res/go_dlc.png differ diff --git a/res/go_dr.png b/res/go_dr.png new file mode 100644 index 0000000..fd529dc Binary files /dev/null and b/res/go_dr.png differ diff --git a/res/go_drc.png b/res/go_drc.png new file mode 100644 index 0000000..8e28321 Binary files /dev/null and b/res/go_drc.png differ diff --git a/res/go_h.png b/res/go_h.png new file mode 100644 index 0000000..c50fc68 Binary files /dev/null and b/res/go_h.png differ diff --git a/res/go_hc.png b/res/go_hc.png new file mode 100644 index 0000000..d8c4f78 Binary files /dev/null and b/res/go_hc.png differ diff --git a/res/go_l.png b/res/go_l.png new file mode 100644 index 0000000..fb4ea55 Binary files /dev/null and b/res/go_l.png differ diff --git a/res/go_lc.png b/res/go_lc.png new file mode 100644 index 0000000..3beb63d Binary files /dev/null and b/res/go_lc.png differ diff --git a/res/go_m.png b/res/go_m.png new file mode 100644 index 0000000..fe89c9b Binary files /dev/null and b/res/go_m.png differ diff --git a/res/go_mc.png b/res/go_mc.png new file mode 100644 index 0000000..e5d884d Binary files /dev/null and b/res/go_mc.png differ diff --git a/res/go_r.png b/res/go_r.png new file mode 100644 index 0000000..0baa335 Binary files /dev/null and b/res/go_r.png differ diff --git a/res/go_rc.png b/res/go_rc.png new file mode 100644 index 0000000..a283d06 Binary files /dev/null and b/res/go_rc.png differ diff --git a/res/go_u.png b/res/go_u.png new file mode 100644 index 0000000..63b0101 Binary files /dev/null and b/res/go_u.png differ diff --git a/res/go_uc.png b/res/go_uc.png new file mode 100644 index 0000000..370dd88 Binary files /dev/null and b/res/go_uc.png differ diff --git a/res/go_ul.png b/res/go_ul.png new file mode 100644 index 0000000..51b9e03 Binary files /dev/null and b/res/go_ul.png differ diff --git a/res/go_ulc.png b/res/go_ulc.png new file mode 100644 index 0000000..bbdd9c6 Binary files /dev/null and b/res/go_ulc.png differ diff --git a/res/go_ur.png b/res/go_ur.png new file mode 100644 index 0000000..de238a1 Binary files /dev/null and b/res/go_ur.png differ diff --git a/res/go_urc.png b/res/go_urc.png new file mode 100644 index 0000000..e9847d0 Binary files /dev/null and b/res/go_urc.png differ diff --git a/res/go_w.png b/res/go_w.png new file mode 100644 index 0000000..9a3e7b0 Binary files /dev/null and b/res/go_w.png differ diff --git a/res/go_wT.png b/res/go_wT.png new file mode 100644 index 0000000..2f710e7 Binary files /dev/null and b/res/go_wT.png differ