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:29:43 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2014-06-16 15:26:36 (GMT)
commit8d5a6050b30a8c5c3ef484314f7db13472d95c36 (patch)
tree1424841a1d67263aa9bc65310e0f1865d77a0615
parent76a20d5dc05d465af1e0c55375033f8d9d5f04db (diff)
Pep8 fixes in maze.py
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
-rw-r--r--maze.py55
1 files changed, 29 insertions, 26 deletions
diff --git a/maze.py b/maze.py
index 02fb805..e51ce9d 100644
--- a/maze.py
+++ b/maze.py
@@ -8,29 +8,30 @@
#
# Copyright (C) 2007 Joshua Minor
# This file is part of Maze.activity
-#
+#
# Maze.activity 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 3 of the License, or
# (at your option) any later version.
-#
+#
# Maze.activity 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 Maze.activity. If not, see <http://www.gnu.org/licenses/>.
import random
import gtk
+
class Maze:
SOLID = 0
EMPTY = 1
SEEN = 2
GOAL = 3
-
+
def __init__(self, seed, width, height):
# use the seed given to us to make a pseudo-random number generator
# we will use that to generate the maze, so that other players can
@@ -45,15 +46,15 @@ class Maze:
for x in range(0, width):
self.map.append([self.SOLID] * self.height)
- startx = self.generator.randrange(1,width,2)
- starty = self.generator.randrange(1,height,2)
- self.dig(startx,starty)
+ startx = self.generator.randrange(1, width, 2)
+ 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:
+ y > rectangle.y + rectangle.height:
return False
return True
@@ -64,17 +65,17 @@ class Maze:
def validDig(self, x, y):
return self._check_point_in_rectangle(self.bounds, x, y) and \
self.map[x][y] == self.SOLID
-
+
def validDigDirections(self, x, y):
directions = []
- if self.validDig(x,y-2):
- directions.append((0,-1))
- if self.validDig(x+2,y):
- directions.append((1,0))
- if self.validDig(x,y+2):
- directions.append((0,1))
- if self.validDig(x-2,y):
- directions.append((-1,0))
+ if self.validDig(x, y - 2):
+ directions.append((0, -1))
+ if self.validDig(x + 2, y):
+ directions.append((1, 0))
+ if self.validDig(x, y + 2):
+ directions.append((0, 1))
+ if self.validDig(x - 2, y):
+ directions.append((-1, 0))
return directions
def fill(self, color):
@@ -83,24 +84,26 @@ class Maze:
self.map[x][y] = color
def digRecursively(self, x, y):
- """This works great, except for python's lame limit on recursion depth."""
+ """This works great, except for python's lame limit on
+ recursion depth.
+ """
self.map[x][y] = self.EMPTY
- directions = self.validDigDirections(x,y)
+ directions = self.validDigDirections(x, y)
while len(directions) > 0:
direction = self.generator.choice(directions)
- self.map[x+direction[0]][y+direction[1]] = self.EMPTY
- self.dig(x+direction[0]*2, y+direction[1]*2)
- directions = self.validDigDirections(x,y)
+ self.map[x + direction[0]][y + direction[1]] = self.EMPTY
+ self.dig(x + direction[0] * 2, y + direction[1] * 2)
+ directions = self.validDigDirections(x, y)
def dig(self, x, y):
- stack = [(x,y)]
+ stack = [(x, y)]
while len(stack) > 0:
x, y = stack[-1]
self.map[x][y] = self.EMPTY
- directions = self.validDigDirections(x,y)
+ directions = self.validDigDirections(x, y)
if len(directions) > 0:
direction = self.generator.choice(directions)
- self.map[x+direction[0]][y+direction[1]] = self.EMPTY
- stack.append((x+direction[0]*2, y+direction[1]*2))
+ self.map[x + direction[0]][y + direction[1]] = self.EMPTY
+ stack.append((x + direction[0] * 2, y + direction[1] * 2))
else:
stack.pop()