def test_change_less(self): old_score = 12 score = 11 expected = 12 player = 'joe' high_score.high_score(player,old_score) high_score.high_score(player,score) observed = high_score.high_score(player,0) self.assertEqual(observed,expected)
def test_new_high_score(self): old_score = 12 score = 21 expected = 21 player = 'joe' high_score.high_score(player,old_score) high_score.high_score(player,score) observed = high_score.high_score(player,0) self.assertEqual(observed,expected)
def test_high_score(self): scores = [1, 2, 3, 4, 5, 1, 2, 3, 4] highest = max(scores) #feeding the function with scores from scores list at the end h_score must have highest score from the list for score in scores: h_score = high_score.high_score('Ronald', score) self.assertEqual(highest, h_score, 'Both scores must be equal')
def test_high_score(self): scores = [1,2,3,4,5,1,2,3,4] highest = max(scores) #feeding the function with scores from scores list at the end h_score must have highest score from the list for score in scores: h_score = high_score.high_score('Ronald', score) self.assertEqual(highest, h_score, 'Both scores must be equal')
def start(screen1): global screen screen=screen1 global menu_font menu_font = pygame.font.Font(None, 30) #options = [Option("NEW GAME", (140, 115)), Option("HIGH SCORE", (140, 165)), # Option("CONTROLS", (140, 215))] options = [Option("NEW GAME", (40, 300)), Option("HIGH SCORE", (200, 300)), Option("CONTROLS", (400, 300))] running =True ball = pygame.image.load("game.bmp") ball = pygame.transform.scale(ball, (460, 240)) while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running=False sys.exit() pygame.event.pump() screen.fill((0, 0, 0)) screen.blit(ball,[40,40,480,300]) for option in options: if option.rect.collidepoint(pygame.mouse.get_pos()): option.hovered = True if(option.text=="NEW GAME"): if(pygame.mouse.get_pressed()[0]): running=False print"1" #controls.controls(screen) start_game(screen,520,340) elif (option.text=="HIGH SCORE"): if(pygame.mouse.get_pressed()[0]): running=False #print"2" high_score.high_score(screen) elif (option.text=="CONTROLS"): if(pygame.mouse.get_pressed()[0]): running=False print"3" controls.controls(screen) else: option.hovered = False option.draw() pygame.display.update()
def gameover_screen(screen, score): high_scor = high_score(score) score_font = pygame.font.Font(path.join(fnt_dir, "PressStart2P.ttf"), 28) score_font2 = pygame.font.Font(path.join(fnt_dir, "PressStart2P.ttf"), 38) # Variável para o ajuste de velocidade clock = pygame.time.Clock() # Carrega o fundo da tela de ajuda background = pygame.image.load(path.join(img_dir, 'Congrats.png')).convert() background_rect = background.get_rect() running = True while running: # Ajusta a velocidade do jogo. clock.tick(FPS) # Processa os eventos (mouse, teclado, botão, etc). for event in pygame.event.get(): # Verifica se foi fechado. if event.type == pygame.KEYUP: if event.key == pygame.K_x: state = QUIT running = False if event.type == pygame.KEYUP: if event.key == pygame.K_p: state = INIT running = False # A cada loop, redesenha o fundo e os sprites screen.fill(BLACK) screen.blit(background, background_rect) text_surface = score_font2.render("{0:08d}".format(score), True, YELLOW) text_surface2 = score_font.render( "High score = {0:08d}".format(high_scor), True, YELLOW) text_rect = text_surface.get_rect() text_rect2 = text_surface2.get_rect() text_rect.midtop = (WIDTH / 2, (HEIGHT / 2) - 100) text_rect2.midtop = (WIDTH / 2, (HEIGHT / 2) + 10) screen.blit(text_surface, text_rect) screen.blit(text_surface2, text_rect2) # Depois de desenhar tudo, inverte o display. pygame.display.flip() return state
def test_new_player_score(self): score = 12 expected = 12 player = 'joe' observed = high_score.high_score(player,score) self.assertEqual(observed,expected)
def test_new_high_score(self): score = 27 expected = 27 player = 'sam' observed = high_score.high_score(player, score) self.assertEqual(observed, expected)
def test_change_less(self): score = 29 expected = 30 player = 'jim' observed = high_score.high_score(player, score) self.assertEqual(observed, expected)
def test_no_change_same(self): score = 21 expected = 21 player = 'joe' observed = high_score.high_score(player, score) self.assertEqual(observed, expected)
def test_high_score(self): scores = [90, 100, 20] self.assertEqual(high_score(scores), 100)