-
Notifications
You must be signed in to change notification settings - Fork 0
/
objects.py
70 lines (59 loc) · 1.84 KB
/
objects.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
'''
Neeeded objects for the main module
'''
import tkinter as tk
class Elevator:
'''
Represents a full elevator system object
'''
def __init__(self, storeys: int, posX: int, posY: int, canvas):
self.storeys = storeys
self.posX = posX
self.posY = posY
self.width = 100
self.height = 50
self.storey_array = [
canvas.create_rectangle(
self.posX,
self.posY + self.height * i,
self.posX + self.width,
self.posY + self.height * (
i + 1),
fill="gray",
activefill="yellow",
state=tk.DISABLED) for i in range(
0,
storeys)]
self.lift = Lift()
self.canvas = canvas
def update(self):
'''
Called every tick, updates lift position
'''
for i in range(0, len(self.storey_array)):
self.canvas.itemconfig(self.storey_array[i], fill="gray")
self.canvas.itemconfig(
self.storey_array[self.lift.current_floor], fill="yellow")
class Lift:
'''
Represents the lift part that moves up and down in an elevator shaft
'''
def __init__(self):
self.capacity = 5
self.current_floor = 0
self.passengers = []
def addPassenger(self, passenger: int) -> None:
self.passengers.append(passenger)
self.capacity -= 1
def removePassenger(self, passenger: int) -> None:
self.passengers.remove(passenger)
self.capacity += 1
def goTo(self, target: int):
if target > self.current_floor:
self.current_floor += 1
print("Moving down")
elif target < self.current_floor:
self.current_floor -= 1
print("Moving up")
else:
return