From fbeeb4832e003f0fb523414a8bc0a3a52ebf5ec9 Mon Sep 17 00:00:00 2001 From: Gerard J. Cerchio Date: Sun, 23 Dec 2007 00:15:36 +0000 Subject: edge prisoners, any board size, new pot file, infoPanel messages --- diff --git a/MANIFEST b/MANIFEST index 4cb8e3b..0fcc7dc 100644 --- a/MANIFEST +++ b/MANIFEST @@ -14,7 +14,7 @@ images/w.gif images/white.gif images/WsTurn.gif po/ar.po -po/Connect.pot +po/PlayGo.pot po/de.po po/el.po po/es.po diff --git a/NEWS b/NEWS index c85c473..d6ea652 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,9 @@ +23 +* edge prisoners are recognized & removed +* allow any board size +* info panel reflects whose move +* renamed pot file + 22 * first test on XO works local no buddy panel * got rid of a stone placement bugs diff --git a/PlayGo-1.xo b/PlayGo-1.xo index 4cf8cbf..a597aad 100644 --- a/PlayGo-1.xo +++ b/PlayGo-1.xo Binary files differ diff --git a/activity.py b/activity.py index eb02959..10cb34d 100755 --- a/activity.py +++ b/activity.py @@ -23,13 +23,23 @@ logger = logging.getLogger('PlayGO') class PlayGo(Activity): + """ + Enter the PlayGo activity. + 1. intialize our parent object + 2. create an empty abstract board + 3. create the graphic objects, boardWidget, buddyPanel, InfoPanel + 4. group them in layout containers + 5. open a channel to the presence server + 6.1 if creating the game, make me the only player and go into local play mode + 6.2 if connecting to a neighborhood game, call the activity connection methods + """ def __init__(self, handle): Activity.__init__(self, handle) logger.debug('Starting Playgo activity...') board = abstractBoard( 19 ) - self.boardWidget = boardwidget.BoardWidget( board ) + self.boardWidget = boardwidget.BoardWidget( board, self ) self.buddies_panel = BuddiesPanel() self.info_panel = InfoPanel() @@ -64,7 +74,7 @@ class PlayGo(Activity): # This displays the buddies_panel even if we fail to connect: self.buddies_panel.add_watcher(owner) - self.info_panel.show(_('To play, share or invite someone.')) + self.info_panel.show(_('Place a black stone to play locally. You may share or invite to play remotely')) self.initiating = None @@ -189,6 +199,7 @@ class PlayGo(Activity): tube_conn = TubeConnection(self.conn, self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES], id, group_iface=self.text_chan[telepathy.CHANNEL_INTERFACE_GROUP]) + self.game = GoGame(tube_conn, self.boardWidget, self.initiating, self.buddies_panel, self.info_panel, self.owner, self._get_buddy, self) diff --git a/boardwidget.py b/boardwidget.py index 4c0d29b..95e19fd 100755 --- a/boardwidget.py +++ b/boardwidget.py @@ -1,4 +1,5 @@ import logging +from gettext import gettext as _ import cairo import gobject import gtk @@ -17,7 +18,7 @@ class BoardWidget(gtk.EventBox): 'insert-requested': (gobject.SIGNAL_RUN_FIRST, None, [int]), } - def __init__( self, aBoard ): + def __init__( self, aBoard, activity ): """ Startup the board widget 1. setup our signals: expose, insert, button and mouse movement @@ -37,6 +38,7 @@ class BoardWidget(gtk.EventBox): self.connect('motion-notify-event', self.__class__.motion_cb) #self.connect('size-request', self.__class__.sizeRequest_cb) + self.activity = activity self.drawCoords = 1 self.size = aBoard.size self.lastUnit = 0 @@ -66,11 +68,13 @@ class BoardWidget(gtk.EventBox): pixbufloader.close() self.pixBlack = pixbufloader.get_pixbuf() - logger.debug( "baord widget starts" ) + logger.debug( "baord widget started" ) + def sizeRequest_cb(self, requistion ): requistion.width = 8 requistion.height = 8 + def check_coord (self, x, y): """ @@ -78,10 +82,12 @@ class BoardWidget(gtk.EventBox): """ return x >= 0 and x < self.size and y >= 0 and y < self.size + def insert(self, dat, value): - """Return: - None : no winner - 0, 1: player 0/1 wins the game + """ + Perform a Stone placement, this is called directly from self + when playing a local game or from the tube to a remote player + managed in game.py """ color = dat >> 16 x = dat & 0xff @@ -96,26 +102,26 @@ class BoardWidget(gtk.EventBox): return None - def remove(self, column, value): - """Return: - None : no winner - 0, 1: player 0/1 wins the game - """ - y = column & 0xff - x = column >> 8 - - logger.debug( 'remove stone event x=%d y=%d col=%d value=%d', x,y,column, value ) - - assert x < self.myBoard.size - assert y < self.myBoard.size - - self.myBoard.setPointi( x, y, 0 ) - return None +# def remove(self, column, value): +# """Return: +# None : no winner +# 0, 1: player 0/1 wins the game +# """ +# y = column & 0xff +# x = column >> 8 +# +# logger.debug( 'remove stone event x=%d y=%d col=%d value=%d', x,y,column, value ) +# +# assert x < self.myBoard.size +# assert y < self.myBoard.size +# +# self.myBoard.setPointi( x, y, 0 ) +# return None def draw_background(self, rect, unit, ctx): """ - set the board windows background to the board image + set the board window's background to the board image """ ct = gtk.gdk.CairoContext(ctx) @@ -126,7 +132,7 @@ class BoardWidget(gtk.EventBox): def draw_lines(self, rect, unit, ctx): """ - draw the grid and star points on the board bitmap + draw the grid and star points onto the board bitmap """ # single width balck lines @@ -154,6 +160,8 @@ class BoardWidget(gtk.EventBox): ctx.arc( unit * 5, unit * 5, 3, 0, -1e-10) ctx.fill_preserve() ctx.stroke() + else : + seq = [] # stroke in the star points #TODO: adjust size for teeny boards @@ -202,6 +210,23 @@ class BoardWidget(gtk.EventBox): return int(x), int(y) + def legal(self, x, y ): + """ + boolean check if the stone play is legal + """ + if self.myBoard.status.has_key( (x,y) ) : + return False + + c = 'W' + if self.lastColor is 1 : + c = 'B' + +# if not self.myBoard.legal( (x,y), c ) : +# return False + + logger.debug( " returning legal ") + return True + def motion_cb(self, event): """ When the mouse moves, find out if it is a legal point @@ -263,17 +288,20 @@ class BoardWidget(gtk.EventBox): logger.debug( 'Button release event x=%d y=%d, pixx=%d pixy=%d', x,y, event.x, event.y ) if self.myGame is None : - + if ( event.button != 3 ) : - if self.myBoard.status.has_key( (x,y) ) : + #if self.myBoard.status.has_key( (x,y) ): + if not self.legal( x, y ) : return else : if self.lastColor is 1: dat = dat | 0x10000 self.lastColor = 2; + self.activity.info_panel.show(_("Black's turn ")) else : dat = dat | 0x20000 self.lastColor = 1; + self.activity.info_panel.show(_("White's turn ")) self.lastX = 0; self.insert( dat, 1 ) diff --git a/game.py b/game.py index a33ff2e..89a68ca 100755 --- a/game.py +++ b/game.py @@ -56,14 +56,14 @@ class abstractBoard: _logger.debug( "init baord size %d", boardSize ) def neighbors(self,x): - """ Returns the coordinates of the 4 (resp. 3 resp. 2 at the side / in the corner) intersections + """ Returns the coordinates of the 4 (resp. 3 resp. 2 at the side 1 in the corner) intersections adjacent to the given one. """ - if x[0]== 1 : l0 = [2] - elif x[0]== self.boardSize : l0 = [self.boardSize-1] + if x[0]== 0 : l0 = [1] + elif x[0]== self.boardSize-1 : l0 = [self.boardSize-2] else: l0 = [x[0]-1, x[0]+1] - if x[1]== 1 : l1 = [2] - elif x[1]== self.boardSize : l1 = [self.boardSize-1] + if x[1]== 0 : l1 = [1] + elif x[1]== self.boardSize-1 : l1 = [self.boardSize-2] else: l1 = [x[1]-1, x[1]+1] l = [] @@ -206,6 +206,7 @@ class GoGame(ExportedGObject): self.tube.watch_participants(self.participant_change_cb) self.boardWidget.connect('insert-requested', self.insert_requested_cb) + def participant_change_cb(self, added, removed): # Initiator is player 0, other player is player 1. diff --git a/po/Connect.pot b/po/PlayGo.pot index 562cb13..a6709f7 100644 --- a/po/Connect.pot +++ b/po/PlayGo.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2007-10-31 13:04+0200\n" +"POT-Creation-Date: 2007-12-22 16:14-0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -16,34 +16,39 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: activity/activity.info:2 -msgid "Go" -msgstr "" - -#: activity.py:63 -msgid "To play the game of Go, share or invite someone." +#: activity.py:77 +msgid "" +"Place a black stone to play locally. You may share or invite to play remotely" msgstr "" -#: activity.py:133 +#: activity.py:148 msgid "Waiting for another player to join." msgstr "" -#: activity.py:164 +#: activity.py:180 msgid "Joined a game. Waiting for my turn..." msgstr "" -#: game.py:183 +#: boardwidget.py:300 +msgid "Black's turn " +msgstr "" + +#: boardwidget.py:304 +msgid "White's turn " +msgstr "" + +#: game.py:335 msgid "The other player wins!" msgstr "" -#: game.py:200 +#: game.py:352 msgid "Your turn" msgstr "" -#: game.py:257 +#: game.py:397 msgid "You win!" msgstr "" -#: game.py:259 +#: game.py:399 msgid "Other player's turn" msgstr "" diff --git a/widgettest.py b/widgettest.py index 79b1540..4df01ca 100755 --- a/widgettest.py +++ b/widgettest.py @@ -1,4 +1,5 @@ import logging +from gettext import gettext as _ import gtk import random import hippo @@ -9,32 +10,41 @@ import boardwidget #from buddiespanel import BuddiesPanel from infopanel import InfoPanel -board = game.abstractBoard( 19 ) +boardSize = 9 +board = game.abstractBoard( boardSize ) logger = logging.getLogger('PlayGO') +class dummyActivity : + + def __init__(self): + + self.info_panel = InfoPanel() + + def redraw(grid): """Utility function to force a redraw of a Gtk widget.""" grid.window.invalidate_rect(grid.get_allocation(), True) + def key_press_cb(window, event, grid, player): key = gtk.gdk.keyval_name(event.keyval) if key in ('Left',): - for x in range( 19 ): + for x in range( boardSize ): board.play( (x, 3), 'W' ) redraw(grid) elif key in ('Right',): - for x in range( 19 ): + for x in range( boardSize ): board.play( ( x, 3 ), 'B' ) redraw(grid) elif key in ( 'r', ): - for x in range( 19 ): - for y in range( 19 ): - board.play( ( x, y ), random.randint( 0, 3 ) ) + for x in range( boardSize ): + for y in range( boardSize ): + board.setPointi( x, y, random.randint( 0, 3 ) ) redraw(grid) @@ -55,19 +65,20 @@ def main(): logger.setLevel( logging.DEBUG ) logger.debug( "Start widget test" ) - for x in range( 19 ): + for x in range( boardSize ): board.play( ( x, 0 ), 'W' ) window = gtk.Window() window.resize( 1200, 850 ) - - boardWidget = boardwidget.BoardWidget( board ) + + dummyMe = dummyActivity() + dummyMe.info_panel.show( " click to begin" ) + boardWidget = boardwidget.BoardWidget( board, dummyMe ) info_panels = InfoPanel() info_panels.show( " hello there I am the side layout test ") + - info_panel = InfoPanel() - info_panel.show( " hello there I am the lower layout test ") vbox = hippo.CanvasBox(spacing=4, orientation=hippo.ORIENTATION_VERTICAL) @@ -79,7 +90,7 @@ def main(): hbox.append(info_panels) vbox.append(hbox, hippo.PACK_EXPAND) - vbox.append(info_panel, hippo.PACK_END) + vbox.append( dummyMe.info_panel, hippo.PACK_END) canvas = hippo.Canvas() canvas.set_root(vbox) -- cgit v0.9.1