Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from entity import Entity
- from random import randint
- STATE_EXPLORING = 0
- STATE_BATTLE = 1
- def attack(attacker, defender):
- chance_to_hit = randint(1, 100)
- if chance_to_hit <= 50:
- attack_value = attacker.attack
- chance_to_defend = randint(1, 100)
- if(chance_to_defend <= 50):
- attack_value -= defender.defense
- defender.health -= attack_value
- print "%s hits %s for %d. %s's health is now %d." % (attacker.name, defender.name, attack_value, defender.name, defender.health)
- else:
- print "%s misses." % (attacker.name)
- def explore(player):
- chance_encounter = randint(1, 100)
- if chance_encounter <= 25:
- monster = Entity("Monster")
- print "You've encountered a %s. Prepare to attack." % (monster.name)
- return monster
- else:
- player.health += 1
- print "You've regained 1 HP. Your HP is now %d." % (player.health)
- name = raw_input("What is your name?")
- player = Entity(name)
- enemy = None
- state = STATE_EXPLORING
- while player.isAlive():
- command = raw_input("What do you want to do? ")
- if command == "explore" or command == "e":
- if state == STATE_EXPLORING:
- enemy = explore(player)
- if enemy != None:
- state = STATE_BATTLE
- else:
- print "You can't do that right now."
- elif command == "attack" or command == "a":
- if state == STATE_BATTLE:
- attack(player, enemy)
- if enemy.isAlive():
- attack(enemy, player)
- else:
- state = STATE_EXPLORING
- print "%s has vanquished the %s. Prepare your anus for the spoils of victory!" % (player.name, enemy.name)
- enemy = None
- else:
- print "You can't do that right now."
- else:
- print "I don't understand you."
- 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