def run_game():
    # Initialise game and create a screen object.
    pygame.init()
    screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("ALIEN INVASION")

    # MAKE A SHIP.
    ship = Ship(ai_settings, screen)

    # MAKE A GROUP TO STORE THE BULLETS.
    bullets = Group()
    new_bullets = Group()

    # make a group of aliens
    aliens = Group()

    # create fleet
    gf.create_fleet(ai_settings, screen, aliens)

    # start the main loop for the game.
    while True:
        gf.check_function(ship, ai_settings, screen, new_bullets, bullets)
        ship.update()
        gf.update_bullet(bullets, aliens, ai_settings, screen)
        gf.update_aliens(aliens, ai_settings)
        gf.update_function(ai_settings, screen, ship, bullets, new_bullets, aliens)
def run_game():
    pygame.init()
    setting = Setting()
    screen = pygame.display.set_mode([setting.width, setting.height])

    #Now create the object of the ship
    ship = Ship(screen, setting)
    pygame.display.set_caption("Alien Games")

    # Make the Play button
    play_button = Button(setting, screen, "Play")

    #create an instance of gameStats
    stats = GameStats(setting)
    sb = Scoreboard(setting, screen, stats)

    #store a bullet in a list
    bullets = Group()
    aliens = Group()
    gf.create_fleet(setting, screen, aliens, ship)

    while True:
        gf.check_event(setting, screen, stats, play_button, sb, ship, aliens,
                       bullets)
        if stats.game_active:
            ship.update()
            gf.update_bullet(setting, screen, stats, sb, ship, bullets, aliens)
            gf.update_alien(setting, stats, screen, ship, aliens, bullets)
        gf.update_screen(screen, setting, sb, ship, stats, bullets, aliens,
                         play_button)
        screen.blit(setting.bg_image, setting.bg_image.get_rect())
        ship.blitme()
        ship.update()
        pygame.display.flip()
Exemplo n.º 3
0
def run_game():
    pygame.init()
    pygame.display.set_caption('Alien Invasion')
    ai_setings = Setting()
    screen = pygame.display.set_mode(
        (ai_setings.screen_width, ai_setings.screen_height), pygame.FULLSCREEN)
    play_button = Button(ai_setings, screen, 'Play')
    setting_button = S_Button(ai_setings, screen, 'Setting')
    q_button = Q_Button(ai_setings, screen, 'Quit')
    ship = Ship(ai_setings, screen)
    bullet = Group()
    alien = Alien(ai_setings, screen, scale)
    aliens = Group()
    gf.create_fleet(ai_setings, screen, ship, aliens)
    stats = GameStats(ai_setings)
    sb = scoreboard(ai_setings, screen, stats)
    gf.update_screen(ai_setings, screen, stats, sb, ship, bullet, aliens,
                     play_button, setting_button, q_button)

    while True:
        gf.check_events(ai_setings, screen, stats, sb, play_button,
                        setting_button, q_button, ship, aliens, bullet)
        if stats.game_active:
            ship.update()
            gf.update_screen(ai_setings, screen, stats, sb, ship, bullet,
                             aliens, play_button, setting_button, q_button)
            gf.update_bullet(ai_setings, screen, stats, sb, ship, bullet,
                             aliens)
            gf.update_aliens(ai_setings, stats, screen, sb, ship, aliens,
                             bullet)
Exemplo n.º 4
0
def run_game():
    # pygame初始化
    pygame.init()
    #设置对象初始化
    py_settings = Settings()

    # 设置窗口大小
    screen = pygame.display.set_mode(
        (py_settings.screen_width, py_settings.screen_height))
    # 设置标题
    pygame.display.set_caption("飞机大战")
    #创建一个飞船
    ship1 = Ship(screen)
    #创建一个敌机
    #enemy1 = Enemy(screen)

    # 创建一群敌机
    enemys = Group()

    #创建一个子弹编组
    bullets = Group()

    for i in range(py_settings.enemy_number):
        gf.creat_enemy(screen, enemys)

    # 程序主循环
    while True:
        gf.check_events(screen, py_settings, ship1, bullets)
        gf.update_screen(screen, py_settings, ship1, enemys, bullets)
        gf.update_bullet(bullets, enemys)
        gf.check(ship1, enemys)
Exemplo n.º 5
0
def run_game():
    eg_settings = Settings()
    pygame.init()
    screen = pygame.display.set_mode(
        (eg_settings.screen_width, eg_settings.screen_height))

    virus = Virus(eg_settings, screen)
    pygame.display.set_caption("virus human")
    humans = Group()
    bullets = Group()
    stats = Stats(eg_settings)
    buttons = Button(eg_settings, screen, stats, virus, bullets, gf)
    sb = Score_Board(eg_settings, screen, stats)

    while True:
        gf.check_event(eg_settings, screen, virus, bullets, humans, buttons,
                       stats, sb)

        if stats.active_game:
            virus.update()

            gf.update_bullet(screen, bullets, humans, eg_settings, virus,
                             stats, sb)
            gf.update_human(humans, virus, stats, bullets, eg_settings, screen,
                            sb)
            if virus.flag:
                gf.fire_humans(eg_settings, screen, humans, virus)

        gf.update_screen(eg_settings, screen, virus, bullets, humans, buttons,
                         stats, sb)
