import sys import pygame from common.constants import * from common.helpers import print_numbers from logic.level import Level from ui.logs import Logs from ui.screens.credits import Credits from ui.screens.main_menu import MainMenu from ui.screens.options import Options from ui.stats import Stats class Game: def __init__(self): pygame.init() pygame.display.set_caption(GAME_TITLE) pygame.display.set_icon(pygame.image.load('./resources/icons/sword.png')) self.screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT)) self.logs = Logs(self.screen) self.clock = pygame.time.Clock() self.bg = pygame.image.load("./resources/textures/bg.jpg") self.screens = {'credits': Credits(self.screen, self.clock), 'options': Options(self.screen, self.clock)} self.level = Level(self.screen, self.logs) def main_menu(self): menu = MainMenu(self.screen, self.clock, self.bg, self.game, self.screens['options'].display_screen, self.screens['credits'].display_screen) menu.display_screen() def game(self): stats = Stats() # setup clock for rounds NEXT_TURN = pygame.USEREVENT + 1 pygame.time.set_timer(NEXT_TURN, TURN_INTERVAL) # create level self.level.create_map() print_numbers_flag = False running = True while running: self.screen.blit(self.bg, (0, 0)) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: running = False if event.key == 110: # clicked n letter on keyboard print_numbers_flag = not print_numbers_flag if event.type == NEXT_TURN: # is called every 'TURN_INTERVAL' milliseconds self.level.handle_turn() stats.draw(self.screen) self.logs.draw() self.level.update() if print_numbers_flag: print_numbers() pygame.display.update() self.clock.tick(FPS_COUNT)