2022-07-24 17:25:22 +00:00
|
|
|
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
|
2022-07-25 10:34:50 +00:00
|
|
|
self.data = {}
|
2022-07-24 17:25:22 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
2022-07-25 10:34:50 +00:00
|
|
|
return str(self.data)
|
2022-07-24 17:25:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_max_size_x(self):
|
|
|
|
return self.size_x
|
|
|
|
|
|
|
|
|
|
|
|
def get_max_size_y(self):
|
|
|
|
return self.size_y
|
|
|
|
|
|
|
|
|
2022-07-25 14:48:34 +00:00
|
|
|
def add_mark(self, x, y, player):
|
2022-07-25 13:53:34 +00:00
|
|
|
if (x <= self.max_size_x and y <= self.max_size_y) and (x >= 0 and y >= 0):
|
2022-07-25 14:49:19 +00:00
|
|
|
if (x, y) not in self.data:
|
|
|
|
self.data[(x,y)] = player
|
|
|
|
else:
|
|
|
|
errorMessage = "The mark is already busy by the Player" + self.data[(x, y)].get_name()
|
|
|
|
raise KeyError(errorMessage)
|
2022-07-24 17:25:22 +00:00
|
|
|
else:
|
2022-07-25 10:34:50 +00:00
|
|
|
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)
|
2022-07-24 17:25:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
def clear_map(self):
|
2022-07-25 14:10:43 +00:00
|
|
|
self.data = {}
|