Magnie

Simple Text Adventure

Nov 4th, 2013
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.83 KB | None | 0 0
  1. # Simple Text Adventure with Python
  2. # By: Magnie
  3. import random
  4.  
  5. # Player stuff
  6. gold = 0
  7. name = raw_input('What is your name? ')
  8. hp = 10
  9. max_hp = 10
  10.  
  11. items = []
  12.  
  13. # weapon: damage
  14. weapon_stats = {'hands': 1,
  15.                 'sword': 3}
  16.  
  17. # item: cost
  18. shop = {'sword': 10,
  19.         'bow': 15,
  20.         'hp potion': 20,
  21.         '10 gold': -10}
  22.  
  23. # monster: health
  24. monsters = {'pig': 5,
  25.             'bull': 10}
  26.  
  27. monsters_dmg = {'pig': 2,
  28.                'bull': 4}
  29.  
  30. while True:
  31.     print 'Places: \nshop\nwilderness'
  32.     place = raw_input("Where do you want to go? ")
  33.  
  34.     if place == 'shop':
  35.         # Print Shop and it's contents
  36.         print '\nItem\t\t- Cost'
  37.         for item in shop:
  38.             print item + '\t\t- ' + str(shop[item])
  39.  
  40.         print
  41.  
  42.         # Ask which item to buy and then buy it.
  43.         choice = raw_input("What would you like to buy? ")
  44.         choice = choice.lower()  # Turn input into lowercase
  45.         if choice in shop:  # Check if the item is in the shop
  46.  
  47.             # Check if user has enough gold
  48.             if gold >= shop[choice]:
  49.                 print 'You bought the {0} for {1} gold'.format(choice,
  50.                                                                shop[choice])
  51.                 gold -= shop[choice]
  52.                 items.append(choice)
  53.  
  54.             else:
  55.                 print 'Not enough gold.'
  56.  
  57.     elif place == 'wilderness':
  58.         # Pick a random event.
  59.         event = random.randrange(0, 2)
  60.         if event == 0:
  61.             # Fight
  62.             monster = random.sample(monsters, 1)[0]
  63.             monster_hp = monsters[monster]
  64.             monster_dmg = monsters_dmg[monster]
  65.             print 'You encountered a {0}.'.format(monster)
  66.             while monster_hp > 0 and hp > 0:
  67.                 print 'Weapons'
  68.                 for item in items:
  69.                     print item
  70.  
  71.                 weapon = raw_input('What item do you wish to use to attack? ')
  72.                 dmg = 1
  73.                 if weapon not in weapon_stats or \
  74.                     weapon not in items:
  75.                     print 'That\'s not going to do a lot...'
  76.  
  77.                 else:
  78.                     dmg = weapon_stats[weapon]
  79.  
  80.                 monster_hp -= random.randrange(1, dmg)
  81.                 hp -= monster_dmg
  82.                 print 'Your health: {0}/{1}'.format(hp, max_hp)
  83.                 print 'Monster health left: {0}'.format(monster_hp)
  84.                 print
  85.  
  86.             if hp <= 0:
  87.                 print 'You died. Game over.'
  88.                 break
  89.  
  90.             elif monster_hp <= 0:
  91.                 print 'You killed the {0}. Congratulations.'.format(monster)
  92.  
  93.         elif event == 1:
  94.             # Find an item
  95.             print 'You found a {0}.'
  96.  
  97.         elif event == 2:
  98.             # Nothing
  99.             print 'Nothing eventful happened.'
Advertisement
Add Comment
Please, Sign In to add comment