class PyForce:
    def __init__(self):
        pygame.init()
        self.screen = pygame.display.set_mode(RESOLUTION)
        pygame.display.set_caption(CAPTION)
        self.clock = pygame.time.Clock()
        self.sfx = Sfx()
        self.rand = Random()
        self.battlefield = BattleField(self.screen, self.sfx, self.rand)
        if FPS_ENABLED:
            self.fps = FPS(self.screen, self.clock)
        self.status = 'game'
        if DEBUG:
            print 'init : main'
            import sys
            print sys.version[:6]

    def run(self):
        while self.status != 'quit':
            # check quit
            for event in pygame.event.get():
                if event.type == QUIT:
                    self.status = 'quit'
                elif event.type == KEYDOWN:
                    if event.key == K_ESCAPE:
                        self.status = 'quit'

            # select status
            if self.status == 'intro':
                self.intro()
            elif self.status == 'game':
                self.game()
            elif self.status == 'win':
                img = pygame.image.load('res/img/end.png').convert()
                self.screen.blit(img, (0, 0))

            pygame.display.update()
            self.clock.tick(FPS_LIMIT)
        else:
            if DEBUG: print 'user prompt quit'
            

    def game(self):
        self.battlefield.update()
        if self.battlefield.status == 'win':
            self.status = 'win'
        if FPS_ENABLED:
            self.fps.update()
Exemplo n.º 2
0
            if Event.menu:  # если пользователь находится в меню
                if event.type == pygame.MOUSEBUTTONUP:
                    Event.event_menu(Menu, pos, Select)
            elif Event.settings:  # если пользователь находится в настройках
                if event.type == pygame.MOUSEBUTTONUP:
                    Event.event_settings(Menu, pos)
            elif Event.select:  # если пользователь находится в окне выбора
                if event.type == pygame.MOUSEBUTTONDOWN:
                    Event.select_window(pos, Select, event, AI, player_1,
                                        player_2, BF, Menu)
            elif Event.game:  # если пользователь находится играет
                if Menu.game_type == 'PvP':  # если включен режим игрок против игрока
                    if Event.ready:  # если игрок готов
                        if event.type == pygame.MOUSEBUTTONDOWN:
                            Event.attack(pos, BF)
                            BF.update()
                    else:
                        BF.draw_preparation_field()
                        if event.type == pygame.MOUSEBUTTONDOWN and BF.ready_button.rect.collidepoint(
                                pos):
                            Event.preparation(BF)
                else:  # если включен режим игрок против компьютера
                    if BF.player == player_1:  # если ход пользователя
                        if Event.ready:  # если игрок готов
                            if event.type == pygame.MOUSEBUTTONDOWN:
                                Event.attack(pos, BF)
                                BF.update()
                        else:
                            Event.ready = True
                            BF.swap()