206530235/游戏结束4

44 lines
1.6 KiB
Plaintext

class GameSta():
def __init__(self,ai_settings):
self.ai_settings=ai_settings
self.reset_sta()
self.game_active=True
def reset_sta(self):
self.ship_counts=self.ai_settings.ship_limit
self.ship_limit=3
from game_sta import GameSta
sta=GameSta(ai_settings)
gf.update_aliens(ai_settings,aliens,screen,ship,bullets,sta)
def ship_col(ai_settings, aliens, screen, ship, bullets, sta):
if sta.ship_counts > 0:
sta.ship_counts -= 1
aliens.empty()
bullets.empty()
creat_aliens(ai_settings, screen, aliens, ship)
ship.ship_center()
sleep(1)
else:
sta.game_active = False
def check_aliens_bottom(ai_settings, aliens, screen, ship, bullets, sta):
for alien in aliens.sprites():
if alien.rect.bottom >= screen.get_rect().bottom:
ship_col(ai_settings, aliens, screen, ship, bullets, sta)
break
def update_aliens(ai_settings, aliens, screen, ship, bullets, sta):
check_aliens_edge(ai_settings, aliens)
aliens.update()
if pygame.sprite.spritecollideany(ship, aliens):
ship_col(ai_settings, aliens, screen, ship, bullets, sta)
check_aliens_bottom(ai_settings, aliens, screen, ship, bullets, sta)
def ship_center(self):
self.center = self.screen_rect.centerx
while True:
gf.check_events(ship, ai_settings, screen, bullets)
if sta.game_active:
ship.update()
gf.update_bullets(ai_settings, screen, ship, bullets, aliens)
gf.update_aliens(ai_settings, aliens, screen, ship, bullets, sta)
gf.update_screen(ai_settings, screen, ship, bullets, aliens)