Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@gmail.com>2013-07-07 01:25:02 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2014-06-16 15:26:36 (GMT)
commit76a20d5dc05d465af1e0c55375033f8d9d5f04db (patch)
tree9e460b36270154014e9887a19eb32962b3e6ed73
parentedee30e326fba1a9b1e4778f4332719fb7829716 (diff)
Remove use of pygame in maze.py
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
-rw-r--r--maze.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/maze.py b/maze.py
index 422a546..02fb805 100644
--- a/maze.py
+++ b/maze.py
@@ -23,7 +23,7 @@
# along with Maze.activity. If not, see <http://www.gnu.org/licenses/>.
import random
-from pygame import Rect
+import gtk
class Maze:
SOLID = 0
@@ -40,7 +40,7 @@ class Maze:
self.generator = random.Random(seed)
self.width, self.height = width, height
self.map = []
- self.bounds = Rect(0,0,width,height)
+ self.bounds = gtk.gdk.Rectangle(0, 0, width, height)
for x in range(0, width):
self.map.append([self.SOLID] * self.height)
@@ -49,11 +49,21 @@ class Maze:
starty = self.generator.randrange(1,height,2)
self.dig(startx,starty)
+ def _check_point_in_rectangle(self, rectangle, x, y):
+ if x < rectangle.x or y < rectangle.y:
+ return False
+ if x > rectangle.x + rectangle.width or \
+ y > rectangle.y + rectangle.height:
+ return False
+ return True
+
def validMove(self, x, y):
- return self.bounds.collidepoint(x,y) and self.map[x][y]!=self.SOLID
+ return self._check_point_in_rectangle(self.bounds, x, y) and \
+ self.map[x][y] != self.SOLID
def validDig(self, x, y):
- return self.bounds.collidepoint(x,y) and self.map[x][y]==self.SOLID
+ return self._check_point_in_rectangle(self.bounds, x, y) and \
+ self.map[x][y] == self.SOLID
def validDigDirections(self, x, y):
directions = []