tic-far-toe/GameMap.py
RomulAugustus e7f1733a8a Fixes of syntax errors; minor edits
out of minor -
* made add_player_mark() also call the player instance to record mark into it's internal list
* put the exception message into a separate variable for the sake of simpler representation
2022-07-25 13:34:50 +03:00

32 lines
866 B
Python

class GameMap:
def __init__(self, max_size_x = float('inf'), max_size_y = float('inf')):
self.max_size_x = max_size_x
self.max_size_y = max_size_y
self.data = {}
def __str__(self):
return str(self.data)
def get_max_size_x(self):
return self.size_x
def get_max_size_y(self):
return self.size_y
def add_player_mark(self, x, y, player):
if x <= self.max_size_x and y <= self.max_size_y:
self.data[(x,y)] = player
player.record_mark(x, y)
else:
errorMessage = "The mark" + str((x,y)) + " is beyond preset max values, max_x - " + str(self.max_size_x) + ", max_y - " + str(self.max_size_y)
raise IndexError(errorMessage)
def clear_map(self):
self.data = {}