Exemplo n.º 6
0
def run_game():
    #初始化游戏并创建一个屏幕对象
    pygame.init()
    #生成游戏场景对象,screen对象,飞船,外星人,子弹,游戏状态,按钮,记分牌
    game_setting = Setting()
    screen = pygame.display.set_mode(
        (game_setting.screen_width, game_setting.screen_height))
    pygame.display.set_caption("Alien Invsion")
    bullets = []
    ship = Ship(screen)
    play_button = Button(screen, 'Play')
    stats = GameStats(game_setting)
    score_board = ScoreBoard(game_setting, screen, stats)
    aliens = []
    gf.create_alien_feet(game_setting, screen, ship, aliens)
    #开始游戏的主循环
    while True:
        #获取事件响应
        gf.check_event(game_setting, screen, ship, bullets, stats, play_button,
                       aliens)
        if stats.game_active:
            ship.update()
            gf.update_bullet(game_setting, screen, ship, bullets, aliens,
                             score_board, stats)
            gf.update_alien(game_setting, screen, bullets, aliens, ship, stats)
        gf.update_screen(game_setting, screen, ship, bullets, aliens,
                         play_button, stats, score_board)
Exemplo n.º 7
0
def run_game():
    # 初始化整个游戏对象
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Alien Invasion")

    # 创建一个用于统计游戏信息的实例
    stats = GameStats(ai_settings)

    # 创建一个飞船
    ship = Ship(ai_settings, screen)

    # 创建一个用于存储子弹的编组
    bullets = Group()

    # 创建一个外星人群组
    aliens = Group()
    gf.create_fleet(ai_settings, screen, ship, aliens)

    # 创建play按钮
    play_button = Button(ai_settings, screen, "play")

    # 游戏主循环
    while True:
        gf.check_events(ai_settings, screen, stats, play_button, ship, bullets)
        if stats.game_active:
            ship.update()
            gf.update_bullet(ai_settings, screen, ship, aliens, bullets)
            gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)
        gf.update_screen(ai_settings, screen, stats, ship, aliens, bullets,
                         play_button)
Exemplo n.º 8
0
def run_game():
    pygame.init()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Alien Invasion")
    ship = Ship(screen, ai_settings)

    bullets = Group()
    aliens = Group()

    gf.create_fleet(ai_settings, screen, aliens)

    while True:
        gf.check_events(ship, bullets, ai_settings, screen)
        ship.update()
        gf.update_bullet(bullets)
        gf.update_screen(ai_settings, screen, ship, bullets, aliens)
Exemplo n.º 9
0
def run_game():
    # Initialize the game and Create a screen object
    pygame.init()
    pygame.display.set_caption("Alien Invasion")
    # create a setting
    ai_setting = Setting()

    # create a screen
    screen = pygame.display.set_mode(
        (ai_setting.screen_width, ai_setting.screen_height))

    # create a stats for storing the information
    stats = GameStats(ai_setting)

    # create a scoreboard
    scoreboard = Scoreboard(ai_setting, screen, stats)
    # create a ship
    ship = Ship(ai_setting, screen)

    # create a bullet
    bullets = Group()

    # create the alien
    # alien = Alien(ai_setting, screen)
    aliens = Group()

    # create a play button
    play_button = Button(ai_setting, screen, "Play")

    gf.create_fleet(ai_setting, screen, ship, aliens)

    # Main Loop of game's beginning
    while True:
        # update the ship
        gf.check_events(ai_setting, screen, stats, scoreboard, play_button,
                        ship, aliens, bullets)
        if stats.game_active:
            ship.update()
            gf.update_bullet(ai_setting, screen, stats, scoreboard, ship,
                             aliens, bullets)
            gf.update_aliens(ai_setting, screen, stats, scoreboard, ship,
                             aliens, bullets)
        # show the update screen
        gf.update_screen(ai_setting, screen, stats, scoreboard, ship, aliens,
                         bullets, play_button)
Exemplo n.º 10
0
def run_game():
    pygame.init()
    screen = pygame.display.set_mode((ai_setting.screen_width, ai_setting.screen_height))
    pygame.display.set_caption(ai_setting.title)
    bg_color = ai_setting.bg_color
    ship = Ship(screen, ai_setting)
    bullet: Group = pygame.sprite.Group()
    aliens = Group()
    state = GameState(ai_setting)
    gf.create_fleet(screen, aliens, ai_setting, ship)
    play_buttom = Buttom(screen,"Play")

    while True:
        gf.check_events(ship,ai_setting,screen,bullet,play_buttom,state,aliens)
        if state.game_active is True:
            ship.update_ship()
            gf.update_bullet(bullet,aliens,screen,ai_setting,ship)
            gf.update_aliens(aliens,ai_setting,ship,state,bullet,screen)
        gf.update_screen(bg_color, screen, ship, bullet, aliens,state,play_buttom)
