-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworld.py
More file actions
32 lines (25 loc) · 808 Bytes
/
world.py
File metadata and controls
32 lines (25 loc) · 808 Bytes
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
from object import Object
class World:
objects = list() # type: list [Object]
def __init__(self) -> None:
pass
def add_object(self, object):
self.objects.append(object)
def add_objects(self, *objects):
for obj in objects:
self.add_object(obj)
def remove_object(self, index):
try:
del self.objects[index]
except:
pass
def find_object_by_id(self, id, all_objects = False) -> 'Object | list [Object]':
objects = list()
for i in range(self.objects):
id_ = self.objects[i].id
if id_ == id:
if all_objects:
objects.append(self.objects[i])
else:
return self.objects[i]
return objects