Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmil Dudev <emildudev@gmail.com>2013-12-19 15:52:46 (GMT)
committer Emil Dudev <emildudev@gmail.com>2013-12-19 15:52:46 (GMT)
commitdf6a4f4da10eebd32c31d9667ded270cecbcc147 (patch)
treeb1c2cfee319f6f2edfb2e3795c66cc4b580cba80
parenta988bd96bff53ea5a3144985b6d7086c4eb7a959 (diff)
Mazes with holes
Fixes #3495
-rw-r--r--game.py8
-rw-r--r--maze.py14
2 files changed, 22 insertions, 0 deletions
diff --git a/game.py b/game.py
index 50d2d6f..e0cca7c 100644
--- a/game.py
+++ b/game.py
@@ -77,6 +77,7 @@ class MazeGame:
EMPTY_COLOR = N8
SOLID_COLOR = N1
TRAIL_COLOR = N10
+ HOLE_COLOR = N4
GOAL_COLOR = (0x00, 0xff, 0x00)
WIN_COLOR = (0xff, 0xff, 0x00)
@@ -528,6 +529,9 @@ class MazeGame:
if self.maze.map[newposition[0]][newposition[1]] == \
self.maze.GOAL:
self.finish(player)
+ elif self.maze.map[newposition[0]][newposition[1]] == \
+ self.maze.HOLE:
+ self.reset()
finish_delay = min(2 * len(self.allplayers), 6)
if self.finish_time is not None and \
@@ -571,6 +575,10 @@ class MazeGame:
pygame.draw.rect(self.screen, self.EMPTY_COLOR, rect, 0)
dot = rect.inflate(-self.outline * 2, -self.outline * 2)
pygame.draw.ellipse(self.screen, self.TRAIL_COLOR, dot, 0)
+ elif tile == self.maze.HOLE:
+ pygame.draw.rect(self.screen, self.EMPTY_COLOR, rect, 0)
+ dot = rect.inflate(-self.outline * 2, -self.outline * 2)
+ pygame.draw.ellipse(self.screen, self.HOLE_COLOR, dot, 0)
elif tile == self.maze.GOAL:
pygame.draw.rect(self.screen, self.GOAL_COLOR, rect, 0)
else:
diff --git a/maze.py b/maze.py
index 422a546..daa9704 100644
--- a/maze.py
+++ b/maze.py
@@ -30,6 +30,7 @@ class Maze:
EMPTY = 1
SEEN = 2
GOAL = 3
+ HOLE = 4
def __init__(self, seed, width, height):
# use the seed given to us to make a pseudo-random number generator
@@ -54,6 +55,10 @@ class Maze:
def validDig(self, x, y):
return self.bounds.collidepoint(x,y) and self.map[x][y]==self.SOLID
+
+ def validHole(self, x, y):
+ return x > 1 and y > 1 and x < self.width - 2 and y < self.height - 2\
+ and self.map[x][y] == self.SOLID
def validDigDirections(self, x, y):
directions = []
@@ -94,3 +99,12 @@ class Maze:
stack.append((x+direction[0]*2, y+direction[1]*2))
else:
stack.pop()
+
+ max_holes = 1
+ holes = 0
+ while holes != max_holes:
+ x = self.generator.randrange(1, self.width, 1)
+ y = self.generator.randrange(1, self.height, 1)
+ if self.validHole(x, y):
+ self.map[x][y] = self.HOLE
+ holes += 1