State class

Define a base class State, in accordance with the state of the above said operation requires three functions are defined (startup, update, cleanup). Defined above said three variables (next, persist, done) in the init function, as well as for start_time and current_time recording time.

class State():
def __init__(self):
self.start_time = 0.0
self.current_time = 0.0
self.done = False
self.next = None
self.persist = {}

@abstractmethod
def startup(self, current_time, persist):
'''abstract method'''

Cleanup DEF (Self):
self.done = False
return self.persist

@abstractmethod
DEF Update (sefl, Surface, Keys, CURRENT_TIME):
'' 'abstract Method' ''
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
10
. 11
12 is
13 is
14
15
16
. 17
18 is
. 19
see LoadScreen class specific implementation of a state, the display state of FIG. 3.
startup function saves the incoming persist, set next to Level class status, start_time saved into the start time for this state. Info initialize a class that is designed to display interface information.
According to the update function of time in this state it has been running - and whether to display the contents of the end state (self.done = True) (current_time self.start_time ), decision.

class LoadScreen(State):
def __init__(self):
State.__init__(self)
self.time_list = [2400, 2600, 2635]

def startup(self, current_time, persist):
self.start_time = current_time
self.persist = persist
self.game_info = self.persist
self.next = self.set_next_state(http://www.amjmh.com/v/BIBRGZ_558768/)

info_state = self.set_info_state()
self.overhead_info = Info(self.game_info, info_state)

def set_next_state(self):
return c.LEVEL

def set_info_state(self):
return c.LOAD_SCREEN

def update(self, surface, keys, current_time):
if (current_time - self.start_time) < self.time_list[0]:
surface.fill(c.BLACK)
self.overhead_info.update(self.game_info)
self.overhead_info.draw(surface)
elif (current_time - self.start_time) < self.time_list[1]:
surface.fill(c.BLACK)
elif (current_time - self.start_time) < self.time_list[2]:
surface.fill((106, 150, 252))
else:
self.done = True

Guess you like

Origin www.cnblogs.com/hyhy904/p/11535768.html