Пример #1
0
    def start_map_maker(screen, map_to_pull: MapYXZ):

        # set default curses colors
        cyan = set_colors(screen, curses, 'cyan')
        yellow = set_colors(screen, curses, 'yellow')
        green = set_colors(screen, curses, 'green')
        red = set_colors(screen, curses, 'red')
        # blue = set_colors(screen, curses, 'blue')
        # white = set_colors(screen, curses, 'white')
        # magenta = set_colors(screen, curses, 'magenta')

        # setup windows
        win_border = screen.subwin(22, 52, 0, 0)
        map_win = win_border.subwin(21, 51, 1, 1)
        list_win = screen.subwin(25, 5, 0, 54)
        output_bor = screen.subwin(12, 71, 22, 0)
        output_win = output_bor.derwin(11, 70, 0, 1)

        output_win.scrollok(True)

        # Get the possible special wall chars
        input_dict = input_list(list_win, yellow, green)
        key_list = []
        for key in input_dict:
            key_list.append(str(key))

        # Pull the map specified on start, or create it if it doesn't exist. The row id and char
        # it is added to the point_data tuple. Point_data is [0] index, row id is [1] index, and
        # char is [2] index
        conn = db_create_connection()
        map_dict = db_pull_saved_map_to_dict(conn, map_to_pull)

        # Setup some color for pulled map
        color_list_yellow = ['D', 'C']
        color_list_cyan = ['E', 'u', 'd']

        # Here we build the map in curses. We pull the point and char data from the
        # map_dict and plot it on the map window.
        if 'map_dec' not in map_dict:
            for key in map_dict:
                if map_dict[key][2] in color_list_yellow:
                    map_win.addstr(key[0], key[1], f'{map_dict[key][2]}', yellow)
                elif map_dict[key] in color_list_cyan:
                    map_win.addstr(key[0], key[1], f'{map_dict[key][2]}', cyan)
                else:
                    map_win.addstr(key[0], key[1], f'{map_dict[key][2]}', green)

        # After drawing map, put the cursor at 0, 0 so we don't have to find it
        map_win.move(0, 0)

        # Start drawing and  awaiting input
        while True:
            output_win.addstr(1, 0, f'Cursor is at: {str(map_win.getyx())}')
            output_win.refresh()
            win_border.box()
            win_border.refresh()
            output_bor.box()
            output_bor.refresh()
            map_win.refresh()
            list_win.refresh()
            screen.refresh()
            key = map_win.getkey()
            y, x = map_win.getyx()
            output_win.clear()
            output_win.addstr(2, 0, f'We got {key}')
            output_win.refresh()
            try:
                if str(key) == 'e':
                    curses.endwin()
                    break
                elif str(key) == 'KEY_DOWN':
                    y += 1
                    map_win.move(y, x)
                elif str(key) == 'KEY_UP':
                    y += -1
                    map_win.move(y, x)
                elif str(key) == 'KEY_RIGHT':
                    x += 1
                    map_win.move(y, x)
                elif str(key) == 'KEY_LEFT':
                    x += -1
                    map_win.move(y, x)
                elif str(key) == 'KEY_DC':
                    y, x = map_win.getyx()
                    map_win.addstr(y, x, ' ')
                    map_win.move(y, x)
                    cords_key = (y, x)
                    result = db_delete_row(conn, 'maps', 'id', map_dict[cords_key][1])
                    if result.rowcount > 0:
                        del map_dict[cords_key]
                elif key in key_list:
                    # Get current position of cursor in the map window
                    y, x = map_win.getyx()
                    # Turn those into a (y, x) tuple
                    cords = (y, x)
                    # Grab the correct char from input_dict (walls only)
                    char = input_dict[int(key)]
                    # Check if the cords already exist, so we know if to insert or update the DB, returns
                    # the row id if it exist, or sets it to 0 if we need to insert
                    if cords in map_dict:
                        row_id = map_dict[(y, x)][1]
                    else:
                        row_id = 0
                    # Declare the dataclass we're using for point_data and assign the correct char to it
                    wall = Wall()
                    wall._char = char
                    # write the char on the screen
                    map_win.addstr(y, x, f'{char}', green)
                    # move the cursor back to where we started (or it always moves right)
                    map_win.move(y, x)
                    # Now were going to either insert or updated the correct row in DB
                    conn = db_create_connection()
                    row_id = db_insert_point_data(conn, cords, map_to_pull, row_id, wall)
                    # Lastly we set the point_data and correct row id into the dictionary
                    map_dict[(y, x)] = (wall, row_id, char)
                elif str(key.lower()) == 'i':
                    curses.endwin()
                    y, x = map_win.getyx()
                    cords = (y, x)
                    map_dict = create_cell(map_dict, cords, 'wall')
                    screen.refresh()
                else:
                    y, x = map_win.getyx()
                    map_win.addstr(y, x, f'{key}', yellow)
                    map_win.move(y, x)
                    map_dict[(y, x)] = key
                    # save_map(map_dict, 'data/maps.json', map_to_pull)
            except Exception as e:
                output_win.addstr(3, 0, f'Exception caught!!: {e}', red)
                continue

            output_win.addstr(3, 0, f'Y = {y} X = {x}')
            # output_win.addstr(5, 0, f'Dict: {map_dict}')
            output_win.refresh()
            win_border.refresh()
            map_win.refresh()
            screen.refresh()
            continue
