示例#1
0
def main():
    if len(sys.argv) != 3:
        print(
            "Wrong number of arguments: ./project2.py, <path to csv file>, <year for which u want diagrams>"
        )
        exit(1)

    # Czytanie nazwy/sciezki do pliku
    try:
        filename = sys.argv[1]
    except IndexError as error:
        print("Problem with reading a path to file:", error)
        exit(1)

    open_and_parse_csvfile(filename)  # Parsowanie pliku

    # Czytanie i parsowanie roku
    try:
        year = sys.argv[2]
        year_int = int(year)
        if year_int < 1998 or year_int > 2012:
            print("Year should be between 1998 and 2012.")
            exit(1)
    except IndexError as error:
        print("Problem with reading year for diagrams:", error)
        exit(1)
    except ValueError as error:
        print("Year is not a int:", error)
        exit(1)

    # Zmienne do rysowania
    state_array = []
    total_production_array = []
    production_value_array = []

    # Wyciagam dane do wykresu dla danego roku
    for elem in object_array:
        if elem.get_state(year_int) is not False:
            state_array.append(elem.get_state(year_int))
        if elem.get_total_production(year_int) is not False:
            total_production_array.append(elem.get_total_production(year_int))
        if elem.get_production_value(year_int) is not False:
            production_value_array.append(elem.get_production_value(year_int))

    # Rysuje wykresy
    print("In case you forgot, diagrams are for year:", year)
    drawer1 = Drawer("total production", state_array, total_production_array)
    drawer1.draw_bar()
    drawer2 = Drawer("production value", state_array, production_value_array)
    drawer2.draw_bar()
