import sys
import pygame
from settings import Settings
from ship import Ship

class AlienInvasion:
    """Overall class for the game"""
    def __init__(self):
        """Initialize game and create resources"""
        pygame.init()
        self.clock = pygame.time.Clock()
        self.settings = Settings()
        self.screen = pygame.display.set_mode((self.settings.screen_width, self.settings.screen_height))
        pygame.display.set_caption("Alien Invasion")
        self.ship = Ship(self)

    def run_game(self):
        """Start main game loop"""
        while True:
            #Listen for events
            self._check_events()
            self._update_screen()
            self.clock.tick(60)

    def _check_events(self):
        """Respond to keypresses and mouse events"""
        for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()
    
    def _update_screen(self):
        self.screen.fill(self.settings.bg_color)   
        self.ship.blitme()  
        # refresh display
        pygame.display.flip()

if __name__ == '__main__':
    # Create game instance and run game
    ai = AlienInvasion()
    ai.run_game()