-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMap.py
More file actions
71 lines (55 loc) · 2.29 KB
/
Copy pathMap.py
File metadata and controls
71 lines (55 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from Aliases import jsonDict
from Aliases import positionTuple
from Utils import hexToTuple
from Constants import HexTypes
class Map:
def __init__(self, mapData: jsonDict) -> None:
'''
Initializes the map object with the given map data.
:param mapData: A dictionary containing the map data.
'''
self.__size = mapData["size"]
self.__name = mapData["name"]
self.__map = {}
self.__initializeMapContent(mapData["content"])
def __initializeMapContent(self, mapContent: jsonDict) -> None:
'''
Initializes the map content.
:param base: A dictionary containing the map content for the map.
'''
for baseHex in mapContent["base"]:
self.__map[hexToTuple(baseHex)] = HexTypes.BASE.value
for obstacleHex in mapContent["obstacle"]:
self.__map[hexToTuple(obstacleHex)] = HexTypes.OBSTACLE.value
for catapultHex in mapContent["catapult"]:
self.__map[hexToTuple(catapultHex)] = HexTypes.CATAPULT.value
for lightRepairHex in mapContent["light_repair"]:
self.__map[hexToTuple(lightRepairHex)] = HexTypes.LIGHT_REPAIR.value
for hardRepairHex in mapContent["hard_repair"]:
self.__map[hexToTuple(hardRepairHex)] = HexTypes.HARD_REPAIR.value
def getSize(self) -> int:
'''
Returns the size of the map.
:return: An integer representing the size of the map.
'''
return self.__size
def getName(self) -> str:
'''
Returns the name of the map.
:return: A string representing the name of the map.
'''
return self.__name
def objectAt(self, position: positionTuple) -> str:
'''
Returns the name of the object located at the given position.
:param position: A tuple representing the position to look up.
:return: A string value indicating the name of the object located at the given position.
If no object exists at the given position, returns "Empty".
'''
return self.__map.get(position, "Empty")
def __iter__(self):
"""
Returns an iterator over the positions and objects in the Map.
"""
for position, obj in self.__map.items():
yield position, obj