示例#2
0
    def run_game(self, data=None):
        self._player = Player(Constants.GAME_WINDOW_WIDTH // 2,
                              Constants.GAME_WINDOW_HEIGHT // 2,
                              animation_images=Textures.PLAYER,
                              saved_params=data)

        text = None
        test_cur = None
        test_max = None

        clock = pygame.time.Clock()
        is_game_exit = False
        while not is_game_exit:
            pygame.event.pump()

            for enemy in self._enemies:
                if pygame.sprite.collide_rect(self._player, enemy):
                    now = pygame.time.get_ticks()
                    if now - enemy._last_attack_time > enemy._attack_interval:
                        enemy._last_attack_time = now
                        self._player.current_health -= enemy.amount_damage
                        if self._player.current_health < 1:
                            return self.game_over()

            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:
                        self.show_pause_menu()
                    if event.key == pygame.K_F5:
                        self.save_game([self._player])
                    if event.key == pygame.K_F9:
                        self.load_game()
                    if event.key == pygame.K_SPACE:
                        shells = self._player.attack()
                        self._shells.extend(shells)
                    if event.key == pygame.K_i:
                        self._player.show_inventory(self._main_game_window)
                    if event.key == pygame.K_c:
                        self._player.change_weapon()

            self._main_game_window.fill(int())

            self._map.update(self._main_game_window)
            for tile in self._map.map_tiles:
                offset = self._camera.offset
                tile.rect.centerx -= offset[0]
                tile.rect.centery -= offset[1]

            for chest in self._chests:
                offset = self._camera.offset
                chest.rect.centerx -= offset[0]
                chest.rect.centery -= offset[1]
                chest.update(self._main_game_window)
                if pygame.sprite.collide_rect(
                        self._player,
                        chest) and pygame.key.get_pressed()[pygame.K_e]:
                    additional_potions = chest.open(
                        self._player.is_key_in_inventory())
                    if additional_potions is not None:
                        for additional_thing in additional_potions:
                            if additional_thing != 0:
                                self._things.append(additional_thing)

            for potion in self._things:
                if potion:
                    potion.update(self._main_game_window)
                    offset = self._camera.offset
                    potion.rect.centerx -= offset[0]
                    potion.rect.centery -= offset[1]

                    if pygame.sprite.collide_rect(
                            self._player,
                            potion) and pygame.key.get_pressed()[pygame.K_e]:
                        self._player.append_thing_to_inventory(potion)
                        self._things.remove(potion)

            for neutral in self._neutrals:
                if pygame.sprite.collide_rect(
                        self._player,
                        neutral) and pygame.key.get_pressed()[pygame.K_e]:
                    self._quests.append(neutral.quest)
                    neutral.vision_quest_mark = False

            offset = self._camera.offset
            for neutral in self._neutrals:
                neutral.update(self._main_game_window)
                neutral.rect.centerx -= offset[0]
                neutral.rect.centery -= offset[1]

            for tree in self._trees:
                tree.update(self._main_game_window)
                offset = self._camera.offset
                tree.rect.centerx -= offset[0]
                tree.rect.centery -= offset[1]

            for shell in self._shells:
                if shell:
                    shell.update(self._main_game_window)
                    offset = self._camera.offset
                    shell.rect.centerx -= offset[0]
                    shell.rect.centery -= offset[1]

            for enemy in self._enemies:
                enemy.attack(self._player.rect.centerx,
                             self._player.rect.centery)
                offset = self._camera.offset
                enemy.rect.centerx -= offset[0]
                enemy.rect.centery -= offset[1]
                enemy.update(self._main_game_window)
                enemy.attack(self._player.rect.centerx,
                             self._player.rect.centery)

            for enemy in self._enemies:
                for shell in self._shells:
                    if shell:
                        if pygame.sprite.collide_rect(enemy, shell):
                            self._shells.remove(shell)
                            enemy.current_health -= self._player.amount_damage
                            enemy.current_health -= shell.amount_additional_damage

                            dx = float(self._player.rect.centerx -
                                       enemy.rect.centerx)
                            dy = float(self._player.rect.centery -
                                       enemy.rect.centery)
                            length = math.sqrt(dx**2 + dy**2)
                            enemy.is_enemy_angry = True
                            enemy.show_aggression_to_attack_player(
                                dx, dy, length)

                            text = enemy.name
                            test_cur = enemy.current_health
                            test_max = enemy.max_amount_health
                            if enemy.current_health < 0:
                                self._player.current_experience += enemy.experience_for_killing

                                if enemy in self._enemies:
                                    self._enemies.remove(enemy)
                                text = None
                                test_cur = None
                                test_max = None

            self._camera.update(self._player)
            self._player.update(self._main_game_window)

            for quest in self._quests:
                if not self._enemies:
                    quest.completed = True
                    self._player.current_experience += quest.experience
                    if quest not in self._names_done_quests:
                        self._names_done_quests.append(quest.title)
                    self._quests.remove(quest)

            if text is not None:
                Drawer.draw_bar(self._main_game_window,
                                Constants.GAME_WINDOW_WIDTH // 2, 10,
                                Constants.UNNAMED_COLOR_HEALTH_BAR, test_cur,
                                test_max, 150, 15)
                Drawer.draw_text(self._main_game_window, text, 25,
                                 Constants.WHITE_COLOR_TITLE_BLOCKS,
                                 Constants.GAME_WINDOW_WIDTH // 2, 9)

            Drawer.draw_text(
                self._main_game_window, self._player.name, 15,
                Constants.WHITE_COLOR_TITLE_BLOCKS, self._player.rect.centerx,
                self._player.rect.centery + self._player.rect.height // 2 + 5)
            Drawer.draw_bar(self._main_game_window,
                            Constants.GAME_WINDOW_WIDTH // 2,
                            Constants.GAME_WINDOW_HEIGHT * 0.86,
                            Constants.WHITE_COLOR_TITLE_BLOCKS,
                            self._player.current_experience,
                            self._player.experience_up_level, 310, 5, True)
            Drawer.draw_bar(self._main_game_window,
                            Constants.GAME_WINDOW_WIDTH // 2 - 70,
                            Constants.GAME_WINDOW_HEIGHT - 70,
                            Constants.STAMINA_BAR_COLOR,
                            self._player.current_stamina,
                            self._player.max_stamina, 90, 14, True)

            pygame.display.flip()  # for double buffering
            clock.tick(Constants.FPS_LOCKING)
        pygame.quit()