"""Учебная реконструкция консольной игры «Побег из замка».""" import random PLAYER_HP = 10 WIN_ITEM = "отмычка" WIN_ROOM = "чердак" ROOMS = ["кухня", "библиотека", "подвал", "ванная", "гараж", "спальня", "чердак"] ENEMIES = ["призрак", "крыса", "тень", "паук", "зомби"] ITEMS = { "отмычка": "Открывает замок на чердаке.", "фонарик": "Помогает ориентироваться в тёмном замке.", "аптечка": "Восстанавливает 4 HP.", "карта": "Показывает, где находится выход.", "записка": "Содержит подсказку о побеге.", "меч": "Помогает победить дракона.", "шоколадка": "Восстанавливает 2 HP.", } def show_status(hp, inventory, current, turns): print(f"\nКомната: {current} | HP: {hp} | Ходы: {turns}") print("Инвентарь:", ", ".join(inventory) if inventory else "пусто") if "карта" in inventory: print(f"На карте отмечен выход: {WIN_ROOM}.") def find_item(inventory, found_items): available = [] for item in ITEMS: if item not in found_items: available.append(item) if not available: return None item = random.choice(available) inventory.append(item) found_items.append(item) return item def use_item(inventory, hp, current, dragon_alive): item = input("Какой предмет использовать? ").strip().lower() if item not in inventory: print("Такого предмета у тебя нет.") elif item == "аптечка": hp = min(PLAYER_HP, hp + 4) inventory.remove(item) print("Ты применил аптечку. Теперь у тебя", hp, "HP.") elif item == "шоколадка": hp = min(PLAYER_HP, hp + 2) inventory.remove(item) print("Ты съел шоколадку. Теперь у тебя", hp, "HP.") elif item == "меч": if current == WIN_ROOM and dragon_alive: dragon_alive = False print("Ты победил дракона мечом!") else: print("Ты проверил меч. Пока сражаться не с кем.") elif item == "карта": print("Карта показывает: выход находится в комнате «чердак».") elif item == "записка": print("На записке написано: «Дракон боится меча, а дверь — отмычки».") elif item == "фонарик": print("Фонарик осветил комнату. Попробуй команду «осмотреть».") elif item == WIN_ITEM: print("Отмычка пригодится у выхода на чердаке.") return hp, dragon_alive hp = PLAYER_HP inventory = [] found_items = [] searched_rooms = [] current_room = "кухня" dragon_alive = True turns = 0 print("ПОБЕГ ИЗ ЗАМКА") print("Найди меч и отмычку, победи дракона на чердаке и открой выход.") print("Команды: осмотреть / идти / использовать / выход") while hp > 0: show_status(hp, inventory, current_room, turns) command = input("Что делать? ").strip().lower() if command == "осмотреть": if current_room in searched_rooms: print("Ты уже осмотрел эту комнату.") else: searched_rooms.append(current_room) item = find_item(inventory, found_items) if item is None: print("Ничего нового здесь нет.") else: print("Ты нашёл предмет:", item) print(ITEMS[item]) turns += 1 elif command == "идти": print("Куда можно пойти:", ", ".join(ROOMS)) next_room = input("Название комнаты: ").strip().lower() if next_room not in ROOMS: print("Такой комнаты нет.") elif next_room == current_room: print("Ты уже здесь.") else: current_room = next_room turns += 1 print("Ты вошёл в комнату:", current_room) if current_room == WIN_ROOM and dragon_alive: hp -= 2 print("На тебя напал дракон! Ты потерял 2 HP.") elif random.randint(1, 3) == 1: enemy = random.choice(ENEMIES) hp -= 1 print("На тебя напал", enemy + "! Ты потерял 1 HP.") elif command == "использовать": hp, dragon_alive = use_item(inventory, hp, current_room, dragon_alive) turns += 1 elif command == "выход": print("Игра остановлена. До встречи!") break else: print("Неизвестная команда. Попробуй ещё раз.") if hp <= 0: print("У тебя закончились HP. Game over!") break if current_room == WIN_ROOM and WIN_ITEM in inventory and not dragon_alive: print("Ты открыл дверь отмычкой и сбежал из замка!") print("Победа! Ходов сделано:", turns) break