See previous commit...
This commit is contained in:
11
lib/config.py
Normal file
11
lib/config.py
Normal file
@ -0,0 +1,11 @@
|
||||
import ConfigParser
|
||||
|
||||
def init():
|
||||
global config
|
||||
config = read_config_file()
|
||||
|
||||
|
||||
def read_config_file():
|
||||
ret = ConfigParser.ConfigParser()
|
||||
ret.read('pygo.cfg')
|
||||
return ret
|
106
lib/goban.py
106
lib/goban.py
@ -1,7 +1,3 @@
|
||||
import pygame
|
||||
from pygame.locals import *
|
||||
|
||||
|
||||
class Goban:
|
||||
"""Represents the go board. Handles stone placement, captures, etc"""
|
||||
|
||||
@ -263,71 +259,71 @@ class Goban:
|
||||
|
||||
|
||||
|
||||
def draw_board(self, size, img_res):
|
||||
ret = pygame.Surface((size,size))
|
||||
# def draw_board(self, size, img_res):
|
||||
# ret = pygame.Surface((size,size))
|
||||
|
||||
inc = size / self.board_size;
|
||||
# inc = size / self.board_size;
|
||||
|
||||
for pos in range(len(self.board)):
|
||||
point = self.board[pos]
|
||||
# for pos in range(len(self.board)):
|
||||
# point = self.board[pos]
|
||||
|
||||
if point == Goban.EMPTY:
|
||||
code = self.def_draw_codes[pos]
|
||||
elif point == Goban.BLACK:
|
||||
code = 'b'
|
||||
elif point == Goban.WHITE:
|
||||
code = 'w'
|
||||
# if point == Goban.EMPTY:
|
||||
# code = self.def_draw_codes[pos]
|
||||
# elif point == Goban.BLACK:
|
||||
# code = 'b'
|
||||
# elif point == Goban.WHITE:
|
||||
# code = 'w'
|
||||
|
||||
if pos == self.last_move:
|
||||
code = code + 'T'
|
||||
# if pos == self.last_move:
|
||||
# code = code + 'T'
|
||||
|
||||
if pos == self.ko:
|
||||
code = code + 'C'
|
||||
# if pos == self.ko:
|
||||
# code = code + 'C'
|
||||
|
||||
s = img_res[code]
|
||||
s = pygame.transform.scale(s, (inc, inc))
|
||||
ret.blit(s, ((pos % self.board_size) *inc, (pos / self.board_size) *inc))
|
||||
# s = img_res[code]
|
||||
# s = pygame.transform.scale(s, (inc, inc))
|
||||
# ret.blit(s, ((pos % self.board_size) *inc, (pos / self.board_size) *inc))
|
||||
|
||||
if self.hover == pos:
|
||||
c = img_res['bH']
|
||||
if self.to_move == Goban.WHITE:
|
||||
c = img_res['wH']
|
||||
c = pygame.transform.scale(c, (inc, inc))
|
||||
ret.blit(c, ((pos % self.board_size) *inc, (pos / self.board_size) *inc))
|
||||
# if self.hover == pos:
|
||||
# c = img_res['bH']
|
||||
# if self.to_move == Goban.WHITE:
|
||||
# c = img_res['wH']
|
||||
# c = pygame.transform.scale(c, (inc, inc))
|
||||
# ret.blit(c, ((pos % self.board_size) *inc, (pos / self.board_size) *inc))
|
||||
|
||||
return ret.convert_alpha()
|
||||
# return ret.convert_alpha()
|
||||
|
||||
|
||||
|
||||
def draw_info(self):
|
||||
textbox = pygame.Surface((150, 300))
|
||||
textbox = textbox.convert()
|
||||
textbox.fill((250, 250, 250))
|
||||
# def draw_info(self):
|
||||
# textbox = pygame.Surface((150, 300))
|
||||
# textbox = textbox.convert()
|
||||
# textbox.fill((250, 250, 250))
|
||||
|
||||
font = pygame.font.Font(None, 24)
|
||||
# time = font.render('Time: {:02d}:{:02d}'.format(self.elapsed_time / 60, self.elapsed_time % 60), 1, (10, 10, 10))
|
||||
heading = font.render('Captures', 1, (10, 10, 10))
|
||||
black_cap = font.render('Black: {}'.format(self.black_captures), 1, (10, 10, 10))
|
||||
white_cap = font.render('White: {}'.format(self.white_captures), 1, (10, 10, 10))
|
||||
if self.to_move == Goban.BLACK:
|
||||
turn = font.render('To move: Black', 1, (10, 10, 10))
|
||||
elif self.to_move == Goban.WHITE:
|
||||
turn = font.render('To move: White', 1, (10, 10, 10))
|
||||
else:
|
||||
if self.winner == Goban.WHITE:
|
||||
turn = font.render('Winner: White', 1, (10, 10, 10))
|
||||
elif self.winner == Goban.BLACK:
|
||||
turn = font.render('Winner: Black', 1, (10, 10, 10))
|
||||
else:
|
||||
turn = font.render('Scoring', 1, (10, 10, 10))
|
||||
# font = pygame.font.Font(None, 24)
|
||||
# # time = font.render('Time: {:02d}:{:02d}'.format(self.elapsed_time / 60, self.elapsed_time % 60), 1, (10, 10, 10))
|
||||
# heading = font.render('Captures', 1, (10, 10, 10))
|
||||
# black_cap = font.render('Black: {}'.format(self.black_captures), 1, (10, 10, 10))
|
||||
# white_cap = font.render('White: {}'.format(self.white_captures), 1, (10, 10, 10))
|
||||
# if self.to_move == Goban.BLACK:
|
||||
# turn = font.render('To move: Black', 1, (10, 10, 10))
|
||||
# elif self.to_move == Goban.WHITE:
|
||||
# turn = font.render('To move: White', 1, (10, 10, 10))
|
||||
# else:
|
||||
# if self.winner == Goban.WHITE:
|
||||
# turn = font.render('Winner: White', 1, (10, 10, 10))
|
||||
# elif self.winner == Goban.BLACK:
|
||||
# turn = font.render('Winner: Black', 1, (10, 10, 10))
|
||||
# else:
|
||||
# turn = font.render('Scoring', 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))
|
||||
# textbox.blit(time, (0, 150))
|
||||
# textbox.blit(heading, (0, 0))
|
||||
# textbox.blit(black_cap, (0, 28))
|
||||
# textbox.blit(white_cap, (0, 56))
|
||||
# textbox.blit(turn, (0, 100))
|
||||
# # textbox.blit(time, (0, 150))
|
||||
|
||||
return textbox
|
||||
# return textbox
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user