This repository was archived by the owner on Feb 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsessionmanager.py
More file actions
126 lines (107 loc) · 5.04 KB
/
sessionmanager.py
File metadata and controls
126 lines (107 loc) · 5.04 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
from qualifyingsession import QualifyingSession
from racesession import RaceSession
from sessionlifecyclepoint import SessionLifecyclePoint
from titlescreensession import TitleScreenSession
from introscreensession import IntroScreenSession
from sessiontype import SessionType
from highscoresession import HighScoreSession
from gameoversession import GameOverSession
class SessionManager(object):
def __init__(self):
self.setTopScore(0)
#self.activeSession=GameOverSession(1600,0.5,SessionType.qualifying)
self.activeSession=IntroScreenSession()
#self.activeSession=RaceSession(8,43100,49200)
#self.activeSession=HighScoreSession(700,700,200,20,20)
def advanceSession(self):
outcome=self.activeSession.getOutcome()
sessionType=outcome["sessiontype"]
if sessionType==SessionType.introScreen:
self.activeSession=TitleScreenSession()
if sessionType==SessionType.titleScreen:
destination=outcome["destination"]
if destination=="qualifying":
self.activeSession=QualifyingSession(self.getTopScore())
else:
self.activeSession=HighScoreSession(0,
self.getTopScore(),
0,
0,
0,
"titlescreen")
elif sessionType==SessionType.qualifying:
self.setTopSpeed(outcome["topspeed"])
self.setFastestLapTimeSeconds(outcome["laptimeseconds"])
self.setFastestLapTimeMilliseconds(outcome["laptimemilliseconds"])
if outcome["topscore"]>self.getTopScore():
self.setTopScore(outcome["topscore"])
if outcome["qualified"]:
self.activeSession=RaceSession(outcome["position"],outcome["score"],self.getTopScore())
else:
self.activeSession=HighScoreSession(outcome["score"],
self.getTopScore(),
self.getTopSpeed(),
outcome["laptimeseconds"],
outcome["laptimemilliseconds"],
"qualifying")
self.setSegmentPosition(outcome["segmentposition"])
self.setSidewaysPosition(outcome["sidewaysposition"])
elif sessionType==SessionType.race:
self.setTopSpeed(outcome["topspeed"])
self.setFastestLapTimeSeconds(outcome["laptimeseconds"])
self.setFastestLapTimeMilliseconds(outcome["laptimemilliseconds"])
if outcome["topscore"]>self.getTopScore():
self.setTopScore(outcome["topscore"])
self.activeSession=HighScoreSession(outcome["score"],
self.getTopScore(),
outcome["topspeed"],
outcome["laptimeseconds"],
outcome["laptimemilliseconds"],
"race")
self.setSegmentPosition(outcome["segmentposition"])
self.setSidewaysPosition(outcome["sidewaysposition"])
elif sessionType==SessionType.highScoreTable:
destination=outcome["destination"]
if destination=="titlescreen":
self.activeSession=TitleScreenSession()
else:
self.activeSession=GameOverSession(self.getSegmentPosition(),
self.getSidewaysPosition(),
SessionType.qualifying,
self.getTopScore(),
outcome["score"],
self.getTopSpeed(),
self.getFastestLapTimeSeconds(),
self.getFastestLapTimeMilliseconds())
elif sessionType==SessionType.gameOver:
self.activeSession=TitleScreenSession()
def advanceTime(self):
status=self.activeSession.getSessionLifecyclePoint()
if status==SessionLifecyclePoint.closed:
self.advanceSession()
else:
self.activeSession.managedAdvanceTime()
def setSegmentPosition(self,segmentPosition):
self.segmentPosition=segmentPosition
def getSegmentPosition(self):
return self.segmentPosition
def setSidewaysPosition(self,sidewaysPosition):
self.sidewaysPosition=sidewaysPosition
def getSidewaysPosition(self):
return self.sidewaysPosition
def getTopScore(self):
return self.topScore
def setTopScore(self,topScore):
self.topScore=topScore
def getTopSpeed(self):
return self.topSpeed
def setTopSpeed(self,topSpeed):
self.topSpeed=topSpeed
def getFastestLapTimeSeconds(self):
return self.fastestLapTimeSeconds
def setFastestLapTimeSeconds(self,fastestLapTimeSeconds):
self.fastestLapTimeSeconds=fastestLapTimeSeconds
def getFastestLapTimeMilliseconds(self):
return self.fastestLapTimeMilliseconds
def setFastestLapTimeMilliseconds(self,fastestLapTimeMilliseconds):
self.fastestLapTimeMilliseconds=fastestLapTimeMilliseconds