add initial Map and Tile classes

This commit is contained in:
Josh Holtrop 2012-01-18 20:06:06 -05:00
commit a0957a0ec9
2 changed files with 27 additions and 0 deletions

22
Map.py Normal file
View File

@ -0,0 +1,22 @@
# odd-numbered rows are right-shifted by half a tile width
class Map(object):
def __init__(self):
self._arr = []
def add(self, row, col, tile):
self._extend(row, col)
self._arr[row][col] = tile
def get(self, row, col):
if len(self._arr) <= row:
return None
if len(self._arr[row]) <= col:
return None
return self._arr[row][col]
def _extend(self, row, col):
while len(self._arr) <= row:
self._arr.append([])
while len(self._arr[row]) <= col:
self._arr[row].append(None)

5
Tile.py Normal file
View File

@ -0,0 +1,5 @@
class Tile(object):
def __init__(self, typ, roll_val):
self.type = typ
self.roll_val = roll_val