import os

from characters import *
from locations import *
from items import *
from helpers import Dice

def choose_location():
    global current_location
    print(f'Dostępne lokacje: {locations[current_location]}')
    goto = input("Idź do: ")
    for l in locations[current_location]:
        if l.name == goto:
            current_location = l
            return
    print("Niepoprawna lokacja")
    choose_location()
def check_win(place, items):
    if place != catedral:
        return False
    
    if key not in items:
        return False
    
    if map not in items:
        return False
    
    if flower not in items:
        return False
    
    return True

#special items
key = Item("Magiczny Klucz")
map = Item("Tajemna Mapa Skarbów")
flower = Item("Kwiat paproci")

road.items.append(key)
village.items.append(map)
forest.items.append(flower)

locations = {
    road : [village],
    village : [forest, road],
    forest : [cave, village],
    cave : [forest, catedral],
    catedral : [cave]
}

current_location = road

player = Player("Juzek")
print(f"{player.name}, Witaj podróżniku!")
current_location.enter(player)

#testowanie wygranej
#player.inventory.extend([key, map, flower])

while player.is_alive():
    os.system('cls')
    choose_location()
    current_location.enter(player)

    if not player.is_alive():
        break

    if check_win(current_location, player.inventory):
        break

if player.is_alive():
    print("Zgłębiłeś tajemnice skrywane w tej grze... Gratulacje, Wygrałeś!")
else:
    print("GAME OVER")