Exemplo n.º 1
0
def run_game():
	pygame.init()
	#实例化一个Settings对象,对象名为ai_settings
	ai_settings = Settings()
	#set_mode()返回的surface表示整个游戏窗口
	screen = pygame.display.set_mode((ai_settings.screen_width,ai_settings.screen_height))
	pygame.display.set_caption("Alien Invasion ding")	
	#创建一艘飞船
	ship = Ship(ai_settings,screen)
	#创建一个用于存储子弹的编组
	bullets = Group()
	#创建一个外星人编组
	aliens = Group()
	#创建外星人群
	gf.create_fleet(ai_settings,screen,ship,aliens)
	#创建一个用于统计游戏信息的实例
	stats = GameStats(ai_settings)
	#创建积分牌
	sb = Scoreboard(ai_settings,screen,stats)
	#创建play按钮
	play_button = Button(ai_settings,screen,"play")
	
    #开始游戏的主循环,
	while True:
		#监视键盘和鼠标事件
		gf.check_events(ai_settings,screen,stats,play_button,ship,aliens,bullets)
		if stats.game_active:
			#更新飞船的位置
			ship.update()
			#更新子弹的位置,并删除已消失的子弹
			gf.update_bullets(ai_settings,screen,stats,sb,ship,aliens,bullets)
			gf.update_aliens(ai_settings,stats,screen,ship,aliens,bullets)
		#更新屏幕上的图像,并切换到新屏幕
		gf.update_screen(ai_settings,screen,stats,sb,ship,aliens,bullets,play_button)
Exemplo n.º 2
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")
    # 创建play按钮
    play_button = Button(ai_settings, screen, "PLAY")
    # 创建一个用于存储游戏统计信息的实例并创建记分牌
    stats = GameStats(ai_settings)
    scoreboard = Scoreboard(ai_settings, screen, stats)

    # 创建一个飞船
    ship = Ship(ai_settings, screen)
    # 创建一个用于存储子弹的编组
    bullets = Group()
    aliens = Group()
    gf.create_fleet(ai_settings, screen, ship, aliens)
    # 开始游戏主循环
    while True:
        gf.check_events(ai_settings, screen, stats, play_button, ship, aliens, bullets, scoreboard)
        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, ship, aliens, bullets, stats, scoreboard)
            gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets, scoreboard)
        gf.update_screen(ai_settings, screen, stats, ship, bullets, aliens, play_button, scoreboard)
Exemplo n.º 3
0
def run_game():
    pygame.init()
    new_setting = Settings_1()
    screen = pygame.display.set_mode((new_setting.screen_width,
    new_setting.screen_height))
    pygame.display.set_caption("Alian Invasion")
    #创建一个play按钮
    play_button = Button(new_setting,screen,"Play")
    #创建一个用于存储游戏统计信息的实例
    stats = GameStats(new_setting)
    #创建存储游戏统计信息的实例,并创建记分牌
    sb = Scoreboard(new_setting,screen,stats)
    #创建一艘飞船
    ship = Ship(new_setting,screen)
    #创建一个用于存储子弹的编组
    bullets = Group()
    #创建一个外星人
    #alien = Alien(new_setting,screen)
    aliens = Group()
    gf.create_fleet(new_setting,screen,ship,aliens)
    #游戏主循环
    while True:
        #监视键盘和鼠标事件
        gf.check_events(new_setting,screen,stats,sb,play_button,ship,aliens,bullets)
        if stats.game_active:
            ship.update()
            gf.update_bullets(new_setting,screen,stats,sb,ship,aliens,bullets)
            gf.update_aliens(new_setting,stats,sb,screen,ship,aliens,bullets)
        #print(len(bullets))  主句代码用于监测是否所有的子弹都被删除了   
        #让最近绘制的屏幕可见
        gf.update_screen(new_setting,screen,stats,sb,ship,aliens,bullets,play_button)
def run_game():
    #初始化pygame,设置和屏幕对象
    pygame.init()
    ai_sett = AlienSett()
    screen = pygame.display.set_mode(
        (ai_sett.screen_width, ai_sett.screen_height))
    pygame.display.set_caption("Press P to start")

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

    #创建一个用于存储游戏统计信息的实例
    stats = GameStats(ai_sett)
    sb = Scoreboard(ai_sett, screen, stats)

    #创建一艘飞船、一个子弹编组和一个外星人编组
    ship = Ship(screen, ai_sett)
    bullets = Group()
    aliens = Group()

    # 创建外星人群
    gf.create_fleet(ai_sett,screen,ship,aliens)


    #开始游戏主循环
    while True:
        #监视键盘和鼠标事件
        gf.check_events(ai_sett, screen, stats, play_button, ship, aliens, bullets)

        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_sett, screen, stats, sb, ship, aliens, bullets)
            gf.update_aliens(ai_sett, screen, stats,  ship, aliens ,bullets)
            gf.update_screen(ai_sett, screen, stats, sb, ship, aliens, bullets,  play_button)
Exemplo n.º 5
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 War")
    play_button = Button(ai_settings, screen, "Play")
    stats = GameStats(ai_settings)
    sb = ScoreBoard(ai_settings, screen, stats)
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()
    f.create_fleet(ai_settings, screen, ship, aliens)
    # Назначение цвета фона
    bg_color = (100, 100, 100)
    alien = Alien(ai_settings, screen)
    while True:
        f.check_events(ai_settings, screen, stats, sb, play_button, ship,
                       aliens, bullets)
        if stats.game_active:
            ship.update()
            f.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
                             bullets)
            f.update_aliens(ai_settings, screen, stats, sb, ship, aliens,
                            bullets)
        f.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets,
                        play_button)
Exemplo n.º 6
0
    def __init__(self):
        """Initaialize the game"""
        pygame.init()
        self.settings = Settings()

        #Screen windows mode
        self.screen = pygame.display.set_mode(
            (self.settings.screen_width, self.settings.screen_height))

        pygame.display.set_caption('Alien Invasion')

        #Create an instaance to store game statistics
        # and create scoreboard

        self.stats = GameStats(self)
        self.sb = Scoreboard(self)

        self.ship = Ship(self)
        self.bullets = pygame.sprite.Group()
        self.aliens = pygame.sprite.Group()

        #Look for aliens-ship collisions

        self._create_fleet()

        #Make play button
        self.play_button = Button(self, "Play")