Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Simple Text Adventure with Python
- # By: Magnie
- import random
- # Player stuff
- gold = 0
- name = raw_input('What is your name? ')
- hp = 10
- max_hp = 10
- items = []
- # weapon: damage
- weapon_stats = {'hands': 1,
- 'sword': 3}
- # item: cost
- shop = {'sword': 10,
- 'bow': 15,
- 'hp potion': 20,
- '10 gold': -10}
- # monster: health
- monsters = {'pig': 5,
- 'bull': 10}
- monsters_dmg = {'pig': 2,
- 'bull': 4}
- while True:
- print 'Places: \nshop\nwilderness'
- place = raw_input("Where do you want to go? ")
- if place == 'shop':
- # Print Shop and it's contents
- print '\nItem\t\t- Cost'
- for item in shop:
- print item + '\t\t- ' + str(shop[item])
- print
- # Ask which item to buy and then buy it.
- choice = raw_input("What would you like to buy? ")
- choice = choice.lower() # Turn input into lowercase
- if choice in shop: # Check if the item is in the shop
- # Check if user has enough gold
- if gold >= shop[choice]:
- print 'You bought the {0} for {1} gold'.format(choice,
- shop[choice])
- gold -= shop[choice]
- items.append(choice)
- else:
- print 'Not enough gold.'
- elif place == 'wilderness':
- # Pick a random event.
- event = random.randrange(0, 2)
- if event == 0:
- # Fight
- monster = random.sample(monsters, 1)[0]
- monster_hp = monsters[monster]
- monster_dmg = monsters_dmg[monster]
- print 'You encountered a {0}.'.format(monster)
- while monster_hp > 0 and hp > 0:
- print 'Weapons'
- for item in items:
- print item
- weapon = raw_input('What item do you wish to use to attack? ')
- dmg = 1
- if weapon not in weapon_stats or \
- weapon not in items:
- print 'That\'s not going to do a lot...'
- else:
- dmg = weapon_stats[weapon]
- monster_hp -= random.randrange(1, dmg)
- hp -= monster_dmg
- print 'Your health: {0}/{1}'.format(hp, max_hp)
- print 'Monster health left: {0}'.format(monster_hp)
- print
- if hp <= 0:
- print 'You died. Game over.'
- break
- elif monster_hp <= 0:
- print 'You killed the {0}. Congratulations.'.format(monster)
- elif event == 1:
- # Find an item
- print 'You found a {0}.'
- elif event == 2:
- # Nothing
- print 'Nothing eventful happened.'
Advertisement
Add Comment
Please, Sign In to add comment