Beispiel #1
0
def create_new_map_segment():

    map = create_map_base(size)
    Logger.all_log("map bluprint found" + Logger.lineno())
    set_enimies(map, prob_one, prob_mult, max)
    Logger.all_log("map segment has been populated with enimies")
    return map
    def entry(self):

        os.system("cls")
        running_shop_loop = True
        print("Shop \nYour coins = " + str(PLAYER[5]))

        for i in WEAPONS:
            if i[NAME] != "hand":
                print(i[NAME] + "\tprice: " + str(i[PRICE]))

        while running_shop_loop:

            shop_command = input(": ").lower()

            if shop_command in shop_commands:
                running_shop_loop = shop_commands[shop_command]()

                if running_shop_loop:
                    True

                elif not running_shop_loop:
                    print("You Leave the shop")

                else:
                    Logger.all_log("Error code 2 in shop.py" + Logger.lineno())
                    sys.exit("Exit code 3")

            else:
                print("this command is invalid. Type -help- to see the shop commands. ")
Beispiel #3
0
def load(extra=None):
    if extra is not None:
        namedata = extra
        extra = None
    else:
        namedata = input(
            "Please enter the name of the saved character: ").lower()
    if namedata == "help":
        match = re.findall(r"([A-z]+\s?)*(?=_data)",
                           str(os.listdir("Saved_Games")))
        metch = []
        x = int(len(match) / 2)
        for i in range(x):
            metch.append('')
        match = list(set(match) - set(metch))
        print("Saved games are " + str(match))
        load()

    data = saved_file_loc("name", namedata)
    cfg.read(data)

    # check ob die file exsistiert
    if os.path.isfile(data):
        # hier werde (vllt?) ich ein backup der file erstellen lassen
        pass
    elif os.path.isfile(data) is False:
        # beendet den load vorgang und startet die eingabe erneut
        print("Dieser Speicherstand ist nicht vorhanden")
        if extra:
            game_load()
            return
        else:
            # Lösung Problem Nr. 0
            eingabe()
            return
    else:
        # diesen teil darf es auf keinen fall erreichen sonst ist bool weder True noch False
        Logger.all_log("Error 2 in main.py" + Logger.lineno())
        sys.exit(
            "Process finished with Error code 2 in main.py/load siehe log")

    # Playerdaten
    characters.PLAYER[characters.NAME] = cfg.get("config_TA", "player")
    characters.savelanguage = cfg.get("config_TA", "language")
    characters.PLAYER[characters.COINS] = float(cfg.get("config_TA", "coins"))
    characters.savetime = float(cfg.get("config_TA", "time"))
    characters.PLAYER[characters.HEALTH] = float(cfg.get("config_TA", "HP"))
    player = {}
    player["name"] = cfg.get("config_TA", "player")
    player["money"] = cfg.get("config_TA", "coins")
    player["health"] = cfg.get("config_TA", "hp")
    """print(player)"""
    # Skilldaten
    characters.PlayerFightEp = float(cfg.get("config_Skill", "AttackEP"))
    characters.fightlevel = int(cfg.get("config_Skill", "Attacklevel"))
    characters.skillfightlevel[characters.fightlevel] = True
    print("Speicherstand " + namedata + " erfolgreich geladen")
    # Lösung Problem Nr. 0
    eingabe()
Beispiel #4
0
def saved_file_loc(data="name", name=characters.PLAYER[characters.NAME]):
    if name == "" or name is None:
        name = characters.PLAYER[characters.NAME]
    else:
        pass
    if data == "name":
        save_file_name = os.path.join("Saved_Games", name + "_data",
                                      "Config_TA_" + name + ".ini")
    elif data == "map":
        save_file_name = os.path.join("Saved_Games", name + "_data",
                                      "map_" + name + ".ini")
    else:
        saved_file_loc("name", name)
    Logger.all_log("Name of folder and save " + save_file_name +
                   Logger.lineno())
    return save_file_name
Beispiel #5
0
def game_load():
    first = input("new game or load game? : ").lower().split(" ")
    new_game = ["new", "New", "new game", "New game", "New Game"]
    load_game = ["load", "Load", "load game", "Load game", "Load Game"]
    if first[0] in new_game:
        buffer = input("Enter your name: ").lower()
        # liste mit nicht gültigen namen - exsistieren schon oder ist leer -> ""
        # #dies können wir auch beleibig erweitern
        buffer_not = re.findall(r"(?<=Config_TA_)(\w+\s?)*(?=\.ini)",
                                str(os.listdir("Saved_Games")))
        # hier können wir Bestimmte eingaben verhindern
        buffer_not_valid = ["", " ", "bennexy", "help"]
        # print(buffer, buffer_not)

        # hier überprüfen wir ob der name schon vergeben ist
        if buffer not in buffer_not and buffer not in buffer_not_valid:
            characters.PLAYER[characters.NAME] = buffer
        elif buffer == "help":
            print("The names " + str(buffer_not) + " are allready taken")
            print("The names " + str(buffer_not_valid) + " are not Valid")
            game_load()
        elif buffer in buffer_not:
            print("Name is allready taken")
            game_load()
        elif buffer in buffer_not_valid:
            print("Name is not Valid")
            game_load()
        else:
            Logger.all_log("Error 2 in main.py" + Logger.lineno())
            sys.exit(
                "Process finished with error code 2 main.py/game_load siehe log"
            )

        print("Player Charakter " + characters.PLAYER[characters.NAME] +
              " made")
        pass
    elif first[0] in load_game:

        if len(first) != 1:
            extra = first[1]
        else:
            extra = None
        load(extra)
    else:
        print("Command not found")
        game_load()
Beispiel #6
0
    def shop_help(self):

        key_value = ""
        for i in self.commands:

            if type(i) == list:
                key_value = key_value + "-" + i[0] + ", "
            elif type(i) == str:
                try:
                    i = int(i)
                    pass
                except:
                    i = str(i)
                    key_value = key_value + "-" + i + "- "
            else:
                Logger.all_log("Error 3 in shop.py " + Logger.lineno())
                sys.exit("TypeError in shop.py")
        print(key_value)
Beispiel #7
0
def game_help():
    key_value = ""
    for i in commands.keys():

        if type(i) == list:
            key_value = key_value + "-" + i[0] + ", "
        elif type(i) == str:
            try:
                i = int(i)
                pass
            except:
                i = str(i)
                key_value = key_value + "-" + i + "- "
        else:
            Logger.all_log("Error 3 in main.py " + Logger.lineno())
            sys.exit("TypeError in main.py")
    print(key_value)
    eingabe()
def buy():

    global COINS

    def buy_item():
        item = input("Item that you want to buy : ").lower()
        if item in WEAPONS:
            return item
        elif item == "quit" or item == "leave":
            return False
        elif item == "help":
            print(
                "enter the name of the item you want to buy or -quit- to leave the shop"
            )
            buy_item()
        else:
            print("This item doesn't exist.")
            buy_item()

    buy_item_name = buy_item()
    if buy_item_name:

        for i in WEAPONS:

            if i[NAME] == buy_item_name:
                if PLAYER[COINS] >= i[PRICE]:
                    PLAYER[COINS] = int(PLAYER[COINS]) - int(i[PRICE])
                    putinv(buy_item_name)
                    print("you bought " + buy_item_name +
                          "and stored it in your backpack")
                    return True
                else:
                    print("You don't have not enough money")
                    return True

    elif not buy_item_name:
        return False
    else:
        Logger.all_log("Error code 2 in shop.py" + Logger.lineno())
        sys.exit("Exit code 3")
Beispiel #9
0
def quiter():
    Logger.all_log("Exit code 2" + Logger.lineno()) + sys.exit(
        print("You commit suicide and leave this world."))
Beispiel #10
0
def save(extra=None):
    global interim

    # von Datei time rauslesen wenn sie existiert
    # Überprüfung ob der Speicherstan vorhanden ist

    save_file = saved_file_loc()
    save_file_map = saved_file_loc("map")
    if os.path.isfile(save_file):
        ueberschrieben = input("Spielstand Überschreiben? (J/N): ")

        if ueberschrieben == "J" or ueberschrieben == "j":
            Backup(save_file)
            Backup(save_file_map)
        elif ueberschrieben == "N" or ueberschrieben == "n" and extra is None:
            print("Saving canceled")
            eingabe()
        elif ueberschrieben == "N" or ueberschrieben == "n" and extra is not None:
            sys.exit("By")
        else:
            print("Unknown Input")
            if extra is None:
                save()
            else:
                save(extra)
    else:
        Logger.all_log("Dir muss erst erstellt werden" + Logger.lineno())

    print("Game is Saving")
    tosavetime = interim + characters.savetime

    cfg["config_TA"] = {
        "Player": characters.PLAYER[characters.NAME],
        "language": "en",
        "coins": characters.PLAYER[characters.COINS],
        "time": tosavetime,
        "HP": characters.PLAYER[characters.HEALTH]
    }
    cfg["config_Game"] = {}  # Rest Zeit usw. Map Größe
    cfg["config_Skill"] = {
        "Attacklevel": characters.fightlevel,
        "AttackEP": characters.PlayerFightEp
    }  # Alles zu Skills

    with open(saved_file_loc(), "w") as file:
        cfg.write(file)

    cfgmap["mapdata"] = {"mapdata": "test"}

    with open(saved_file_loc("map"), "w") as file:
        cfgmap.write(file)

    Logger.all_log("Pending game saved" + Logger.lineno())

    if extra == "end":
        Logger.all_log("Exit code 0" + Logger.lineno())
        sys.exit("Byby")
    elif extra is None:
        eingabe()
    else:
        Logger.all_log("passed argument to save is not known")
        pass