Пример #2
0
def load_saved(saved_game: str):
    clear_screen()

    typed_print(f'Here are the current values for {cy}{saved_game}{ce}:')
    print()

    # char_build: Player
    conn = db_create_connection()
    char_build: Player = db_return_class_object(conn, 'saves', 'player_name',
                                                saved_game, Player)
    char_build.Race_details = db_return_class_object(conn, 'races', 'name',
                                                     char_build.Player_race,
                                                     Race)
    char_build.Arch_details = db_return_class_object(conn, 'archetype', 'name',
                                                     char_build.Player_type,
                                                     Archetype)
    char_build.Inventory = db_create_inventory_dict(conn,
                                                    char_build.Player_name)
    conn.close()

    typed_print(
        f"You are a {cb}{char_build.Player_race} {char_build.Player_type}{ce}"
        f" named {cy}{char_build.Player_name}{ce}.")
    print()
    typed_print(f"{'Level:':<14} {cb}{char_build.Level}{ce}")
    typed_print(f"{'XP:':<14} {cb}{char_build.XP}{ce}")
    typed_print(f"{'Height:':<14} {cb}{char_build.Height}{ce}")
    typed_print(f"{'Weight:':<14} {cb}{char_build.Weight} lbs{ce}")
    typed_print(f"{'Age:':<14} {cb}{char_build.Age}{ce}")
    typed_print(f"{'Hit points:':<14} {cb}{char_build.Current_HP}{ce}")
    typed_print(f"{'Armor Class:':14} {cb}{char_build.AC}{ce}")
    typed_print(
        f"{'Load/Max Load:':14} {cb}{char_build.Current_weight}/{char_build.Carry_weight}{ce}"
    )
    print()
    typed_print(f"{cbol}{lg}{'Attribute':<14} {'Stat':<4} Mod{ce}")
    typed_print('-----------------------')
    typed_print(
        f"{'Strength:':<14} {cb}{char_build.Str:<4}{ce} {stat_bonus(char_build.Str, colored=True)}"
    )
    typed_print(
        f"{'Dexterity:':<14} {cb}{char_build.Dex:<4}{ce} {stat_bonus(char_build.Dex, colored=True)}"
    )
    typed_print(
        f"{'Constitution:':<14} {cb}{char_build.Con:<4}{ce} {stat_bonus(char_build.Con, colored=True)}"
    )
    typed_print(
        f"{'Wisdom:':<14} {cb}{char_build.Wis:<4}{ce} {stat_bonus(char_build.Wis, colored=True)}"
    )
    typed_print(
        f"{'Intelligence:':<14} {cb}{char_build.Int:<4}{ce} {stat_bonus(char_build.Int, colored=True)}"
    )
    typed_print(
        f"{'Charisma:':<14} {cb}{char_build.Cha:<4}{ce} {stat_bonus(char_build.Cha, colored=True)}"
    )
    print()
    typed_print(
        f'Type ({cb}l{ce})oad, ({cb}c{ce})ancel, or ({cb}d{ce})elete '
        f'to continue: {cb}[l, d, c]{ce}:{cb} ',
        new_line=False)

    while True:
        load_response = input()
        print(ce, end='')
        if load_response.lower() == 'l':
            return curses.wrapper(start_main, char_build)
        elif load_response.lower() == 'd':
            typed_print(
                f'{cr}WARNING!!!{ce} are you SURE you wish to delete saved game {cy}{saved_game}{ce}?'
                f' {cb}[Yes,no]{ce}:{cb} ',
                new_line=False)
            delete = input()
            print(ce, end='')
            if delete.lower() == 'yes':
                conn = db_create_connection()
                db_delete_row(conn, 'saves', 'player_name', saved_game)
                conn.close()
            return saved_game_menu()
        elif load_response.lower() == 'c':
            return saved_game_menu()
        else:
            typed_print(
                f'Invalid response: "{cb}{load_response}{ce}". Type ({cb}l{ce})oad'
                f', ({cb}c{ce})ancel, or ({cb}d{ce})elete to continue: {cb}[l, d, c]{ce}:{cb} ',
                new_line=False)
            continue
