add initial Map and Tile classes
This commit is contained in:
commit
a0957a0ec9
22
Map.py
Normal file
22
Map.py
Normal 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)
|
Loading…
x
Reference in New Issue
Block a user