See previous commit...
This commit is contained in:
parent
17a49169eb
commit
704e7209a6
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:
|
class Goban:
|
||||||
"""Represents the go board. Handles stone placement, captures, etc"""
|
"""Represents the go board. Handles stone placement, captures, etc"""
|
||||||
|
|
||||||
|
@ -263,71 +259,71 @@ class Goban:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def draw_board(self, size, img_res):
|
# def draw_board(self, size, img_res):
|
||||||
ret = pygame.Surface((size,size))
|
# ret = pygame.Surface((size,size))
|
||||||
|
|
||||||
inc = size / self.board_size;
|
# inc = size / self.board_size;
|
||||||
|
|
||||||
for pos in range(len(self.board)):
|
# for pos in range(len(self.board)):
|
||||||
point = self.board[pos]
|
# point = self.board[pos]
|
||||||
|
|
||||||
if point == Goban.EMPTY:
|
# if point == Goban.EMPTY:
|
||||||
code = self.def_draw_codes[pos]
|
# code = self.def_draw_codes[pos]
|
||||||
elif point == Goban.BLACK:
|
# elif point == Goban.BLACK:
|
||||||
code = 'b'
|
# code = 'b'
|
||||||
elif point == Goban.WHITE:
|
# elif point == Goban.WHITE:
|
||||||
code = 'w'
|
# code = 'w'
|
||||||
|
|
||||||
if pos == self.last_move:
|
# if pos == self.last_move:
|
||||||
code = code + 'T'
|
# code = code + 'T'
|
||||||
|
|
||||||
if pos == self.ko:
|
# if pos == self.ko:
|
||||||
code = code + 'C'
|
# code = code + 'C'
|
||||||
|
|
||||||
s = img_res[code]
|
# s = img_res[code]
|
||||||
s = pygame.transform.scale(s, (inc, inc))
|
# s = pygame.transform.scale(s, (inc, inc))
|
||||||
ret.blit(s, ((pos % self.board_size) *inc, (pos / self.board_size) *inc))
|
# ret.blit(s, ((pos % self.board_size) *inc, (pos / self.board_size) *inc))
|
||||||
|
|
||||||
if self.hover == pos:
|
# if self.hover == pos:
|
||||||
c = img_res['bH']
|
# c = img_res['bH']
|
||||||
if self.to_move == Goban.WHITE:
|
# if self.to_move == Goban.WHITE:
|
||||||
c = img_res['wH']
|
# c = img_res['wH']
|
||||||
c = pygame.transform.scale(c, (inc, inc))
|
# c = pygame.transform.scale(c, (inc, inc))
|
||||||
ret.blit(c, ((pos % self.board_size) *inc, (pos / self.board_size) *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):
|
# def draw_info(self):
|
||||||
textbox = pygame.Surface((150, 300))
|
# textbox = pygame.Surface((150, 300))
|
||||||
textbox = textbox.convert()
|
# textbox = textbox.convert()
|
||||||
textbox.fill((250, 250, 250))
|
# textbox.fill((250, 250, 250))
|
||||||
|
|
||||||
font = pygame.font.Font(None, 24)
|
# 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))
|
# # 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))
|
# heading = font.render('Captures', 1, (10, 10, 10))
|
||||||
black_cap = font.render('Black: {}'.format(self.black_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))
|
# white_cap = font.render('White: {}'.format(self.white_captures), 1, (10, 10, 10))
|
||||||
if self.to_move == Goban.BLACK:
|
# if self.to_move == Goban.BLACK:
|
||||||
turn = font.render('To move: Black', 1, (10, 10, 10))
|
# turn = font.render('To move: Black', 1, (10, 10, 10))
|
||||||
elif self.to_move == Goban.WHITE:
|
# elif self.to_move == Goban.WHITE:
|
||||||
turn = font.render('To move: White', 1, (10, 10, 10))
|
# turn = font.render('To move: White', 1, (10, 10, 10))
|
||||||
else:
|
# else:
|
||||||
if self.winner == Goban.WHITE:
|
# if self.winner == Goban.WHITE:
|
||||||
turn = font.render('Winner: White', 1, (10, 10, 10))
|
# turn = font.render('Winner: White', 1, (10, 10, 10))
|
||||||
elif self.winner == Goban.BLACK:
|
# elif self.winner == Goban.BLACK:
|
||||||
turn = font.render('Winner: Black', 1, (10, 10, 10))
|
# turn = font.render('Winner: Black', 1, (10, 10, 10))
|
||||||
else:
|
# else:
|
||||||
turn = font.render('Scoring', 1, (10, 10, 10))
|
# turn = font.render('Scoring', 1, (10, 10, 10))
|
||||||
|
|
||||||
textbox.blit(heading, (0, 0))
|
# textbox.blit(heading, (0, 0))
|
||||||
textbox.blit(black_cap, (0, 28))
|
# textbox.blit(black_cap, (0, 28))
|
||||||
textbox.blit(white_cap, (0, 56))
|
# textbox.blit(white_cap, (0, 56))
|
||||||
textbox.blit(turn, (0, 100))
|
# textbox.blit(turn, (0, 100))
|
||||||
# textbox.blit(time, (0, 150))
|
# # textbox.blit(time, (0, 150))
|
||||||
|
|
||||||
return textbox
|
# return textbox
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
75
pygo.py
75
pygo.py
|
@ -6,34 +6,67 @@
|
||||||
import sys
|
import sys
|
||||||
sys.path.append('lib/')
|
sys.path.append('lib/')
|
||||||
|
|
||||||
import ConfigParser
|
|
||||||
|
|
||||||
import goban
|
import goban
|
||||||
import pygogui
|
import config
|
||||||
|
import gtk, gtk.glade
|
||||||
|
|
||||||
|
|
||||||
|
class Pygo():
|
||||||
|
"""This class handles the main interface, defines basic callbacks"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.resize = True
|
||||||
|
self.goban = None
|
||||||
|
|
||||||
|
self.network_mode = False
|
||||||
|
self.our_color = None
|
||||||
|
|
||||||
|
self.init_user_interface('./ui/default.glade')
|
||||||
|
self.init_widgets()
|
||||||
|
|
||||||
|
def init_user_interface(self, path_to_skin):
|
||||||
|
self.tree=gtk.glade.XML(path_to_skin, "window")
|
||||||
|
self.tree.signal_autoconnect(self)
|
||||||
|
self.window = self.tree.get_widget('window')
|
||||||
|
|
||||||
|
|
||||||
|
def init_widgets(self):
|
||||||
|
self.window.resize(1000,800)
|
||||||
|
|
||||||
|
# gobject.timeout_add(1000, self.update)
|
||||||
|
|
||||||
|
|
||||||
|
def on_local_new(self, widget):
|
||||||
|
if self.goban:
|
||||||
|
del self.goban
|
||||||
|
self.goban = goban.Goban()
|
||||||
|
self.network_mode = False
|
||||||
|
self.our_color = None
|
||||||
|
|
||||||
|
|
||||||
|
def on_net_direct(self, widget):
|
||||||
|
print 'stub: Pygo.on_menu_net_direct()'
|
||||||
|
|
||||||
|
|
||||||
|
def on_quit(self, widget):
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Read config file
|
# Read config file
|
||||||
settings = read_config_file()
|
config.init()
|
||||||
|
|
||||||
# Data
|
# base_icon = gtk.gdk.pixbuf_new_from_file('ui/icon.svg')
|
||||||
gb = goban.Goban()
|
# icon = base_icon.scale_simple(128, 128, gtk.gdk.INTERP_BILINEAR)
|
||||||
gui = pygogui.GUI(gb, settings)
|
# gtk.window_set_default_icon(icon)
|
||||||
|
go_obj = Pygo()
|
||||||
|
|
||||||
gui.update()
|
# Let's see if we can avoid using threads in this implementation
|
||||||
|
# gtk.gdk.threads_init()
|
||||||
while True:
|
# gtk.gdk.threads_enter()
|
||||||
# All of the real work happens in pygogui
|
gtk.main()
|
||||||
# It keeps a copy of all the relevant data
|
# gtk.gdk.threads_leave()
|
||||||
gui.do_event()
|
|
||||||
gui.update()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def read_config_file():
|
|
||||||
ret = ConfigParser.ConfigParser()
|
|
||||||
ret.read('pygo.cfg')
|
|
||||||
return ret
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__': main()
|
if __name__ == '__main__': main()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user