Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/implodegame.py
diff options
context:
space:
mode:
authorJoe Lee <joe@jotaro.com>2009-08-16 16:26:53 (GMT)
committer Joe Lee <joe@jotaro.com>2009-08-19 04:11:36 (GMT)
commit4c1615a587bd9208da1f05964603cf066bc40cbc (patch)
tree6a63585e161d3d241ffe2e6f7fe3a43ba9ad7387 /implodegame.py
parentd8c65e40b2ec986e803953fe467c3f5af3173071 (diff)
Separated drawing code, refactored animation.
Diffstat (limited to 'implodegame.py')
-rw-r--r--implodegame.py29
1 files changed, 17 insertions, 12 deletions
diff --git a/implodegame.py b/implodegame.py
index fe4229b..9cbfc4b 100644
--- a/implodegame.py
+++ b/implodegame.py
@@ -35,7 +35,7 @@ class ImplodeGame(gtk.EventBox):
def __init__(self, *args, **kwargs):
super(ImplodeGame, self).__init__(*args, **kwargs)
self._animate = True
- self._current_anim = None
+ self._anim = None
self._board = None
self._undo_stack = []
@@ -45,7 +45,6 @@ class ImplodeGame(gtk.EventBox):
#self._random.seed(0)
self._difficulty = 0
self._size = (8, 6)
- self._contiguous = None
self._seed = 0
self._fragmentation = 0
@@ -164,11 +163,15 @@ class ImplodeGame(gtk.EventBox):
self._stop_animation()
contiguous = self._board.get_contiguous(x, y)
if len(contiguous) >= 3:
- self._contiguous = contiguous
+ def remove_func(anim_stopped=False):
+ self._remove_contiguous(contiguous, anim_stopped)
if self._animate:
- self._current_anim = self._grid.start_removal_anim(self._remove_contiguous, contiguous)
+ self._anim = self._grid.get_removal_anim(self._board,
+ contiguous,
+ remove_func)
+ self._anim.start()
else:
- self._remove_contiguous()
+ remove_func()
def _undo_key_pressed_cb(self, widget, dummy):
self.undo()
@@ -183,13 +186,14 @@ class ImplodeGame(gtk.EventBox):
self.new_game()
def _stop_animation(self):
- if self._current_anim is not None:
- self._current_anim.stop()
+ if self._anim is not None:
+ self._anim.stop()
- def _remove_contiguous(self, anim_stopped=False):
+ def _remove_contiguous(self, contiguous, anim_stopped=False):
+ # Removes the given set of contiguous blocks from the board.
self._redo_stack = []
self._undo_stack.append(self._board.clone())
- self._board.clear_pieces(self._contiguous)
+ self._board.clear_pieces(contiguous)
self._board.drop_pieces()
self._board.remove_empty_columns()
@@ -198,12 +202,13 @@ class ImplodeGame(gtk.EventBox):
if self._board.is_empty():
if self._animate and not anim_stopped:
- self._current_anim = self._grid.start_win_anim(self._init_win)
+ self._anim = self._grid.get_win_anim(self._init_win)
+ self._anim.start()
else:
self._init_win()
else:
- contiguous = self._board.get_all_contiguous()
- if len(contiguous) == 0:
+ all_contiguous = self._board.get_all_contiguous()
+ if len(all_contiguous) == 0:
self._init_lose()
def _init_win(self, anim_stopped=False):