Beispiel #1
0
    def __init__(self, ai_settings, screen, stats):
        self.screen = screen
        self.screen_rect = screen.get_rect()
        self.ai_settings = ai_settings
        self.stats = stats

        self.update = HighScores(ai_settings, screen, stats)

        self.text_color = (30, 30, 30)
        self.font = pygame.font.SysFont(None, 48)

        self.prep_score()
        self.prep_high_score()
        self.prep_level()
        self.prep_ships()
Beispiel #2
0
    def __init__(self):
        pygame.init()
        # declares all and sets classes, data, groups
        self.pac = Group()
        self.points = Group()
        self.pills = Group()
        self.fruits = Group()
        self.ghosts = Group()
        self.delay = 0
        self.count = 0
        self.timer = random.randint(3000, 5001)
        self.timer2 = 4500

        self.settings = Settings()
        self.stats = GameStats(self.settings)
        self.screen = pygame.display.set_mode(
            (self.settings.screen_width, self.settings.screen_height))
        pygame.display.set_caption("Pacman Portal")

        self.point = Point(self.screen, self.settings)
        self.maze = Maze(self.screen,
                         self.settings,
                         self.pac,
                         self.points,
                         self.pills,
                         self.fruits,
                         mazefile='images/maze.txt',
                         brickfile='square')
        self.portal = Portal(self.screen, self.settings)
        self.pacman = Pacman(self.screen, self.settings, self.maze,
                             self.portal, self.stats)

        self.sb = Scoreboard(self.settings, self.screen, self.stats, self.maze,
                             self.portal)
        self.play_button = Startup(self.screen, self.settings, 'Play')
        self.score_button = HighScores(self.screen, "High Scores",
                                       self.settings)
        self.back_button = HighScores(self.screen, "Back (B)", self.settings)
Beispiel #3
0
def run_game():
    BLACK = (0, 0, 0)
    pygame.init()
    settings = Settings()
    screen = pygame.display.set_mode((settings.get_dims()))
    pygame.display.set_caption('Alien Invasion')

    #play_button = Button(screen, 'Play')
    play_button = pygame.Rect(564, 598, 72, 29)
    scores_button = pygame.Rect(502, 636, 197, 29)
    high_scores = HighScores(screen, settings, BLACK, 62)

    stats = GameStats(settings, high_scores)
    sb = Scoreboard(settings, screen, stats)
    ship = Ship(settings, screen)
    alien = Alien(settings, screen)
    boss = BossAlien(settings, screen)
    #boss = GroupSingle()
    game_over = GameOver(screen, settings, stats, high_scores)
    bullets = Group()
    aliens = Group()
    alien_explosions = Group()
    alien_bullets = Group()
    boss_bullets = Group()
    gf.create_fleet(settings, screen, ship, aliens, alien_explosions)

    FPS = 60
    clock = pygame.time.Clock()
    settings.play_music()

    while True:
        dt = clock.tick(FPS) / 1000
        gf.check_events(settings, screen, stats, sb, play_button, high_scores,
                        scores_button, ship, aliens, bullets, game_over,
                        alien_explosions, boss)
        if stats.game_active:
            if not stats.game_over:
                ship.update(dt)
                gf.update_bullets(settings, screen, stats, sb, ship, aliens,
                                  bullets, alien_bullets, alien_explosions, dt,
                                  boss_bullets, boss)
                gf.update_aliens(settings, screen, stats, sb, ship, aliens,
                                 bullets, dt, alien_bullets, alien,
                                 alien_explosions, boss_bullets, boss)
                bullets.update()
                alien_bullets.update()
                boss_bullets.update()
        gf.update_screen(settings, screen, stats, sb, ship, aliens, bullets,
                         play_button, game_over, alien_bullets,
                         alien_explosions, dt, boss_bullets, boss)
Beispiel #4
0
def run_game():
    # Initialize game
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Alien Invaders by Diana Joya")

    # Game Stats
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)

    # Screens
    start_screen = Start(ai_settings, screen)
    score_board = HighScores(ai_settings, screen, stats)

    # Sprite Groups
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()
    bunkers = Group()
    random_ufo = UFO(ai_settings, screen)
    bullet_animation = BulletAnimation(ai_settings, screen, ship, bullets,
                                       aliens, stats, sb, random_ufo, bunkers)

    events = Update(ai_settings, screen, ship, bullets, aliens, stats, sb,
                    start_screen, score_board, random_ufo, bunkers)
    collision = Collisions(ai_settings, screen, ship, bullets, aliens, stats,
                           sb, start_screen, score_board, random_ufo, bunkers)

    # Game Loop
    while True:
        events.check_events()

        if stats.game_active:
            current_time = pygame.time.get_ticks()
            ship.update()
            bullet_animation.update_bullets()
            collision.update_aliens()
            bunkers.update()
            if ai_settings.ufo_allowed:
                random_ufo.update(current_time)

        events.update_screen()
