changeset 36:3d3c523edefe

Move some methods from Level to BaseLevel
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Sat, 10 Mar 2012 12:09:02 +0100
parents d95d229f6931
children 18646f021d62
files mhrok/level.py
diffstat 1 files changed, 18 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/mhrok/level.py	Sat Mar 10 12:04:37 2012 +0100
+++ b/mhrok/level.py	Sat Mar 10 12:09:02 2012 +0100
@@ -8,8 +8,7 @@
 from mhrok import display
 from mhrok import mobs
 
-
-class Level(object):
+class BaseLevel(object):
     def __init__(self, pc):
         self.pc = pc
         self.mobs = [pc]
@@ -19,6 +18,19 @@
         self.lit_rooms = []
         self.map = [[0] * self.width for y in xrange(self.height)]
 
+    def __getitem__(self, (x, y)):
+        if self.width > x >= 0 and self.height > y >= 0:
+            return self.map[y][x]
+
+    def __setitem__(self, (x, y), value):
+        if self.width > x >= 0 and self.height > y >= 0:
+            self.map[y][x] = value
+
+
+class Level(BaseLevel):
+    def __init__(self, pc):
+        super(Level, self).__init__(pc)
+
         areas = [
             ((0, 0), (9, 11)), ((11, 0), (9, 11)), ((22, 0), (9, 11)),
             ((0, 13), (9, 11)), ((11, 13), (9, 11)), ((22, 13), (9, 11)),
@@ -43,11 +55,11 @@
             y1 = ny + r(0, nh/2) * 2
             x2 = x + r(0, w/2) * 2
             y2 = y + r(0, h/2) * 2
-            self.path((x1, y1), (x2, y2), 2)
+            self._path((x1, y1), (x2, y2), 2)
 
         for room in rooms:
             (x, y), (w, h) = room
-            self.fill((x, y), (w + 1, h + 1), 1)
+            self._fill((x, y), (w + 1, h + 1), 1)
             for i in xrange(r(0, 2)):
                 self[r(x, x+w), r(y, y+h)] = 3
             for i in xrange(r(1, 3)):
@@ -62,20 +74,12 @@
         self.rooms = rooms
 
 
-    def __getitem__(self, (x, y)):
-        if self.width > x >= 0 and self.height > y >= 0:
-            return self.map[y][x]
-
-    def __setitem__(self, (x, y), value):
-        if self.width > x >= 0 and self.height > y >= 0:
-            self.map[y][x] = value
-
-    def fill(self, (sx, sy), (width, height), fill):
+    def _fill(self, (sx, sy), (width, height), fill):
         for y in xrange(sy, sy + height):
             for x in xrange(sx, sx + width):
                 self[x, y] = fill
 
-    def path(self, (sx, sy), (ex, ey), fill):
+    def _path(self, (sx, sy), (ex, ey), fill):
         for x in xrange(sx, ex, 1 if sx < ex else -1):
             if self[x, sy]:
                 return