Added pass, resign, and quit buttons using SGC
This commit is contained in:
56
pygo.py
56
pygo.py
@ -11,6 +11,8 @@ import math
|
||||
|
||||
import pygame
|
||||
from pygame.locals import *
|
||||
import sgc
|
||||
from sgc.locals import *
|
||||
|
||||
import goban
|
||||
|
||||
@ -69,36 +71,52 @@ def magnitude(vector):
|
||||
def main():
|
||||
# Basic screen init
|
||||
pygame.init()
|
||||
screen = pygame.display.set_mode((1000, 800))
|
||||
# screen = pygame.display.set_mode((1000, 800))
|
||||
screen = sgc.surface.Screen((1000,800))
|
||||
pygame.display.set_caption('pyGo')
|
||||
|
||||
# SGC font color
|
||||
sgc.Font.col = (10,10,10)
|
||||
|
||||
# Create the background object, make it blank
|
||||
background = pygame.Surface(screen.get_size())
|
||||
background = background.convert()
|
||||
background.fill((250, 250, 250))
|
||||
# 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()
|
||||
|
||||
|
||||
board_size = 800
|
||||
board_inc = board_size / 19
|
||||
|
||||
gb = goban.Goban()
|
||||
|
||||
screen.fill((250, 250, 250))
|
||||
board = gb.draw_board(board_size, img_res)
|
||||
background.blit(board, (0,0))
|
||||
|
||||
screen.blit(board, (0,0))
|
||||
text = gb.draw_info()
|
||||
background.blit(text, (815, 25))
|
||||
screen.blit(text, (815, 25))
|
||||
|
||||
screen.blit(background, (0, 0))
|
||||
pass_btn = sgc.widgets.Button(label="Pass", pos=(850,500))
|
||||
pass_btn.activate = gb.pass_move
|
||||
pass_btn.add()
|
||||
|
||||
resign_btn = sgc.widgets.Button(label="Resign", pos=(850,600))
|
||||
resign_btn.activate = gb.resign
|
||||
resign_btn.add()
|
||||
|
||||
quit_btn = sgc.widgets.Button(label="Quit", pos=(850,700))
|
||||
quit_btn.activate = sys.exit
|
||||
quit_btn.add()
|
||||
|
||||
pygame.display.flip()
|
||||
|
||||
pygame.time.set_timer(USEREVENT, 1000)
|
||||
# pygame.time.set_timer(USEREVENT, 1000)
|
||||
|
||||
while True:
|
||||
event = pygame.event.wait()
|
||||
|
||||
sgc.widgets.event(event)
|
||||
|
||||
if event.type == QUIT:
|
||||
return
|
||||
|
||||
@ -127,16 +145,22 @@ def main():
|
||||
if event.button == 1:
|
||||
gb.play_move((row, col))
|
||||
|
||||
if event.type == USEREVENT:
|
||||
gb.elapsed_time += 1
|
||||
# if event.type == USEREVENT:
|
||||
# gb.elapsed_time += 1
|
||||
|
||||
|
||||
# Cleanup removed windows
|
||||
# for widget in dialogs:
|
||||
# if not widget.active():
|
||||
# dialogs.remove(widget)
|
||||
|
||||
board = gb.draw_board(board_size, img_res)
|
||||
background.blit(board, (0,0))
|
||||
screen.blit(board, (0,0))
|
||||
|
||||
text = gb.draw_info()
|
||||
background.blit(text, (815, 25))
|
||||
screen.blit(text, (815, 25))
|
||||
|
||||
screen.blit(background, (0, 0))
|
||||
sgc.widgets.update(0)
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user