Beispiel #5
0
def high_scores_table(score=0):
    print(score)
    score_board = HighScores()
    if score != 0:
        position = score_board.check_score(score)
        if position is not None:
            name = type_your_name()
            score_board.update_score(name, score, position)

    high_scores_list = score_board.get_scores()

    run_board = True
    while run_board:
        clock.tick(FPS)
        win.blit(BACKGROUND, (0, 0))

        header_shadow = LETTER_FONT_2.render('< HI SCORES >', 1, WHITE_2)
        header_text = LETTER_FONT_2.render('< HI SCORES >', 1, WHITE)
        win.blit(header_shadow, (int(WIDTH / 2) - int(header_shadow.get_width() / 2),
                                 int(FONT_SIZE_2)))
        win.blit(header_text, (int(WIDTH / 2) - int(header_text.get_width() / 2) + 2,
                               int(FONT_SIZE_2) + 2))

        for i in range(0, score_board.high_scores_count):
            score_shadow = LETTER_FONT_2.render(high_scores_list[i], 1, WHITE_2)
            score_text = LETTER_FONT_2.render(high_scores_list[i], 1, WHITE)
            win.blit(score_shadow, (int(WIDTH / 2) - int(score_shadow.get_width() / 2),
                                int((FONT_SIZE_2) * (i + 9/4))))
            win.blit(score_text, (int(WIDTH / 2) - int(score_text.get_width() / 2) + 2,
                                  int((FONT_SIZE_2) * (i + 9 / 4)) + 2))

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run_board = False

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    main_menu()
                    run_board = False

        pygame.display.update()
 def test_message_for_repeated_personal_best(self):
     scores = [20, 70, 50, 70, 30]
     expected = (
         "Your latest score was 30. That's 40 short of your personal best!")
     self.assertEqual(HighScores(scores).report(), expected)
 def test_message_for_new_personal_best(self):
     scores = [20, 40, 0, 30, 70]
     expected = "Your latest score was 70. That's your personal best!"
     self.assertEqual(HighScores(scores).report(), expected)
 def test_personal_top_when_there_is_only_one(self):
     scores = [40]
     expected = [40]
     self.assertEqual(HighScores(scores).personal_top(), expected)
 def test_personal_top_when_there_is_a_tie(self):
     scores = [40, 20, 40, 30]
     expected = [40, 40, 30]
     self.assertEqual(HighScores(scores).personal_top(), expected)
Beispiel #10
0
 def test_personal_top(self):
     scores = [50, 30, 10]
     expected = [50, 30, 10]
     self.assertEqual(HighScores(scores).personal_top(), expected)
Beispiel #11
0
 def test_latest_score(self):
     scores = [100, 0, 90, 30]
     expected = 30
     self.assertEqual(HighScores(scores).latest(), expected)
 def test_alternate(self):
     array = [17, 69, 42, 23, 0]
     assert HighScores(array).personal_best() == 69
 def test_basic(self):
     array = [17, 42, 23, 0]
     assert HighScores(array).personal_best() == 42
 def test_with_none(self):
     assert HighScores([]).latest() == None
 def test_alternate(self):
     array = [17, 42, 23, 0, 69]
     assert HighScores(array).latest() == 69
 def test_with_only_two(self):
     array = [42, 69]
     expected = sorted(array, reverse=True)
     assert HighScores(array).personal_top_three() == expected
 def test_with_only_one(self):
     array = [42]
     assert HighScores(array).personal_top_three() == array
 def test_with_none(self):
     assert HighScores([]).personal_best() == None
Beispiel #19
0
 def test_personal_best(self):
     scores = [40, 100, 70]
     expected = 100
     self.assertEqual(HighScores(scores).personal_best(), expected)
 def test_dont_modify_list(self):
     array = [17, 42, 86, 23, 0, 69]
     hs = HighScores(array)
     hs.personal_best()  # don't need to use it
     assert hs.scores == array
Beispiel #21
0
 def test_personal_top_highest_to_lowest(self):
     scores = [20, 10, 30]
     expected = [30, 20, 10]
     self.assertEqual(HighScores(scores).personal_top(), expected)
 def test_basic(self):
     array = [17, 42, 23, 0, 86, 69]
     assert HighScores(array).personal_top_three() == [86, 69, 42]
Beispiel #23
0
 def test_personal_top_when_there_are_less_than_3(self):
     scores = [30, 70]
     expected = [70, 30]
     self.assertEqual(HighScores(scores).personal_top(), expected)
 def test_alternate(self):
     array = [17, 42, 23, 72, 86, 69]
     assert HighScores(array).personal_top_three() == [86, 72, 69]
Beispiel #25
0
 def test_personal_top_from_a_long_list(self):
     scores = [10, 30, 90, 30, 100, 20, 10, 0, 30, 40, 40, 70, 70]
     expected = [100, 90, 70]
     self.assertEqual(HighScores(scores).personal_top(), expected)
 def test_with_first_place_2_way_tie(self):
     array = [17, 69, 42, 39, 26, 69, 42]
     assert HighScores(array).personal_top_three() == [69, 69, 42]
Beispiel #27
0
 def test_message_when_latest_score_is_not_the_highest_score(self):
     scores = [20, 100, 0, 30, 70]
     expected = (
         "Your latest score was 70. That's 30 short of your personal best!")
     self.assertEqual(HighScores(scores).report(), expected)
 def test_with_second_place_3_way_tie(self):
     array = [17, 69, 42, 69, 86, 69, 42]
     assert HighScores(array).personal_top_three() == [86, 69, 69]
Beispiel #29
0
 def test_list_of_scores(self):
     scores = [30, 50, 20, 70]
     expected = [30, 50, 20, 70]
     self.assertEqual(HighScores(scores).scores, expected)
 def test_basic(self):
     array = [17, 42, 23, 0]
     assert HighScores(array).scores == array