Exemplo n.º 11
0
def run_game():
    pygame.init()
    screen=pygame.display.set_mode(Settings().size)
    pygame.display.set_caption('外星人入侵')
    ship=Ship(screen,Settings())
    alien=Alien(screen,Settings())
    button=Button(Settings(), screen,'PLAY')
    stats=GameStats(Settings())
    score = GameScore(screen, Settings(), stats)
    bullets=Group()
    aliens=Group()
    gf.update_screen(Settings(), screen, ship, bullets, aliens, button,stats,score)
    while True:
        gf.check_events(ship, Settings(), screen, bullets,stats,button)
        if stats.game_start:
            gf.create_alien(Settings(), screen, aliens,stats)
            gf.update_bullet(bullets,Settings(),aliens,stats)

            gf.update_aliens(aliens,Settings(),ship,stats,bullets,screen)
            score.prep_score(stats.score,stats.max_score,stats.settings.copy_life)
            gf.update_screen(Settings(),screen,ship,bullets,aliens,button,stats,score)
Exemplo n.º 12
0
def run_game():
    pygame.init()
    settings = Settings()
    screen = pygame.display.set_mode((settings.screen_width,settings.screen_height))
    pygame.display.set_caption("外星人入侵")
    ship = Ship(screen)
    bullets = Group()
    aliens = Group()
    game_stats = Gamestat(settings)
    play_button = Button(screen,settings,"Play")
    score_broad = Score_broad(screen,settings)
    ship_life = Ship_life(screen,settings,game_stats)
    level = Level(screen,settings,game_stats)
    gf.create_aliens(screen,settings,aliens)
    while True:
        gf.check_event(screen,settings,ship,bullets,aliens,game_stats,play_button,ship_life)
        if game_stats.game_active:
            ship.update(settings)
            gf.update_bullet(screen,settings,bullets,aliens,game_stats,score_broad)
            gf.update_aliens(screen,settings,ship,bullets,aliens,game_stats,ship_life)
        gf.update_screen(screen,settings,ship,bullets,aliens,game_stats,play_button,score_broad,ship_life,level)
Exemplo n.º 13
0
def run_game():
    pygame.init()

    ai_setting = Setting()
    screen = pygame.display.set_mode(
        (ai_setting.screen_width, ai_setting.screen_height))
    pygame.display.set_caption('Alien Invasion')
    play_button = Button(ai_setting, screen, 'Play')
    ship = Ship(ai_setting, screen)
    bullets = Group()
    aliens = Group()
    stats = GameStats(ai_setting)
    gf.create_fleet(ai_setting, screen, ship, aliens)
    while True:
        gf.check_events(ai_setting, screen, stats,
                        play_button, ship, aliens, bullets)
        gf.update_screen(ai_setting, screen, stats, ship,
                             aliens, bullets, play_button)

        if stats.game_active:
            ship.update()
            gf.update_aliens(ai_setting, stats, screen, ship, aliens, bullets)
            gf.update_bullet(ai_setting, screen, ship, aliens, bullets)
Exemplo n.º 14
0
def run_game():
	pygame.init()

	# 导入设置参数
	my_settings = Settings()
	# 初始化屏幕并设置
	pygame.display.set_caption(my_settings.title)
	screen = pygame.display.set_mode((my_settings.screen_width, my_settings.screen_height))
	
	# 创建一个用于存储游戏统计信息的实例
	stats = GameStats(my_settings)
	
	# 创建一艘飞船
	ship = Ship(my_settings, screen)
	
    # 创建子弹组
	bullets = Group()

    # 创建初始外星人族群
	aliens = Group()
	gf.create_fleet(my_settings, screen, ship, aliens)

	# 创建Play按钮
	play_button = Button(my_settings, screen, "Play")

	# 创建记分牌
	sb = Scoreboard(my_settings, screen, stats)


	# 开始游戏的主循环
	while True:
		gf.check_event(my_settings, stats, screen, sb, ship, bullets, play_button)
		if stats.game_active:
			ship.update()
			gf.update_bullet(my_settings, stats, screen, sb, ship, aliens, bullets)
			gf.update_aliens(my_settings, stats, screen, sb, ship, aliens, bullets)
		gf.update_screen(my_settings, screen, stats, sb, ship, aliens, bullets, play_button)
Exemplo n.º 15
0
def run_game():
    # 初始化游戏,并创建一个屏幕对象
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption('Alien Invasion')
    # 创建飞船
    ship = Ship(ai_settings, screen)
    # 创建一个用于存储外星人的编组
    aliens = Group()
    # 创建外星人群
    gf.create_fleet(ai_settings, screen, aliens)
    # 创建一个用于存储子弹的编组
    bullets = Group()

    # 开始游戏的主循环
    while True:
        # 监视键盘和鼠标事件
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        gf.update_bullet(bullets)
        # 重绘屏幕
        gf.update_screen(ai_settings, screen, ship, bullets,aliens)