コード例 #1
0
ファイル: gamestate.py プロジェクト: goshdarngames/flood
 def __init__(self,model,fps):
    State.__init__(self,model)
    
    #create game event manager and register self as listener
    self.game_event_manager = GameEventManager()
    GameEventListener.__init__(self,self.game_event_manager)
    
    self.screen_size = self.model.screen_size
    
    self.fps = fps
    self.frames_elapsed = 0
    
    #set the square_size so all squares will fit in the playing field
    self.square_size = self.screen_size[0]/math.sqrt(NUM_SQUARES)
    self.grid = Grid(self.game_event_manager,self.square_size)
    
    #check for the highly unlikely situation where all squares are the
    #same      
    while(self._check_win()):
       self.grid = Grid(self.game_event_manager,self.square_size)   
    
    self.game_objects.append(self.grid)
    
    self.click_count = 0    
コード例 #2
0
ファイル: gameoverstate.py プロジェクト: goshdarngames/flood
    def __init__(self, model, click_count, fps, frames_elapsed):

        State.__init__(self, model)

        screen_width = self.model.screen_size[0]
        self.fps = fps

        # read old best time and score
        old_score_and_time = self._read_high_score()
        old_high_score = int(old_score_and_time[0])
        old_best_time = int(old_score_and_time[1])

        # check for new best score
        new_high_score = False
        if click_count < old_high_score:
            new_high_score = True
            self._write_high_score(click_count, frames_elapsed)

        # check for new best time
        new_best_time = False
        if frames_elapsed < old_best_time and click_count == old_high_score:
            new_best_time = True
            self._write_high_score(old_high_score, frames_elapsed)

        # game over text
        self.game_objects.append(TextObject("GAME OVER", GAME_OVER_TXT_Y, GAME_OVER_COLOR, screen_width))

        # how many clicks
        num_clicks_text = "It took you " + str(click_count) + " clicks"

        self.game_objects.append(TextObject(num_clicks_text, NUM_CLICKS_TXT_Y, NUM_CLICKS_COLOR, screen_width))

        # time taken
        time_taken_text = "Your time: " + self._frames_to_time(frames_elapsed)

        self.game_objects.append(TextObject(time_taken_text, TIME_TAKEN_TXT_Y, TIME_TAKEN_COLOR, screen_width))

        # new high score
        if new_high_score:
            self.game_objects.append(
                TextObject("!!!NEW HIGH SCORE!!!", NEW_HIGH_SCORE_TXT_Y, NEW_HIGH_SCORE_COLOR, screen_width)
            )

        if new_best_time:
            self.game_objects.append(
                TextObject("!!!NEW BEST TIME!!!", NEW_BEST_TIME_TXT_Y, NEW_BEST_TIME_COLOR, screen_width)
            )

        # old high score
        old_score_text = ""

        if new_high_score:
            old_score_text = "Old high score: " + str(old_high_score) + " clicks"
        else:
            old_score_text = "High score: " + str(old_high_score) + " clicks"

        self.game_objects.append(TextObject(old_score_text, OLD_SCORE_TXT_Y, OLD_SCORE_COLOR, screen_width))

        # old time taken
        old_time_taken_text = ""

        if not new_high_score:

            if new_best_time:
                old_time_taken_text = "Old best time: " + self._frames_to_time(old_best_time)
            else:
                old_time_taken_text = "Best time: " + self._frames_to_time(old_best_time)

        self.game_objects.append(TextObject(old_time_taken_text, OLD_TIME_TXT_Y, OLD_TIME_COLOR, screen_width))

        # press any key
        self.game_objects.append(TextObject("Press any key to continue.", ANY_KEY_TXT_Y, ANY_KEY_COLOR, screen_width))