Exemplo n.º 1
0
def Menu(header, options, width):
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options')
    header_height = libtcodpy.console_get_height_rect(0, 0, 0,
                                                      config.window_width,
                                                      config.window_height,
                                                      header)
    if header == '':
        header_height = 0
    height = len(options) + header_height
    menupanel = Panel(0, 0, width, height)
    menupanel.write_wrap_ex(0, 0, width, height, header, libtcodpy.LEFT)
    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        menupanel.write(0, y, text)
        y += 1
        letter_index += 1

    x = config.window_width / 2 - width / 2
    y = config.window_height / 2 - height / 2
    menupanel.blit(xdst=x, ydst=y, bfade=0.7)

    config.gamewindow.flush
    key = libtcodpy.console_wait_for_keypress(True)

    if key.vk == libtcodpy.KEY_ENTER and key.lalt:
        libtcodpy.console_set_fullscreen(not libtcodpy.console_is_fullscreen())

    index = key.c - ord('a')
    if index >= 0 and index < len(options):
        return index
    return None
Exemplo n.º 2
0
def get_name():
    config.PlayerName = ''
    name = ''
    namepanel = Panel(0, 0, config.window_width, config.window_height)
    while True:
        namepanel.clear
        config.gamewindow.clear
        namepanel.write(config.window_width / 2 - 21,
                        int(config.window_height * .2),
                        'Please Enter a Name! (ten character limit)')
        namepanel.write(config.window_width / 2 - len(name) / 2 - 2,
                        int(config.window_height * .3),
                        '( ' + name + ' )')
        namepanel.blit()
        config.gamewindow.flush
        key = libtcodpy.console_wait_for_keypress(True)
        if key.vk == libtcodpy.KEY_BACKSPACE and len(name) > 0:
            name = name[:-1]
        elif key.vk == libtcodpy.KEY_ENTER and len(name) > 0:
            option = None
            while option is None:
                option = Menu('Is ' + name + ' the name you want?',
                              ['Yes', 'No'], 20)
            if option == 0:
                break
        else:
            if len(name) < 10:
                if key.c != 0:
                    key_char = chr(key.c)
                    name += key_char
    config.PlayerName = name
Exemplo n.º 3
0
def menu(header, options, width):
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options')

    # header_height = libtcod.console_get_height_rect(con, 0, 0, width,
    #                                                 SCREEN_HEIGHT, header)
    header_height = libtcod.console_get_height_rect(console.body, 0, 0, width,
                                                    SCREEN_HEIGHT, header)
    if header == '':
        header_height = 0
    height = len(options) + header_height

    # window = libtcod.console_new(width, height)
    window = Panel(0, 0, width, height)

    # libtcod.console_set_default_foreground(window, libtcod.white)
    # libtcod.console_print_rect_ex(window, 0, 0, width, height,
    #                               libtcod.BKGND_NONE, libtcod.LEFT, header)
    window.set_default_foreground(libtcod.white)
    window.write_wrap_ex(0, 0, width, height, header, libtcod.LEFT)

    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        # libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE,
        #                          libtcod.LEFT, text)
        window.write(0, y, text)
        y += 1
        letter_index += 1

    x = SCREEN_WIDTH / 2 - width / 2
    y = SCREEN_HEIGHT / 2 - height / 2
    # libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
    window.x = x
    window.y = y
    window.blit(bfade=0.7)

    # libtcod.console_flush()
    root.flush
    key = libtcod.console_wait_for_keypress(True)

    if key.vk == libtcod.KEY_ENTER and key.lalt:
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

    index = key.c - ord('a')
    if index >= 0 and index < len(options):
        return index
    return None
