def gameover(self, full_exit=False): """ Gameover occurs when a new tetromino does not fit after the old one has died, either after a "natural" drop or a hard drop by the player. That is why `self.lock_tetromino` is responsible for checking if it's game over. """ write_score(self.score) if full_exit: matrisquit("FULL_EXIT") else: Game().main(screen)
def gameover(self, full_exit=False): """ Gameover occurs when a new tetromino does not fit after the old one has died, either after a "natural" drop or a hard drop by the player. That is why `self.lock_tetromino` is responsible for checking if it's game over. """ write_score(self.score) if full_exit: exit() else: raise GameOver("Sucker!")
def prepare_and_execute_gameover(self, playsound=False): # if playsound: # self.gameover_sound.play() write_score(self.score) self.gameover = True
def prepare_and_execute_gameover(self, playsound=True): write_score(self.score) self.gameover = True
def prepare_and_execute_gameover(self, playsound = True): if playsound: self.gameover_sound.play() write_score(self.score) self.gameover = True
def main(self, screen): clock = pg.time.Clock() word_frequency = 2.5 # new word every N second word_speed = 30 + (self.difficulty*3) # pixels downwards per second word_timer = 0 paused = False while True: for event in pg.event.get(): if event.type == pg.QUIT: exit() elif event.type == pg.KEYDOWN and event.unicode in self.allowed_chars and event.unicode != '': if event.unicode == BACKSPACE: self.prompt_content = self.prompt_content[:-1] elif self.prompt_font.size(self.prompt_content + event.unicode)[0] < WIDTH: # ^ Ensuring the content of the prompt stays approximately within the boundraries of the screen self.prompt_content += event.unicode elif event.type == pg.MOUSEBUTTONDOWN and self.photo_info_rect.collidepoint(event.pos): source = self.background.get_current_bg().info['source'] print("Attempting to open {url} in webbrowser.".format(url=source)) webbrowser.open(source) elif event.type == pg.KEYDOWN and event.key in (pg.K_RIGHT, pg.K_LEFT): self.background.browse({pg.K_RIGHT: 'forward', pg.K_LEFT: 'backward'}[event.key]) elif event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE: write_score(self.score) return elif event.type == pg.KEYDOWN and event.key == pg.K_RETURN: paused = not paused if paused: screen.fill((0,0,0)) screen.blit(get_font(23).render("Pause (press enter to return (pardon the pun))", True, (80,80,80)), (40,40)) pg.display.flip() if paused: clock.tick(35) continue timepassed = clock.tick(35) / 1000. old_wt, word_timer = word_timer, (word_timer+timepassed) % word_frequency if old_wt > word_timer: self.add_word() old_level, self.level = self.level, 1 + self.words_killed//10 if self.level > old_level: self.compile_words(self.level) word_frequency *= 0.99 """ Each level, word_frequency becomes 99 percent of itself. If word_frequency starts out at 2.5, then ''' it will become around 2.065 on level 20: ''' for level in range(1, 21): print("Level {:<3}= {:.3f} Seconds".format(level, 2.5 * (0.99 ** (level - 1)))) """ print("Word frequency:", word_frequency) if self.health <= 0: write_score(self.score) return if len(self.current_words) < 1: self.add_word() word_timer = 0 for word in self.current_words: self.current_words[word][1] += timepassed self.current_words[word][2] = transform_color(self.current_words[word][2], 29, max_=240, min_=100) self.background.update(timepassed) self.surf.blit(self.background.surf, self.background.surf.get_rect(centerx=screen.get_rect().centerx, centery=self.background_height/2 + self.info_surf_height)) for word, meta in list(self.current_words.items()): """ math.cos is used to make the words move softly and delicately like ''' a leaf traveling in the wind an autum..... no. I don't feel very well, I feel like.. ''' like I'm not me anymore, HELP ME PLEASE, IF YOU'RE OUT THERE ''' ''' The multipliers on the result are pretty arbitrary, just to make the words move at the ''' right speed. """ y = (meta[1]*word_speed) + abs(math.cos(meta[1]*3)*10) if y > HEIGHT: del self.current_words[word] self.health -= 1 elif word == self.prompt_content: del self.current_words[word] self.score += len(word) self.words_killed += 1 self.prompt_content = '' else: self.surf.blit(self.create_word_surf(word, meta[2]), (meta[0] + math.cos(meta[1]*3)*8, y)) self.surf.blit(renderpair("Photo:", self.background.get_current_bg().info["photo"], get_font(18), 250, textcolor=(0,0,0), background=True, bgcolor=((25,155,215,108) if self.photo_info_rect.collidepoint(pg.mouse.get_pos()) else (255,255,215,108))), self.photo_info_rect) self.surf.blit(self.generate_info_surf(), (0,0)) prompt_surf = self.generate_prompt_surf() self.surf.blit(prompt_surf, (0, HEIGHT-prompt_surf.get_rect().height)) screen.blit(self.surf, (0, 0)) pg.display.flip()
def gameover(self, full_exit=False): """ Gameover occurs when a new tetromino does not fit after the old one has died, either after a "natural" drop or a hard drop by the player. That is why `self.lock_tetromino` is responsible for checking if it's game over. """ write_score(self.score) if full_exit: if self.agent_mode == True: print("Runs completed.") self.serialize_agent() exit() else: if self.agent_mode == True: self.agent.complete_episode() #Manages the starting of a new game if self.agent.get_current_episode( ) < self.agent.get_number_of_episodes(): #Resets the board self.matrix = dict() for y in range(MATRIX_HEIGHT): for x in range(MATRIX_WIDTH): self.matrix[(y, x)] = None self.score = 0 self.lines = 0 self.board = agent.board( self.create_board_representation()) self.board.set_board_height() self.board.set_holes() self.board.set_column_differences() self.agent.set_current_board(self.board) print(str(self.board)) new_seed = self.agent.load_new_seed() if new_seed == None: try: raise ValueError( "Not enough seeds for current experiment!") except: print( "\nNot enough seeds for current experiment!\nExiting Matris..." ) exit() print("Generating new game with seed: " + str(new_seed)) random.seed(new_seed) self.set_tetrominoes() self.next_tetromino = random.choice(list_of_tetrominoes) self.agent.set_agent_tetromino(self.current_tetromino) #Agent's first move of the new game self.tetromino_placement = self.agent.make_move() self.tetromino_position = (0, self.tetromino_placement[2]) for rotations in range(self.tetromino_placement[0]): self.request_rotation() else: print("Runs completed.") self.serialize_agent() exit() else: raise GameOver("Sucker!")