Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZach Stephens <zxs3926@rit.edu>2011-05-13 17:11:24 (GMT)
committer Zach Stephens <zxs3926@rit.edu>2011-05-13 17:11:24 (GMT)
commit3bf559404826b29a76f4dfb87286a7e66b2b4a8f (patch)
tree21b3d332bf77e5af6f7b1aba408b828775c45daf
parent14b03cedf3e56e63fdd95ed699f4094b4e581f0e (diff)
Tutorial toolbar fully implemented. Pressing next will show you the next line of the script. Pressing previous will bring you to the previous category. Board widget modified to remove parts of the previous draw piece. Editor toolbar added, and the skeleton has been implemented in the working activity.
-rw-r--r--MANIFEST1
-rw-r--r--activity.py471
-rw-r--r--boardwidget.py6
-rw-r--r--edittoolbar.py218
-rw-r--r--gametoolbar.py9
-rw-r--r--tutorialtoolbar.py81
6 files changed, 766 insertions, 20 deletions
diff --git a/MANIFEST b/MANIFEST
index 9f07bec..c6ad863 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,6 +1,7 @@
activity.py
gametoolbar.py
tutorialtoolbar.py
+edittoolbar.py
collaboration.py
boardwidget.py
gogame.py
diff --git a/activity.py b/activity.py
index e47c9cd..2868d62 100644
--- a/activity.py
+++ b/activity.py
@@ -29,6 +29,7 @@ from sugar._sugarext import KeyGrabber
from gametoolbar import GameToolbar
from tutorialtoolbar import TutorialToolbar
+from edittoolbar import EditToolbar
from gogame import GoGame
import boardwidget
import infopanel
@@ -52,9 +53,9 @@ class PlayGo(Activity):
self.komi = DEFAULT_KOMI
# Set the script
- self.script = ["This is the main board for a game of Go.", "There are three different board sizes to choose from; 9 x 9, 13 x 13, and 19 x 19.", "This game is played by placing stones down on the board.", "One person has black stones, and the other has white stones.", "To place a stone, move your mouse to the where you want to put the stone and click.", "Territories are created when you place stones of your color near other stones.", "If empty places on the board are surrounded by your pieces alone, then it counts as your territory.", "Scoring is based on a lot of different things.", "During the game, your score increases based on the amount of pieces you capture that are your opponents.", "When the game ends, territory is also added to these scores.", "A liberty is when there is a blank space next to one of your pieces.", "In this example, the black piece has four liberties.", "Those liberties are shown by the four squares around the piece.", "At one time, a piece can only have four liberties.", "To capture an opponents piece, it must have no more liberties.", "In this example, the black piece would be captured if white placed a piece where the triangle is.", "This would give white one point.", "Seki is a situation where both players share liberties.", "In this example, the black and white pieces share the two liberties that have circles in them.", "It is recommended for neither player to place pieces in those spots, because the other opponent could then capture the other player's pieces.", "Ko is a situation which prevents a game from going on forever.", "The example above shows a normal ko situation.", "If white were to place a piece where the X is, then it would capture the black piece.", "Black can't place a piece back in the same place though, since it would allow black and white capture the same pieces over and over.", "Superko is similar to ko, but on a larger scale.", "The superko rule states that the board can't be brought back to a previous position.", "This can happen when there is many ko's on the board, and players could keep capturing them forever.", "In the example above, there are two ko's that could be captured over and over, causing a superko.", "Life and death are important things to consider in Go.", "When some of your pieces become surrounded, then they are considered to be dead.", "This is because they could be captured at any time.", "It is important to know when a group of pieces are dead, since it will let you place pieces where they may be more useful.", "A ko fight is when two players challenge each other with their kos.", "When fighting, they will place pieces that will give them advantage as long as the opponent doesn't stop them.", "In this example, a white piece was taken where the circle was.", "During white's turn they then place the white piece with the x, which gives the black player a choice.", "They can either place a spot where the circle is, or stop the white player from having territory that won't be capturable.", "Semeai, or \"Capture Race\", is when there is a mutual capturing contest between the two players.", "These situations are usually won by whomever moves first in the race, since they tend to involve the same amount of moves on both sides.", "The current board is a common example of semeai.", "Sente and gote are terms for who has initiative at a current time.", "Sente means that you are making the first move, which the opponent may then have to respond to.", "Gote is the direct opposite, where you have to play a piece in respose to your opponent's move.", "In this example, black has played at x in sente.", "This places white in gote, where they must respond where the circle is or they will lose their pieces eventually.", "It's important to know when you have initiative in the game, since it will commonly exchange between the players.", "Maintaining sente and keeping out of gote will give you a higher chance of winning, since you will be able to make your opponent play where you want them to play.", "The game ends with both players have passed in the same turn.", "When that happens, each player's score is settled.", "First, the pieces that were captured by each player are counted.", "Then, the score of each player's territories are added to their scores.", "Finally, the komi (a point handicap given for playing second) is added to the white player.", "Whomever has the higher score after this is the winner!"]
+ self.script = ["", "This is the main board for a game of Go.", "There are three different board sizes to choose from; 9 x 9, 13 x 13, and 19 x 19.", "This game is played by placing stones down on the board.", "One person has black stones, and the other has white stones.", "To place a stone, move your mouse to the where you want to put the stone and click.", "Territories are created when you place stones of your color near other stones.", "If empty places on the board are surrounded by your pieces alone, then it counts as your territory.", "Scoring is based on a lot of different things.", "During the game, your score increases based on the amount of pieces you capture that are your opponents.", "When the game ends, territory is also added to these scores.", "A liberty is when there is a blank space next to one of your pieces.", "In this example, the black piece has four liberties.", "Those liberties are shown by the four squares around the piece.", "At one time, a piece can only have four liberties.", "To capture an opponents piece, it must have no more liberties.", "In this example, the black piece would be captured if white placed a piece where the triangle is.", "This would give white one point.", "Seki is a situation where both players share liberties.", "In this example, the black and white pieces share the two liberties that have circles in them.", "It is recommended for neither player to place pieces in those spots, because the other opponent could then capture the other player's pieces.", "Ko is a situation which prevents a game from going on forever.", "The example above shows a normal ko situation.", "If white were to place a piece where the X is, then it would capture the black piece.", "Black can't place a piece back in the same place though, since it would allow black and white capture the same pieces over and over.", "Superko is similar to ko, but on a larger scale.", "The superko rule states that the board can't be brought back to a previous position.", "This can happen when there is many ko's on the board, and players could keep capturing them forever.", "In the example above, there are two ko's that could be captured over and over, causing a superko.", "Life and death are important things to consider in Go.", "When some of your pieces become surrounded, then they are considered to be dead.", "This is because they could be captured at any time.", "It is important to know when a group of pieces are dead, since it will let you place pieces where they may be more useful.", "A ko fight is when two players challenge each other with their kos.", "When fighting, they will place pieces that will give them advantage as long as the opponent doesn't stop them.", "In this example, a white piece was taken where the circle was.", "During white's turn they then place the white piece with the x, which gives the black player a choice.", "They can either place a spot where the circle is, or stop the white player from having territory that won't be capturable.", "Semeai, or \"Capture Race\", is when there is a mutual capturing contest between the two players.", "These situations are usually won by whomever moves first in the race, since they tend to involve the same amount of moves on both sides.", "The current board is a common example of semeai.", "Sente and gote are terms for who has initiative at a current time.", "Sente means that you are making the first move, which the opponent may then have to respond to.", "Gote is the direct opposite, where you have to play a piece in respose to your opponent's move.", "In this example, black has played at x in sente.", "This places white in gote, where they must respond where the circle is or they will lose their pieces eventually.", "It's important to know when you have initiative in the game, since it will commonly exchange between the players.", "Maintaining sente and keeping out of gote will give you a higher chance of winning, since you will be able to make your opponent play where you want them to play.", "The game ends with both players have passed in the same turn.", "When that happens, each player's score is settled.", "First, the pieces that were captured by each player are counted.", "Then, the score of each player's territories are added to their scores.", "Finally, the komi (a point handicap given for playing second) is added to the white player.", "Whomever has the higher score after this is the winner!"]
- self.next_script_frame = [0,2,5,7,10,14,16,18,22,25,29,34,36,44]
+ self.next_script_frame = [0,1,3,6,8,11,15,18,21,25,29,33,38,41,48]
# Set the activity toolbox
toolbox = ActivityToolbox(self)
self.set_toolbox(toolbox)
@@ -76,6 +77,19 @@ class PlayGo(Activity):
self.tutorialToolbar.connect('change-category', self.category_cb)
self.tutorialToolbar.show()
+ # Set the editor toolbox
+ self.editToolbar = EditToolbar(self)
+ toolbox.add_toolbar(_('Editor'), self.editToolbar)
+ self.editToolbar.connect('add-black', self.add_black_cb)
+ self.editToolbar.connect('add-white', self.add_white_cb)
+ self.editToolbar.connect('add-x', self.add_x_cb)
+ self.editToolbar.connect('add-circle', self.add_circle_cb)
+ self.editToolbar.connect('add-triangle', self.add_triangle_cb)
+ self.editToolbar.connect('add-square', self.add_square_cb)
+ self.editToolbar.connect('load-game', self.load_cb)
+ self.editToolbar.connect('save-game', self.save_cb)
+ self.editToolbar.show()
+
# Initialize the game
self.game = GoGame(self.size)
self.CurrentColor = 'B'
@@ -347,13 +361,17 @@ class PlayGo(Activity):
self.show_score()
self.board.set_sensitive(True)
self.buttons_box.set_sensitive(True)
+ self.tutorialToolbar.reset_cb()
self.tutorialToolbar.grey_out_previous()
self.tutorialToolbar.grey_out_next()
self.tutorialToolbar.grey_out_category()
self.tutorialToolbar.activate_begin()
+ self.gameToolbar.activate_size_change()
+ self.gameToolbar.activate_ai()
self.current_tutorial = 0;
self.lastX = -1
self.lastY = -1
+ self.infopanel.show(self.script[0])
if self.ai_activated:
self.ai.clear()
@@ -447,49 +465,480 @@ class PlayGo(Activity):
# Each page has a script which will be printed out to the user, which will explain the current item.
def begin_cb(self, widget = None):
+ del self.game
+ self.game = GoGame(19)
+ self.board_aspect.remove(self.board)
+ del self.board
+ self.board = boardwidget.GoBoardWidget(self.game.get_status(), int(19))
+ self.board_aspect.add(self.board)
+ self.board.connect('motion-notify-event', self.board_motion_cb)
+ self.board.connect('insert-requested', self.insert_cb)
+ self.board.show()
+
self.game.clear()
self.board.set_sensitive(False)
self.buttons_box.set_sensitive(False)
self.board.territories = None
self.board.status = self.game.status
self.board.do_expose_event()
+ self.gameToolbar.grey_out_size_change()
+ self.gameToolbar.grey_out_ai()
self.tutorialToolbar.activate_previous()
self.tutorialToolbar.activate_next()
self.tutorialToolbar.activate_category()
+ self.infopanel.show(self.script[0])
+
def previous_category(self, widget = None):
- self.game.clear()
+
self.board.set_sensitive(False)
self.buttons_box.set_sensitive(False)
self.board.territories = None
self.board.status = self.game.status
self.board.do_expose_event()
- if self.current_tutorial != 0:
- self.current_tutorial -= 1
self.infopanel.show(self.script[self.current_tutorial])
def next_category(self, widget = None):
- self.game.clear()
+
+ if self.current_tutorial != 53:
+ self.current_tutorial += 1
+
self.board.set_sensitive(False)
self.buttons_box.set_sensitive(False)
self.board.territories = None
+ if self.current_tutorial == 1:
+ self.game.clear()
+ elif self.current_tutorial == 3:
+ self.game.clear()
+ elif self.current_tutorial == 6:
+ self.game.clear()
+ self.game.status[(7,0)] = 'B'
+ self.game.status[(8,1)] = 'B'
+ self.game.status[(9,1)] = 'B'
+ self.game.status[(10,1)] = 'B'
+ self.game.status[(11,1)] = 'B'
+ self.game.status[(12,0)] = 'B'
+ self.game.status[(0,7)] = 'B'
+ self.game.status[(0,1)] = 'W'
+ self.game.status[(1,2)] = 'W'
+ self.game.status[(1,3)] = 'W'
+ self.game.status[(1,4)] = 'W'
+ self.game.status[(1,5)] = 'W'
+ self.game.status[(1,6)] = 'W'
+ elif self.current_tutorial == 8:
+ self.game.status = self.game.status
+ elif self.current_tutorial == 11:
+ self.game.clear()
+ self.game.status[(11,4)] = 'B'
+ self.game.status[(10,4)] = 'S'
+ self.game.status[(12,4)] = 'S'
+ self.game.status[(11,3)] = 'S'
+ self.game.status[(11,5)] = 'S'
+ elif self.current_tutorial == 15:
+ self.game.clear()
+ self.game.status[(9,3)] = 'B'
+ self.game.status[(8,4)] = 'B'
+ self.game.status[(15,9)] = 'B'
+ self.game.status[(15,10)] = 'B'
+ self.game.status[(8,3)] = 'W'
+ self.game.status[(8,5)] = 'W'
+ self.game.status[(9,4)] = 'W'
+ self.game.status[(7,4)] = 'T'
+ elif self.current_tutorial == 18:
+ self.game.clear()
+ self.game.status[(8,2)] = 'B'
+ self.game.status[(9,1)] = 'B'
+ self.game.status[(9,0)] = 'B'
+ self.game.status[(7,0)] = 'W'
+ self.game.status[(7,1)] = 'W'
+ self.game.status[(7,2)] = 'W'
+ self.game.status[(8,0)] = 'C'
+ self.game.status[(8,1)] = 'C'
+ elif self.current_tutorial == 21:
+ self.game.clear()
+ self.game.status[(9,9)] = 'B'
+ self.game.status[(10,8)] = 'B'
+ self.game.status[(10,10)] = 'B'
+ self.game.status[(11,9)] = 'B'
+ self.game.status[(9,8)] = 'W'
+ self.game.status[(9,10)] = 'W'
+ self.game.status[(8,9)] = 'W'
+ self.game.status[(10,9)] = 'X'
+ elif self.current_tutorial == 25:
+ self.game.clear()
+ self.game.status[(9,9)] = 'B'
+ self.game.status[(10,8)] = 'B'
+ self.game.status[(10,10)] = 'B'
+ self.game.status[(11,9)] = 'B'
+ self.game.status[(9,12)] = 'B'
+ self.game.status[(9,14)] = 'B'
+ self.game.status[(8,13)] = 'B'
+ self.game.status[(9,8)] = 'W'
+ self.game.status[(9,10)] = 'W'
+ self.game.status[(8,9)] = 'W'
+ self.game.status[(9,13)] = 'W'
+ self.game.status[(10,12)] = 'W'
+ self.game.status[(10,14)] = 'W'
+ self.game.status[(11,13)] = 'W'
+ elif self.current_tutorial == 29:
+ self.game.clear()
+ self.game.status[(7,0)] = 'B'
+ self.game.status[(8,0)] = 'B'
+ self.game.status[(8,1)] = 'B'
+ self.game.status[(9,0)] = 'B'
+ self.game.status[(9,1)] = 'B'
+ self.game.status[(9,2)] = 'B'
+ self.game.status[(10,1)] = 'B'
+ self.game.status[(10,2)] = 'B'
+ self.game.status[(11,0)] = 'B'
+ self.game.status[(11,1)] = 'B'
+ self.game.status[(12,0)] = 'B'
+ self.game.status[(6,0)] = 'W'
+ self.game.status[(7,1)] = 'W'
+ self.game.status[(7,2)] = 'W'
+ self.game.status[(8,3)] = 'W'
+ self.game.status[(9,3)] = 'W'
+ self.game.status[(10,3)] = 'W'
+ self.game.status[(11,2)] = 'W'
+ self.game.status[(12,2)] = 'W'
+ self.game.status[(12,1)] = 'W'
+ self.game.status[(13,1)] = 'W'
+ self.game.status[(13,0)] = 'W'
+ elif self.current_tutorial == 33:
+ self.game.clear()
+ self.game.status[(10,16)] = 'B'
+ self.game.status[(10,17)] = 'B'
+ self.game.status[(11,15)] = 'B'
+ self.game.status[(11,17)] = 'B'
+ self.game.status[(11,18)] = 'B'
+ self.game.status[(12,16)] = 'B'
+ self.game.status[(12,17)] = 'B'
+ self.game.status[(12,18)] = 'B'
+ self.game.status[(13,16)] = 'B'
+ self.game.status[(13,17)] = 'B'
+ self.game.status[(14,18)] = 'B'
+ self.game.status[(2,18)] = 'W'
+ self.game.status[(3,18)] = 'W'
+ self.game.status[(3,17)] = 'W'
+ self.game.status[(4,16)] = 'W'
+ self.game.status[(5,17)] = 'W'
+ self.game.status[(6,17)] = 'W'
+ self.game.status[(7,17)] = 'W'
+ self.game.status[(7,18)] = 'W'
+ self.game.status[(8,18)] = 'W'
+ self.game.status[(4,18)] = 'T'
+ self.game.status[(11,16)] = 'C'
+ self.game.status[(5,18)] = 'S'
+ elif self.current_tutorial == 38:
+ self.game.clear()
+ self.game.status[(7,0)] = 'B'
+ self.game.status[(7,1)] = 'B'
+ self.game.status[(7,2)] = 'B'
+ self.game.status[(7,3)] = 'B'
+ self.game.status[(7,4)] = 'B'
+ self.game.status[(8,5)] = 'B'
+ self.game.status[(9,5)] = 'B'
+ self.game.status[(10,0)] = 'B'
+ self.game.status[(10,1)] = 'B'
+ self.game.status[(10,2)] = 'B'
+ self.game.status[(10,3)] = 'B'
+ self.game.status[(10,4)] = 'B'
+ self.game.status[(9,0)] = 'W'
+ self.game.status[(9,1)] = 'W'
+ self.game.status[(9,2)] = 'W'
+ self.game.status[(9,3)] = 'W'
+ self.game.status[(9,4)] = 'W'
+ self.game.status[(10,5)] = 'W'
+ self.game.status[(11,5)] = 'W'
+ self.game.status[(12,0)] = 'W'
+ self.game.status[(12,1)] = 'W'
+ self.game.status[(12,2)] = 'W'
+ self.game.status[(12,3)] = 'W'
+ self.game.status[(12,4)] = 'W'
+ elif self.current_tutorial == 41:
+ self.game.clear()
+ self.game.status[(3,0)] = 'B'
+ self.game.status[(3,1)] = 'B'
+ self.game.status[(4,2)] = 'B'
+ self.game.status[(5,2)] = 'B'
+ self.game.status[(6,2)] = 'B'
+ self.game.status[(7,2)] = 'B'
+ self.game.status[(8,2)] = 'B'
+ self.game.status[(9,1)] = 'B'
+ self.game.status[(4,0)] = 'W'
+ self.game.status[(4,1)] = 'W'
+ self.game.status[(5,1)] = 'W'
+ self.game.status[(6,0)] = 'W'
+ self.game.status[(6,1)] = 'W'
+ self.game.status[(7,1)] = 'W'
+ self.game.status[(8,1)] = 'W'
+ self.game.status[(8,0)] = 'C'
+ self.game.status[(9,1)] = 'X'
+ elif self.current_tutorial == 48:
+ self.game.clear()
+ else:
+ self.game.status = self.game.status
self.board.status = self.game.status
self.board.do_expose_event()
- if self.current_tutorial != 53:
- self.current_tutorial += 1
+
self.infopanel.show(self.script[self.current_tutorial])
- def category_cb(self, category):
- self.game.clear()
+ def category_cb(self, widget, category):
self.board.set_sensitive(False)
self.buttons_box.set_sensitive(False)
self.board.territories = None
+ self.current_tutorial = int(self.next_script_frame[category])
+ if self.current_tutorial == 0:
+ self.game.clear()
+ elif self.current_tutorial == 1:
+ self.game.clear()
+ elif self.current_tutorial == 3:
+ self.game.clear()
+ elif self.current_tutorial == 6:
+ self.game.clear()
+ self.game.status[(7,0)] = 'B'
+ self.game.status[(8,1)] = 'B'
+ self.game.status[(9,1)] = 'B'
+ self.game.status[(10,1)] = 'B'
+ self.game.status[(11,1)] = 'B'
+ self.game.status[(12,0)] = 'B'
+ self.game.status[(0,7)] = 'B'
+ self.game.status[(0,1)] = 'W'
+ self.game.status[(1,2)] = 'W'
+ self.game.status[(1,3)] = 'W'
+ self.game.status[(1,4)] = 'W'
+ self.game.status[(1,5)] = 'W'
+ self.game.status[(1,6)] = 'W'
+ elif self.current_tutorial == 8:
+ self.game.clear()
+ self.game.status[(7,0)] = 'B'
+ self.game.status[(8,1)] = 'B'
+ self.game.status[(9,1)] = 'B'
+ self.game.status[(10,1)] = 'B'
+ self.game.status[(11,1)] = 'B'
+ self.game.status[(12,0)] = 'B'
+ self.game.status[(0,7)] = 'B'
+ self.game.status[(0,1)] = 'W'
+ self.game.status[(1,2)] = 'W'
+ self.game.status[(1,3)] = 'W'
+ self.game.status[(1,4)] = 'W'
+ self.game.status[(1,5)] = 'W'
+ self.game.status[(1,6)] = 'W'
+ elif self.current_tutorial == 11:
+ self.game.clear()
+ self.game.status[(11,4)] = 'B'
+ self.game.status[(10,4)] = 'S'
+ self.game.status[(12,4)] = 'S'
+ self.game.status[(11,3)] = 'S'
+ self.game.status[(11,5)] = 'S'
+ elif self.current_tutorial == 15:
+ self.game.clear()
+ self.game.status[(9,3)] = 'B'
+ self.game.status[(8,4)] = 'B'
+ self.game.status[(15,9)] = 'B'
+ self.game.status[(15,10)] = 'B'
+ self.game.status[(8,3)] = 'W'
+ self.game.status[(8,5)] = 'W'
+ self.game.status[(9,4)] = 'W'
+ self.game.status[(7,4)] = 'T'
+ elif self.current_tutorial == 18:
+ self.game.clear()
+ self.game.status[(8,2)] = 'B'
+ self.game.status[(9,1)] = 'B'
+ self.game.status[(9,0)] = 'B'
+ self.game.status[(7,0)] = 'W'
+ self.game.status[(7,1)] = 'W'
+ self.game.status[(7,2)] = 'W'
+ self.game.status[(8,0)] = 'C'
+ self.game.status[(8,1)] = 'C'
+ elif self.current_tutorial == 21:
+ self.game.clear()
+ self.game.status[(9,9)] = 'B'
+ self.game.status[(10,8)] = 'B'
+ self.game.status[(10,10)] = 'B'
+ self.game.status[(11,9)] = 'B'
+ self.game.status[(9,8)] = 'W'
+ self.game.status[(9,10)] = 'W'
+ self.game.status[(8,9)] = 'W'
+ self.game.status[(10,9)] = 'X'
+ elif self.current_tutorial == 25:
+ self.game.clear()
+ self.game.status[(9,9)] = 'B'
+ self.game.status[(10,8)] = 'B'
+ self.game.status[(10,10)] = 'B'
+ self.game.status[(11,9)] = 'B'
+ self.game.status[(9,12)] = 'B'
+ self.game.status[(9,14)] = 'B'
+ self.game.status[(8,13)] = 'B'
+ self.game.status[(9,8)] = 'W'
+ self.game.status[(9,10)] = 'W'
+ self.game.status[(8,9)] = 'W'
+ self.game.status[(9,13)] = 'W'
+ self.game.status[(10,12)] = 'W'
+ self.game.status[(10,14)] = 'W'
+ self.game.status[(11,13)] = 'W'
+ elif self.current_tutorial == 29:
+ self.game.clear()
+ self.game.status[(7,0)] = 'B'
+ self.game.status[(8,0)] = 'B'
+ self.game.status[(8,1)] = 'B'
+ self.game.status[(9,0)] = 'B'
+ self.game.status[(9,1)] = 'B'
+ self.game.status[(9,2)] = 'B'
+ self.game.status[(10,1)] = 'B'
+ self.game.status[(10,2)] = 'B'
+ self.game.status[(11,0)] = 'B'
+ self.game.status[(11,1)] = 'B'
+ self.game.status[(12,0)] = 'B'
+ self.game.status[(6,0)] = 'W'
+ self.game.status[(7,1)] = 'W'
+ self.game.status[(7,2)] = 'W'
+ self.game.status[(8,3)] = 'W'
+ self.game.status[(9,3)] = 'W'
+ self.game.status[(10,3)] = 'W'
+ self.game.status[(11,2)] = 'W'
+ self.game.status[(12,2)] = 'W'
+ self.game.status[(12,1)] = 'W'
+ self.game.status[(13,1)] = 'W'
+ self.game.status[(13,0)] = 'W'
+ elif self.current_tutorial == 33:
+ self.game.clear()
+ self.game.status[(10,16)] = 'B'
+ self.game.status[(10,17)] = 'B'
+ self.game.status[(11,15)] = 'B'
+ self.game.status[(11,17)] = 'B'
+ self.game.status[(11,18)] = 'B'
+ self.game.status[(12,16)] = 'B'
+ self.game.status[(12,17)] = 'B'
+ self.game.status[(12,18)] = 'B'
+ self.game.status[(13,16)] = 'B'
+ self.game.status[(13,17)] = 'B'
+ self.game.status[(14,18)] = 'B'
+ self.game.status[(2,18)] = 'W'
+ self.game.status[(3,18)] = 'W'
+ self.game.status[(3,17)] = 'W'
+ self.game.status[(4,16)] = 'W'
+ self.game.status[(5,17)] = 'W'
+ self.game.status[(6,17)] = 'W'
+ self.game.status[(7,17)] = 'W'
+ self.game.status[(7,18)] = 'W'
+ self.game.status[(8,18)] = 'W'
+ self.game.status[(4,18)] = 'T'
+ self.game.status[(11,16)] = 'C'
+ self.game.status[(5,18)] = 'S'
+ elif self.current_tutorial == 38:
+ self.game.clear()
+ self.game.status[(7,0)] = 'B'
+ self.game.status[(7,1)] = 'B'
+ self.game.status[(7,2)] = 'B'
+ self.game.status[(7,3)] = 'B'
+ self.game.status[(7,4)] = 'B'
+ self.game.status[(8,5)] = 'B'
+ self.game.status[(9,5)] = 'B'
+ self.game.status[(10,0)] = 'B'
+ self.game.status[(10,1)] = 'B'
+ self.game.status[(10,2)] = 'B'
+ self.game.status[(10,3)] = 'B'
+ self.game.status[(10,4)] = 'B'
+ self.game.status[(9,0)] = 'W'
+ self.game.status[(9,1)] = 'W'
+ self.game.status[(9,2)] = 'W'
+ self.game.status[(9,3)] = 'W'
+ self.game.status[(9,4)] = 'W'
+ self.game.status[(10,5)] = 'W'
+ self.game.status[(11,5)] = 'W'
+ self.game.status[(12,0)] = 'W'
+ self.game.status[(12,1)] = 'W'
+ self.game.status[(12,2)] = 'W'
+ self.game.status[(12,3)] = 'W'
+ self.game.status[(12,4)] = 'W'
+ elif self.current_tutorial == 41:
+ self.game.clear()
+ self.game.status[(3,0)] = 'B'
+ self.game.status[(3,1)] = 'B'
+ self.game.status[(4,2)] = 'B'
+ self.game.status[(5,2)] = 'B'
+ self.game.status[(6,2)] = 'B'
+ self.game.status[(7,2)] = 'B'
+ self.game.status[(8,2)] = 'B'
+ self.game.status[(9,1)] = 'B'
+ self.game.status[(4,0)] = 'W'
+ self.game.status[(4,1)] = 'W'
+ self.game.status[(5,1)] = 'W'
+ self.game.status[(6,0)] = 'W'
+ self.game.status[(6,1)] = 'W'
+ self.game.status[(7,1)] = 'W'
+ self.game.status[(8,1)] = 'W'
+ self.game.status[(8,0)] = 'C'
+ self.game.status[(9,1)] = 'X'
+ elif self.current_tutorial == 48:
+ self.game.clear()
+ else:
+ self.game.status = self.game.status
+
self.board.status = self.game.status
self.board.do_expose_event()
- self.current_tutorial = self.next_script_frame[category - 1]
+
self.infopanel.show(self.script[self.current_tutorial])
+
+ # ----------- Editor Functions ------------------ #
+
+ def add_black_cb(self, widget=None):
+ self.editToolbar.grey_out_add_black()
+ self.editToolbar.activate_add_white()
+ self.editToolbar.activate_add_x()
+ self.editToolbar.activate_add_circle()
+ self.editToolbar.activate_add_triangle()
+ self.editToolbar.activate_add_square()
+
+ def add_white_cb(self, widget=None):
+ self.editToolbar.grey_out_add_white()
+ self.editToolbar.activate_add_black()
+ self.editToolbar.activate_add_x()
+ self.editToolbar.activate_add_circle()
+ self.editToolbar.activate_add_triangle()
+ self.editToolbar.activate_add_square()
+
+ def add_x_cb(self, widget=None):
+ self.editToolbar.grey_out_add_x()
+ self.editToolbar.activate_add_white()
+ self.editToolbar.activate_add_black()
+ self.editToolbar.activate_add_circle()
+ self.editToolbar.activate_add_triangle()
+ self.editToolbar.activate_add_square()
+
+ def add_circle_cb(self, widget=None):
+ self.editToolbar.grey_out_add_circle()
+ self.editToolbar.activate_add_white()
+ self.editToolbar.activate_add_x()
+ self.editToolbar.activate_add_black()
+ self.editToolbar.activate_add_triangle()
+ self.editToolbar.activate_add_square()
+
+ def add_triangle_cb(self, widget=None):
+ self.editToolbar.grey_out_add_triangle()
+ self.editToolbar.activate_add_white()
+ self.editToolbar.activate_add_x()
+ self.editToolbar.activate_add_circle()
+ self.editToolbar.activate_add_black()
+ self.editToolbar.activate_add_square()
+
+ def add_square_cb(self, widget=None):
+ self.editToolbar.grey_out_add_square()
+ self.editToolbar.activate_add_white()
+ self.editToolbar.activate_add_x()
+ self.editToolbar.activate_add_circle()
+ self.editToolbar.activate_add_triangle()
+ self.editToolbar.activate_add_black()
+
+ def save_cb(self, widget=None):
+ self.infopanel.show(_("To be implemented in the future!"))
+
+ def load_cb(self, widget=None):
+ self.infopanel.show(_("To be implemented in the future!"))
+
# ----------- Keypad events functions ----------- #
def _key_pressed_cb(self, grabber, keycode, state):
key = grabber.get_key(keycode, state)
diff --git a/boardwidget.py b/boardwidget.py
index a41b9c9..5c08532 100644
--- a/boardwidget.py
+++ b/boardwidget.py
@@ -243,12 +243,6 @@ class GoBoardWidget(gtk.Widget):
y = y + 1
ctx = self.window.cairo_create()
ct = gtk.gdk.CairoContext(ctx)
- #######################################################################################################
- #if color == 'B':
- # ct.set_source_pixbuf(self.ScaledBlackPixbuf, self.unit*x - self.unit/2, self.unit*y - self.unit/2 )
- #else:
- # ct.set_source_pixbuf(self.ScaledWhitePixbuf, self.unit*x - self.unit/2, self.unit*y - self.unit/2 )
- #######################################################################################################
# draw stone for when the icons of the editor are ready
diff --git a/edittoolbar.py b/edittoolbar.py
new file mode 100644
index 0000000..2c3a57d
--- /dev/null
+++ b/edittoolbar.py
@@ -0,0 +1,218 @@
+# -*- coding: UTF-8 -*-
+# Copyright 2007-2008 One Laptop Per Child
+# Copyright 2007 Gerard J. Cerchio <www.circlesoft.com>
+# Copyright 2008 Andrés Ambrois <andresambrois@gmail.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import gtk
+from os.path import join, dirname
+
+from gettext import gettext as _
+from sugar.graphics.toolbutton import ToolButton
+from sugar.graphics.objectchooser import ObjectChooser
+import logging
+from gobject import SIGNAL_RUN_FIRST, TYPE_PYOBJECT, TYPE_NONE, TYPE_INT
+
+class EditToolbar(gtk.Toolbar):
+ __gtype_name__ = 'EditToolbar'
+
+ __gsignals__ = {
+ 'add-black': (SIGNAL_RUN_FIRST, TYPE_NONE, []),
+ 'add-white': (SIGNAL_RUN_FIRST, TYPE_NONE, []),
+ 'add-x': (SIGNAL_RUN_FIRST, TYPE_NONE, []),
+ 'add-circle': (SIGNAL_RUN_FIRST, TYPE_NONE, []),
+ 'add-triangle': (SIGNAL_RUN_FIRST, TYPE_NONE, []),
+ 'add-square': (SIGNAL_RUN_FIRST, TYPE_NONE, []),
+ 'save-game': (SIGNAL_RUN_FIRST, TYPE_NONE, []),
+ 'load-game': (SIGNAL_RUN_FIRST, TYPE_NONE, []),
+ }
+
+ def __init__(self, activity):
+ gtk.Toolbar.__init__(self)
+ self.activity = activity
+
+ # Add Black Toggle Button
+ add_black_icon = join(dirname(__file__), 'images', 'black.gif')
+ add_black_image = gtk.Image()
+ add_black_image.set_from_file(add_black_icon)
+ self._add_black_button = ToolButton()
+ self._add_black_button.set_icon_widget(add_black_image)
+ self._add_black_button.connect('clicked', self._add_black_cb)
+ self.insert(self._add_black_button, -1)
+ self._add_black_button.show()
+
+ # Add White Toggle Button
+ add_white_icon = join(dirname(__file__), 'images', 'white.gif')
+ add_white_image = gtk.Image()
+ add_white_image.set_from_file(add_white_icon)
+ self._add_white_button = ToolButton()
+ self._add_white_button.set_icon_widget(add_white_image)
+ self._add_white_button.connect('clicked', self._add_white_cb)
+ self.insert(self._add_white_button, -1)
+ self._add_white_button.show()
+
+ # Separator
+ separator = gtk.SeparatorToolItem()
+ separator.set_draw(True)
+ self.insert(separator, -1)
+
+ # Add X Toggle Button
+ add_x_icon = join(dirname(__file__), 'images', 'XWhite.gif')
+ add_x_image = gtk.Image()
+ add_x_image.set_from_file(add_x_icon)
+ self._add_x_button = ToolButton()
+ self._add_x_button.set_icon_widget(add_x_image)
+ self._add_x_button.connect('clicked', self._add_x_cb)
+ self.insert(self._add_x_button, -1)
+ self._add_x_button.show()
+
+ # Add Circle Toggle Button
+ add_circle_icon = join(dirname(__file__), 'images', 'CircleWhite.gif')
+ add_circle_image = gtk.Image()
+ add_circle_image.set_from_file(add_circle_icon)
+ self._add_circle_button = ToolButton()
+ self._add_circle_button.set_icon_widget(add_circle_image)
+ self._add_circle_button.connect('clicked', self._add_circle_cb)
+ self.insert(self._add_circle_button, -1)
+ self._add_circle_button.show()
+
+ # Add Triangle Toggle Button
+ add_triangle_icon = join(dirname(__file__), 'images', 'TriangleWhite.gif')
+ add_triangle_image = gtk.Image()
+ add_triangle_image.set_from_file(add_triangle_icon)
+ self._add_triangle_button = ToolButton()
+ self._add_triangle_button.set_icon_widget(add_triangle_image)
+ self._add_triangle_button.connect('clicked', self._add_triangle_cb)
+ self.insert(self._add_triangle_button, -1)
+ self._add_triangle_button.show()
+
+ # Add Square Toggle Button
+ add_square_icon = join(dirname(__file__), 'images', 'SquareWhite.gif')
+ add_square_image = gtk.Image()
+ add_square_image.set_from_file(add_square_icon)
+ self._add_square_button = ToolButton()
+ self._add_square_button.set_icon_widget(add_square_image)
+ self._add_square_button.connect('clicked', self._add_square_cb)
+ self.insert(self._add_square_button, -1)
+ self._add_square_button.show()
+
+ # Separator
+ separator = gtk.SeparatorToolItem()
+ separator.set_draw(True)
+ self.insert(separator, -1)
+
+ # Load Button
+ self._load_button = ToolButton()
+ self._load_button.set_label(_('Load'))
+ self._load_button.connect('clicked', self._load_cb)
+ self.insert(self._load_button, -1)
+ self._load_button.show()
+
+ # Save Button
+ self._save_button = ToolButton()
+ self._save_button.set_label(_('Save'))
+ self._save_button.connect('clicked', self._save_cb)
+ self.insert(self._save_button, -1)
+ self._save_button.show()
+
+ def _add_widget(self, widget, expand=False):
+ tool_item = gtk.ToolItem()
+ tool_item.set_expand(expand)
+ tool_item.add(widget)
+ widget.show()
+ self.insert(tool_item, -1)
+ tool_item.show()
+
+ def _add_black_cb(self, widget):
+ self._add_black_button.set_sensitive(False)
+ self.emit('add-black')
+
+ def activate_add_black(self):
+ self._add_black_button.set_sensitive(True)
+
+ def grey_out_add_black(self):
+ self._add_black_button.set_sensitive(False)
+
+ def _add_white_cb(self, widget):
+ self._add_white_button.set_sensitive(False)
+ self.emit('add-white')
+
+ def activate_add_white(self):
+ self._add_white_button.set_sensitive(True)
+
+ def grey_out_add_white(self):
+ self._add_white_button.set_sensitive(False)
+
+ def _add_x_cb(self, widget):
+ self._add_x_button.set_sensitive(False)
+ self.emit('add-x')
+
+ def activate_add_x(self):
+ self._add_x_button.set_sensitive(True)
+
+ def grey_out_add_x(self):
+ self._add_x_button.set_sensitive(False)
+
+ def _add_square_cb(self, widget):
+ self._add_square_button.set_sensitive(False)
+ self.emit('add-square')
+
+ def activate_add_square(self):
+ self._add_square_button.set_sensitive(True)
+
+ def grey_out_add_square(self):
+ self._add_square_button.set_sensitive(False)
+
+ def _add_circle_cb(self, widget):
+ self._add_circle_button.set_sensitive(False)
+ self.emit('add-circle')
+
+ def activate_add_circle(self):
+ self._add_circle_button.set_sensitive(True)
+
+ def grey_out_add_circle(self):
+ self._add_circle_button.set_sensitive(False)
+
+ def _add_triangle_cb(self, widget):
+ self._add_triangle_button.set_sensitive(False)
+ self.emit('add-triangle')
+
+ def activate_add_triangle(self):
+ self._add_triangle_button.set_sensitive(True)
+
+ def grey_out_add_triangle(self):
+ self._add_triangle_button.set_sensitive(False)
+
+ def _save_cb(self, widget):
+ self._save_button.set_sensitive(True)
+ self.emit('save-game')
+
+ def activate_save(self):
+ self._save_button.set_sensitive(True)
+
+ def grey_out_save(self):
+ self._save_button.set_sensitive(False)
+
+ def _load_cb(self, widget):
+ self._load_button.set_sensitive(True)
+ self.emit('load-game')
+
+ def activate_load(self):
+ self._load_button.set_sensitive(True)
+
+ def grey_out_load(self):
+ self._load_button.set_sensitive(False)
+
diff --git a/gametoolbar.py b/gametoolbar.py
index 8e93ba6..4691963 100644
--- a/gametoolbar.py
+++ b/gametoolbar.py
@@ -101,6 +101,9 @@ class GameToolbar(gtk.Toolbar):
def _game_restart_cb(self, widget):
self._size_combo.set_sensitive(True)
self.emit('game-restart')
+
+ def activate_restart(self):
+ self._restart_button.set_sensitive(True)
def grey_out_restart(self):
self._restart_button.set_sensitive(False)
@@ -108,6 +111,9 @@ class GameToolbar(gtk.Toolbar):
def _game_size_cb(self, widget):
game_size = int(self._sizes[self._size_combo.combo.get_active()][:2])
self.emit('game-board-size', game_size)
+
+ def activate_size_change(self):
+ self._size_combo.set_sensitive(True)
def grey_out_size_change(self):
self._size_combo.set_sensitive(False)
@@ -124,6 +130,9 @@ class GameToolbar(gtk.Toolbar):
self.emit('ai-activated')
else:
self.emit('ai-deactivated')
+
+ def activate_ai(self):
+ self._ai_button.set_sensitive(True)
def grey_out_ai(self):
self._ai_button.set_sensitive(False)
diff --git a/tutorialtoolbar.py b/tutorialtoolbar.py
index 8e41a2d..5d154bd 100644
--- a/tutorialtoolbar.py
+++ b/tutorialtoolbar.py
@@ -33,13 +33,16 @@ class TutorialToolbar(gtk.Toolbar):
'begin': (SIGNAL_RUN_FIRST, TYPE_NONE, []),
'previous': (SIGNAL_RUN_FIRST, TYPE_NONE, []),
'next': (SIGNAL_RUN_FIRST, TYPE_NONE, []),
- 'change-category': (SIGNAL_RUN_FIRST, TYPE_NONE, [TYPE_STRING]),
+ 'change-category': (SIGNAL_RUN_FIRST, TYPE_NONE, [TYPE_INT]),
}
+
+
def __init__(self, activity):
gtk.Toolbar.__init__(self)
self.activity = activity
-
+ self._current_category = 0
+ self._script_indicies = [0,1,3,6,8,11,15,18,21,25,29,33,38,41,48]
# Begin Button
@@ -102,6 +105,10 @@ class TutorialToolbar(gtk.Toolbar):
self._begin_button.set_sensitive(False)
self.emit('begin')
+ def reset_cb(self):
+ self._current_category = 0
+ self._category_combo.combo.set_active(0)
+
def grey_out_previous(self):
self._previous_button.set_sensitive(False)
@@ -110,6 +117,40 @@ class TutorialToolbar(gtk.Toolbar):
def _previous_cb(self, widget):
self._previous_button.set_sensitive(True)
+ if self._current_category != 0:
+ self._current_category -= 1
+
+ if self._current_category == 0:
+ self._category_combo.combo.set_active(0)
+ elif self._current_category == 2:
+ self._category_combo.combo.set_active(1)
+ elif self._current_category == 5:
+ self._category_combo.combo.set_active(2)
+ elif self._current_category == 7:
+ self._category_combo.combo.set_active(3)
+ elif self._current_category == 10:
+ self._category_combo.combo.set_active(4)
+ elif self._current_category == 14:
+ self._category_combo.combo.set_active(5)
+ elif self._current_category == 17:
+ self._category_combo.combo.set_active(6)
+ elif self._current_category == 20:
+ self._category_combo.combo.set_active(7)
+ elif self._current_category == 24:
+ self._category_combo.combo.set_active(8)
+ elif self._current_category == 28:
+ self._category_combo.combo.set_active(9)
+ elif self._current_category == 32:
+ self._category_combo.combo.set_active(10)
+ elif self._current_category == 37:
+ self._category_combo.combo.set_active(11)
+ elif self._current_category == 40:
+ self._category_combo.combo.set_active(12)
+ elif self._current_category == 47:
+ self._category_combo.combo.set_active(13)
+ else:
+ self._category_combo.combo.set_active(int(self._category_combo.combo.get_active()) - 1)
+
self.emit('previous')
def grey_out_next(self):
@@ -120,7 +161,40 @@ class TutorialToolbar(gtk.Toolbar):
def _next_cb(self, widget):
self._next_button.set_sensitive(True)
+ if self._current_category != 53:
+ self._current_category += 1
self.emit('next')
+ if self._current_category == 1:
+ self._category_combo.combo.set_active(1)
+ elif self._current_category == 3:
+ self._category_combo.combo.set_active(2)
+ elif self._current_category == 6:
+ self._category_combo.combo.set_active(3)
+ elif self._current_category == 8:
+ self._category_combo.combo.set_active(4)
+ elif self._current_category == 11:
+ self._category_combo.combo.set_active(5)
+ elif self._current_category == 15:
+ self._category_combo.combo.set_active(6)
+ elif self._current_category == 18:
+ self._category_combo.combo.set_active(7)
+ elif self._current_category == 21:
+ self._category_combo.combo.set_active(8)
+ elif self._current_category == 25:
+ self._category_combo.combo.set_active(9)
+ elif self._current_category == 29:
+ self._category_combo.combo.set_active(10)
+ elif self._current_category == 33:
+ self._category_combo.combo.set_active(11)
+ elif self._current_category == 38:
+ self._category_combo.combo.set_active(12)
+ elif self._current_category == 41:
+ self._category_combo.combo.set_active(13)
+ elif self._current_category == 48:
+ self._category_combo.combo.set_active(14)
+ else:
+ self._category_combo.combo.set_active(int(self._category_combo.combo.get_active()))
+
def grey_out_category(self):
self._category_combo.set_sensitive(False)
@@ -129,6 +203,7 @@ class TutorialToolbar(gtk.Toolbar):
self._category_combo.set_sensitive(True)
def _category_cb(self, widget):
- self.category = int(self._categories[self._category_combo.combo.get_active()])
+ self._current_category = int(self._script_indicies[int(self._category_combo.combo.get_active())])
+ self.category = int(self._category_combo.combo.get_active())
self.emit('change-category', self.category)