Exemplo n.º 4
0
def End_Game(finished=False):
    header = ''
    PC = CM.get_Component('Creature', config.PlayerId)
    PL = CM.get_Component('Level', config.PlayerId)
    PA = CM.get_Component('Attack', config.PlayerAttack)
    if finished:
        header = '\n\nYou completed the dungeon! Congradulations ' + \
            config.PlayerName
    else:
        header = '\n\nSadly you died in the dungeon. ' +\
            'Better luck next time ' + \
            config.PlayerId
    header += '\n\nDungeon Level: ' + str(config.CurrentDungeonLevel) + \
        '\nLevel: ' + str(PL.level) + \
        '   Max Hp: ' + str(PC.MaxHp) + \
        '   Defense: ' + str(PC.Defense) + \
        '   Strength: ' + str(PC.Strength) + \
        '   Agility: ' + str(PC.Agility) + '\n'
    statlst = []
    atcklst = []
    atcklst.append('Attack: ' + str(PA.Dice) + 'd' + str(PA.Sides))
    if 'LifeDrain' in PA.Special:
        atcklst.append('   Life Drain: ' + str(PA.Special['LifeDrain']))
    if 'Paralyze' in PA.Special:
        atcklst.append('   Paralyze: %' + str(PA.Special['Paralyze']))
    if 'PierceDefense' in PA.Special:
        atcklst.append('   Pierce Defense: %' +
                       str(PA.Special['PierceDefense']))
    if 'CausePoison' in PA.Special:
        (percent, turns, damage) = PA.Special['CausePoison']
        atcklst.append('   Poison: %' + str(percent) + ' T' + str(turns) +
                       ' D' + str(damage))
    if 'EnhancedDefense' in PC.Special:
        statlst.append('   Enhanced Defense: %' +
                       str(PC.Special['EnhancedDefense']))
    if 'SideSwipe' in PC.Special:
        statlst.append('   Side Swipe Attack')
    if 'Dodge' in PC.Special:
        statlst.append('   Dodge: %' + str(PC.Special['Dodge']))
    if 'ParalyzeResistance' in PC.Special:
        statlst.append('   Paralyze Resistance: %' +
                       str(PC.Special['ParalyzeResistance']))
    if 'CritChance' in PC.Special:
        statlst.append('   Crit Chance: %' + str(PC.Special['CritChance']))
    if 'ReduceCrit' in PC.Special:
        statlst.append('   Reduce Crit: %' + str(PC.Special['ReduceCrit']))
    if 'Fear' in PC.Special:
        statlst.append('   Fear: %' + str(PC.Special['Fear']))
    if 'RandomBlink' in PC.Special:
        statlst.append('   Blink Uses: ' + str(PC.Special['RandomBlink']))
    if 'HealthPotion' in PC.Special:
        statlst.append('   Health Potions: ' + str(PC.Special['HealthPotion']))
    if 'LifeSaver' in PC.Special:
        statlst.append('   %$#: @')
    if 'CardinalLeap' in PC.Special:
        (need, current, distance) = PC.Special['CardinalLeap']
        statlst.append('   Leap: E' + str(need) + ' Dist' + str(distance))
    for item in atcklst:
        header += item
    header += '\n\n'
    cur = 1
    for item in statlst:
        if cur < 3:
            cur += 1
            header += item
        else:
            cur = 1
            header += item + '\n'
    if cur != 1:
        header += '\n'
    width = config.window_width
    options = ['Main Menu', 'Quit']
    header_height = libtcodpy.console_get_height_rect(0, 0, 0,
                                                      config.window_width,
                                                      config.window_height,
                                                      header)
    height = len(options) + header_height
    endpanel = Panel(0, 0, width, height)
    endpanel.write_wrap_ex(0, 0, width, height, header, libtcodpy.LEFT)
    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        endpanel.write(0, y, text)
        y += 1
        letter_index += 1
    x = config.window_width / 2 - width / 2
    y = config.window_height / 2 - height / 2
    endpanel.blit(xdst=x, ydst=y, bfade=0.7)
    config.gamewindow.flush
    filename = config.PlayerName
    keepcharacters = (' ', '.', '_')
    filename = "".join(
        c for c in filename if c.isalnum() or c in keepcharacters).rstrip()
    if filename == '':
        filename = 'Empty'
    if finished:
        filename += '\'s Victory Monument'
    else:
        filename += '\'s Tombstone'
    with open(filename + '.txt', mode='w') as f:
        f.write(header)
    choice = None
    while choice is None:
        key = libtcodpy.console_wait_for_keypress(True)
        if key.vk == libtcodpy.KEY_ENTER and key.lalt:
            libtcodpy.console_set_fullscreen(
                not libtcodpy.console_is_fullscreen())

        index = key.c - ord('a')

        if index >= 0 and index < len(options):
            choice = index
    if choice == 0:
        config.game_state = 'finished'
    elif choice == 1:
        config.game_state = 'Quit'
Exemplo n.º 5
0
            pw = xbox - cursor.x + 1
        else:
            px = xbox
            pw = cursor.x - xbox + 1
        if cursor.y < ybox:
            py = cursor.y
            ph = ybox - cursor.y + 1
        else:
            py = ybox
            ph = cursor.y - ybox + 1
        boxlist[-1] = Panel(px, py, pw, ph, border=True)


test = Console(80, 50, 'test')
test3 = Panel(0, 0, 80, 50)
test3.write(0, 0, '1234567891111111111222222222233333333334444444444' +
            '5555555555666666666677777777778')
test3.write(0, 1, '         0123456789012345678901234567890123456789' +
            '0123456789012345678901234567890')
test3.write_wrap(0, 0, 2, 50, '1 2 3 4 5 6 7 8 9 1011121314151617181' +
                 '92021222324252627282930313233343536373839404142434' +
                 '4454647484950')
cursor = Panel(0, 0, 1, 1)
cursor.write(0, 0, '@')
boxlist = []
xbox = 0
ybox = 0
working = False
mouse = libtcodpy.Mouse()
key = libtcodpy.Key()
while not test.is_window_closed:
    libtcodpy.sys_check_for_event(libtcodpy.EVENT_KEY_PRESS |
Exemplo n.º 6
0
from Panel import Panel


test = Console(20, 20, 'test')
test.set_fps(10)
ptest = Panel(0, 0, 20, 20)
ptest.set_default_foreground(libtcodpy.light_gray)
pshade = Panel(-1, -1, 10, 10)
random.seed(222)
fade = 0.1

while not test.is_window_closed:
    for x in range(0, 20):
        for y in range(0, 20):
            if random.randint(0, 2):
                ptest.write(x, y, '.')
                if not random.randint(0, 5):
                    ptest.set_default_background(libtcodpy.red)
                elif not random.randint(0, 5):
                    ptest.set_default_background(libtcodpy.blue)
                elif not random.randint(0, 5):
                    ptest.set_default_background(libtcodpy.yellow)
                else:
                    ptest.set_default_background(libtcodpy.black)
            else:
                ptest.write(x, y, '#')
                if not random.randint(0, 3):
                    ptest.set_default_foreground(libtcodpy.red)
                elif not random.randint(0, 3):
                    ptest.set_default_foreground(libtcodpy.blue)
                elif not random.randint(0, 3):