Пример #3
0
def archetype_admin_edit(archetype, new=False):
    """The actual edit interface for archetype"""
    edited: Archetype = Archetype()
    clear_screen()
    if new:
        typed_print(f"You've chosen to create a new Archetype.")
    else:
        typed_print(
            f'You chose to edit {archetype}, here are the current values:')
    print()

    if not new:
        conn = db_create_connection()
        pulled_archetype = db_return_class_object(conn, 'archetype', 'name',
                                                  archetype, Archetype())
    else:
        pulled_archetype = archetype

    field_dict = print_class_data(pulled_archetype)
    print()
    typed_print(
        f'Enter a field to edit, (D) to delete race, or (C) to return to Races menu. '
        f'Example {cb}[Str]{ce}:{cb} ',
        new_line=False)

    while True:
        menu_choice = input()
        print(ce, end='')
        if menu_choice in field_dict:
            edited_archetype = edit_class_data(pulled_archetype, menu_choice,
                                               field_dict, Archetype)
            edited = edited_archetype[0]
            success = edited_archetype[1]
            if success is True:
                print()
                typed_print(
                    f"Value was updated, enter another to edit or (S) to save: {cb}",
                    new_line=False)
            else:
                typed_print(
                    f'There was an error. Enter a field to edit, or (C) to return to Races menu. '
                    f'Example {cb}[Str]{ce}:{cb} ',
                    new_line=False)
            continue
        elif menu_choice.lower() == 'c':
            return archetype_admin_menu()
        elif menu_choice.lower() == 's':
            conn = db_create_connection()
            if new:
                db_insert_class_in_table(conn, edited, 'archetype')
            else:
                db_update_class_in_table(conn, edited, 'archetype', 'name',
                                         edited.Name)
            conn.close()
            return archetype_admin_menu()
        elif menu_choice.lower() == 'd':
            result = input(
                f'Are you SURE you wish to {cr}DELETE{ce} Archetype: {cb}{archetype}{ce} [yes,n]? '
            )
            if result.lower() == 'yes':
                conn = db_create_connection()
                db_delete_row(conn, 'archetype', 'name', archetype)
                conn.close()
                return archetype_admin_menu()
            else:
                input(
                    f'Archetype: {cb}{archetype}{ce} not deleted! Press enter to continue...'
                )
                return archetype_admin_menu()
        else:
            typed_print(
                f'Value entered: {cb}{menu_choice}{ce} is not valid, please reenter: {cb} ',
                new_line=False)
