xaviermontenegro

Untitled

Jul 17th, 2013
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.73 KB | None | 0 0
  1. from entity import Entity
  2. from random import randint
  3.  
  4. STATE_EXPLORING = 0
  5. STATE_BATTLE = 1
  6.  
  7. def attack(attacker, defender):
  8.     chance_to_hit = randint(1, 100)
  9.     if chance_to_hit <= 50:
  10.         attack_value = attacker.attack
  11.         chance_to_defend = randint(1, 100)
  12.         if(chance_to_defend <= 50):
  13.             attack_value -= defender.defense
  14.         defender.health -= attack_value
  15.         print "%s hits %s for %d. %s's health is now %d." % (attacker.name, defender.name, attack_value, defender.name, defender.health)
  16.     else:
  17.         print "%s misses." % (attacker.name)
  18.  
  19. def explore(player):
  20.     chance_encounter = randint(1, 100)
  21.     if chance_encounter <= 25:
  22.         monster = Entity("Monster")
  23.         print "You've encountered a %s. Prepare to attack." % (monster.name)
  24.         return monster
  25.     else:
  26.         player.health += 1
  27.         print "You've regained 1 HP. Your HP is now %d." % (player.health)
  28.  
  29. name = raw_input("What is your name?")
  30. player = Entity(name)
  31. enemy = None
  32. state = STATE_EXPLORING
  33.  
  34. while player.isAlive():
  35.     command = raw_input("What do you want to do? ")
  36.     if command == "explore" or command == "e":
  37.         if state == STATE_EXPLORING:
  38.             enemy = explore(player)
  39.             if enemy != None:
  40.                 state = STATE_BATTLE
  41.         else:
  42.             print "You can't do that right now."
  43.     elif command == "attack" or command == "a":
  44.         if state == STATE_BATTLE:
  45.             attack(player, enemy)
  46.             if enemy.isAlive():
  47.                 attack(enemy, player)
  48.             else:
  49.                 state = STATE_EXPLORING
  50.                 print "%s has vanquished the %s. Prepare your anus for the spoils of victory!" % (player.name, enemy.name)
  51.                 enemy = None
  52.         else:
  53.             print "You can't do that right now."
  54.     else:
  55.         print "I don't understand you."
  56.  
  57. print "You have died. Your princess is in a different castle. Your life sucks...or it would, if you had one!"
Add Comment
Please, Sign In to add comment