fork download
  1. class Map2D:
  2. def __init__(self, width, height, val):
  3. self._internalMap = [[val]*height for width in range(height)]
  4. def fromArray2D(self, array2D):
  5. self.internalMap = array2D
  6. def at(self, x, y):
  7. return self._internalMap[x][y]
  8. def putAt(self, x, y, val):
  9. self._internalMap[x][y] = val
  10. return self
  11. def putMap2DAt(self, x, y, another):
  12. for ix in range(x, x+another.width()):
  13. for iy in range(y, y+another.height()):
  14. self.putAt(ix, iy, another.at(ix-x, iy-y))
  15. return self
  16. def width(self):
  17. return len(self._internalMap[0])
  18. def height(self):
  19. return len(self._internalMap)
  20.  
  21. def printPureMap2D(map2d):
  22. for y in range(map2d.height()):
  23. row = []
  24. for x in range(map2d.width()):
  25. row.extend(map2d.at(x, y))
  26. print ''.join(row)
  27.  
  28. canvas = Map2D(20, 20, ' ')
  29. stars = Map2D(5, 5, '*')
  30.  
  31. canvas.putMap2DAt(0, 0, stars).putAt(5+3, 0, 'x').putMap2DAt(10, 0, stars)
  32. canvas.putMap2DAt(5, 5, stars)
  33. canvas.putMap2DAt(0, 10, stars).putMap2DAt(10, 10, stars)
  34.  
  35. printPureMap2D(canvas)
Success #stdin #stdout 0.01s 7896KB
stdin
Standard input is empty
stdout
*****   x *****     
*****     *****     
*****     *****     
*****     *****     
*****     *****     
     *****          
     *****          
     *****          
     *****          
     *****          
*****     *****     
*****     *****     
*****     *****     
*****     *****     
*****     *****