Пример #4
0
def item_admin_edit(item, new=False):
    """The actual edit interface for items"""
    edited: Items = Items()
    clear_screen()
    if new:
        typed_print(f"You've chosen to create a new Item.")
    else:
        typed_print(
            f'You chose to edit {cb}{item}{ce}, here are the current values:')
    print()
    if not new:
        conn = db_create_connection()
        pulled_item = db_return_class_object(conn, 'items', 'name', item,
                                             Items)
    else:
        pulled_item = item
    field_dict = print_class_data(pulled_item, col_one='<12', col_two='<30')
    print()
    typed_print(
        f'Enter a field to edit, ({cb}d{ce})elete to delete item, or ({cb}c{ce})ancel to return'
        f' to Items menu. Example {cb}[Name]{ce}:{cb} ',
        new_line=False)

    while True:
        menu_choice = input()
        print(ce, end='')
        edited: Items
        if menu_choice in field_dict:
            edited_item = edit_class_data(pulled_item, menu_choice, field_dict,
                                          Items)
            edited = edited_item[0]
            success = edited_item[1]
            if success is True:
                print()
                typed_print(
                    f"{cy}SUCCESS!{ce}, enter another to edit, ({cb}C{ce}) to cancel,"
                    f" or ({cb}S{ce}) to save: {cb}",
                    new_line=False)
            else:
                typed_print(
                    f'There was an error. Enter a field to edit, or ({cb}C{ce}) to return to Items menu. '
                    f'Example {cb}[Name]{ce}:{cb} ',
                    new_line=False)
            continue
        elif menu_choice.lower() == 'c':
            return item_admin_menu()
        elif menu_choice.lower() == 's':
            conn = db_create_connection()
            if new:
                db_insert_class_in_table(conn, edited, 'items')
            else:
                db_update_class_in_table(conn, edited, 'items', 'name',
                                         edited.Name)
            conn.close()
            return item_admin_menu()
        elif menu_choice.lower() == 'd':
            result = input(
                f'Are you SURE you wish to {cr}DELETE{ce} item: {cb}{item}{ce} [yes,n]? '
            )
            if result.lower() == 'yes':
                conn = db_create_connection()
                db_delete_row(conn, 'items', 'name', item)
                return item_admin_menu()
            else:
                input(
                    f'Item: {cb}{item}{ce} was not deleted. Press enter to continue...'
                )
                return item_admin_menu()
        else:
            typed_print(
                f'Value entered: {cb}{menu_choice}{ce} is not valid, please reenter: {cb} ',
                new_line=False)
Пример #5
0
def races_admin_edit(dataclass, table, race=None, new=False):
    """The actual edit interface for races"""

    edited: dataclass = dataclass
    clear_screen()
    if new:
        typed_print(f"You've chosen to create a new Race.")
    else:
        typed_print(
            f'You chose to edit {cb}{race}{ce}, here are the current values:')
    print()

    if not new:
        conn = db_create_connection()
        pulled_race = db_return_class_object(conn, table, 'name', race,
                                             dataclass)
        conn.close()
    else:
        pulled_race = dataclass

    field_dict = print_class_data(pulled_race)
    print()
    typed_print(
        f'Enter a field to edit, ({cb}d{ce}) to delete race, or ({cb}c{ce}) to return to Races menu. '
        f'Example {cb}[Name]{ce}:{cb} ',
        new_line=False)

    while True:
        menu_choice = input()
        print(ce, end='')
        if menu_choice in field_dict:
            edited_race = edit_class_data(pulled_race, menu_choice, field_dict,
                                          dataclass)
            edited = edited_race[0]
            success = edited_race[1]
            if success is True:
                print()
                typed_print(
                    f"{cy}SUCCESS!{ce}, enter another to edit, ({cb}C{ce}) to cancel,"
                    f" or ({cb}S{ce}) to save: {cb}",
                    new_line=False)
            else:
                typed_print(
                    f'There was an error. Enter a field to edit, or ({cb}C{ce}) to return to Races menu. '
                    f'Example {cb}[Str]{ce}:{cb} ',
                    new_line=False)
            continue
        elif menu_choice.lower() == 'c':
            return races_admin_menu()
        elif menu_choice.lower() == 's':
            conn = db_create_connection()
            if not new:
                db_update_class_in_table(conn, edited, table, 'name',
                                         edited.Name)
            else:
                db_insert_class_in_table(conn, edited, table)
            conn.close()
            return races_admin_menu()
        elif menu_choice.lower() == 'd':
            result = input(
                f'Are you SURE you wish to {cr}DELETE{ce} Race: {cb}{race}{ce} [yes,n]? '
            )
            if result.lower() == 'yes':
                conn = db_create_connection()
                db_delete_row(conn, table, 'name', race)
                conn.close()
                return races_admin_menu()
            else:
                input(
                    f'Race: {cb}{race}{ce} was not deleted. Press enter to continue...'
                )
                return races_admin_menu()
        else:
            typed_print(
                f'Value entered: {cb}{menu_choice}{ce} is not valid, please reenter: {cb} ',
                new_line=False)