简体   繁体   中英

how do i increase the min and max on my number list?

I'm creating a game in python but I ran into trouble when creating the level system. ya see for her attack I created A list from 1(min) to 10(max) and for every level she gains I want the min and the max of the list to increase by 1 but how should i do it if it is possible? I'm coding in python 3.2

char ={
    'atk':[1,10],
    'Hp':100,
    'name': 'Ruby',
    'Age': 1,
    'weapon': 'Scythe',
    'lvl': 1,
    'xp': 0,
    'nextlvl': 50,
    'stats': {
        'str': 1,
        'dex': 1,
        'vit': 1
}}
while char['xp'] >= char['nextlvl']:
    char['lvl'] += 1
    char['nextlvl'] = char['nextlvl'] * 3
    char['stats']['str'] +=1
    char['stats']['dex'] +=1
    char['stats']['vit'] +=1
    char['atk'] +=1 <-- my problems right here
    print('level:', char['lvl'],'Exp:', char['xp'],'nextlvl:', char['nextlvl'])
    print('STR:', char['stats']['str'], 'DEX:', char['stats']['dex'], 'VIT:', char['stats']['vit'])

The following will do it:

char['atk'] = [atk + 1 for atk in char['atk']]

You could also increment the two numbers (the min and the max) individually:

char['atk'][0] = char['atk'][0] + 1
char['atk'][1] = char['atk'][1] + 1

If you think this unwieldy, you might want to consider storing the min and the max in two separate dictionary entries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM