Initial commit - So far we can print the board.

This commit is contained in:
Anna Rose 2012-04-08 01:06:10 -04:00
commit 225f09c98f
26 changed files with 147 additions and 0 deletions

139
pygo.py Executable file
View File

@ -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()

8
readme.markdown Normal file
View File

@ -0,0 +1,8 @@
## Installation
### Dependencies
You will need:
pygame
SDL_ttf

BIN
res/go_b.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

BIN
res/go_bT.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

BIN
res/go_d.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 656 B

BIN
res/go_dc.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

BIN
res/go_dl.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
res/go_dlc.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
res/go_dr.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
res/go_drc.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

BIN
res/go_h.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 818 B

BIN
res/go_hc.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

BIN
res/go_l.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 666 B

BIN
res/go_lc.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
res/go_m.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 B

BIN
res/go_mc.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
res/go_r.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 665 B

BIN
res/go_rc.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
res/go_u.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 656 B

BIN
res/go_uc.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
res/go_ul.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 921 B

BIN
res/go_ulc.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
res/go_ur.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
res/go_urc.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
res/go_w.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

BIN
res/go_wT.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB