-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpelevatorgraphics.py
85 lines (63 loc) · 2.78 KB
/
pelevatorgraphics.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from gamegrid import *
from elevatoractor import ElevatorActor
from mockactor import MockActor
from personactor import PersonActor
class PelevatorGraphics:
def __init__(self, gameState):
self.gameState = gameState
self.numFloors = gameState.getNumFloors()
self.numElevators = len(gameState.getElevators())
self.elevatorActors = []
self.personActors = []
self.floorColors = [Color.orange, Color.blue,
Color.magenta, Color.green, Color.cyan, Color(0x006400),Color.yellow,Color(0xB03060),Color.black,Color.red,Color.DARK_GRAY,
Color.pink,Color(0xA52A2A),Color(0xBA55D3),Color(0x00FA9A)]
for elevatorId in range(0, self.numElevators):
self.elevatorActors.append(ElevatorActor(
self, gameState.getElevators()[elevatorId]))
self.floorHeight = self.elevatorActors[0].height
self.windowHeight = self.floorHeight*self.numFloors
self.windowWidth = 600
makeGameGrid(self.windowWidth, self.windowHeight, 1, None)
self.background = getBg()
self.background.setBgColor(Color.white)
self.mockActor = MockActor()
addActor(self.mockActor, Location(-5, -5))
for elevatorActor in self.elevatorActors:
addActor(elevatorActor, Location(-1000, -1000))
self.setupBg()
registerNavigation(resetted=gameState.reset)
def start(self):
show()
setSimulationPeriod(20)
doRun()
def getWindowHeight(self):
return self.windowHeight
def getWindowWidth(self):
return self.windowWidth
def getFloorHeight(self):
return self.floorHeight
def addPerson(self, person):
personActor = PersonActor(self, person)
addActor(personActor, Location(-1000, -1000))
self.personActors.append(person)
def getElevatorActor(self, elevator):
for elevatorActor in self.elevatorActors:
if elevatorActor.getElevator() == elevator:
return elevatorActor
def setupBg(self):
self.background.clear()
# draw a line for each floor
for floor in range(0, self.numFloors):
floorY = self.windowHeight - floor * self.floorHeight
self.background.setPaintColor(self.floorColors[floor % len(self.floorColors)])
# draw 'two' lines.. should be a rect, I know..
self.background.drawLine(0, floorY, self.windowWidth, floorY)
self.background.drawLine(0, floorY-1, self.windowWidth, floorY-1)
self.background.drawLine(0, floorY-2, self.windowWidth, floorY-2)
def dispose(self):
dispose()
def play():
if elevatorIsFull():
naechsterStock = closestDestinationFloor()
setElevatorDestination(naechsterStock)