-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject.py
49 lines (40 loc) · 1.09 KB
/
object.py
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
import re
#A object is anything that can be inserted in the space
class Object:
#Stores all the objects deployed
lstObj = []
def __init__(self, name: str, x: int, y: int) -> None:
self.name = name
self.x = x
self.y = y
self.id = len(Object.lstObj)
self._startX = self.x
self._startY = self.y
Object.lstObj.append(self)
@property
def name(self):
return self._name
@name.setter
def name(self, value):
if re.match(r"[a-zA-Z]+$", value):
self._name = value
else:
raise ValueError("The name attribute may have only a-z characters")
@property
def x(self):
return self._x
@x.setter
def x(self, value):
if value >= 0:
self._x = value
else:
raise ValueError("The x attribute cannot be negative")
@property
def y(self):
return self._y
@y.setter
def y(self, value):
if value >= 0:
self._y = value
else:
raise ValueError("The y attribute cannot be negative")