Advertisement
Guest User

BATTLE

a guest
Jan 2nd, 2013
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.03 KB | None | 0 0
  1. from random import randint
  2.  
  3. # define variables
  4.  
  5. you_hp = 20
  6. you_atk = 2
  7. you_def = 1
  8.  
  9. you = [you_hp, you_atk, you_def]
  10.  
  11. it_hp = 20
  12. it_atk = 2
  13. it_def = 1
  14.  
  15. it = [it_hp, it_atk, it_def]
  16.  
  17. end = 0 #if 1, ends game
  18. condition = 0 #0 is your turn, 1 is the monsters, 3 is after one of you have died
  19.  
  20.  
  21. #processes
  22.  
  23. while end == 0:
  24.  
  25.     while condition == 0: # Your turn
  26.         print "\nThe monster has "+`it[0]`+" health left and you have "+`you[0]`
  27.         print "1.Attack\n2.Battle Cry\n3.Heal\n4.Check stats"
  28.         x = raw_input("\nWhat do you do? ")
  29.  
  30.         if x == "1": # You attacking it
  31.  
  32.             you_chance = randint(1,1000) #random used for crit/miss/hit
  33.  
  34.             if you_chance > 900: #Crit
  35.                 it[0] = it[0] - you[1]
  36.                
  37.                 print "\nYou lands a CRITICAL HIT on your foe for " + `you[1]` + " damage"
  38.                 print "\nThe monster loses " + `you[1]` + " health.."
  39.  
  40.                 if it[0] <= 0:
  41.                         print "And falls, defeated, to the ground."
  42.                         print "\nYOU ARE VICTORIOUS!"
  43.  
  44.                         condition = 2
  45.  
  46.                 else:
  47.                     condition = 1
  48.                     raw_input("<enter>\n")
  49.  
  50.             elif you_chance < 300: #Miss
  51.                 print "\nYour attacked completely missed!"
  52.  
  53.                 condition = 1
  54.                 raw_input("<enter>\n")
  55.  
  56.             else: #Hit
  57.                
  58.                 print "\nYou attack for " + `you[1]` + " damage"
  59.                 print "but the monster blocked " + `it[2]` + " of it."
  60.  
  61.                 your_damage = (you[1] - it[2])
  62.  
  63.                 if your_damage > 0:
  64.                     it[0] = it[0] - your_damage
  65.                     print "\nThe monster loses " + `your_damage` + " health.."
  66.  
  67.                     if it[0] <= 0:
  68.                         print "And falls, defeated, to the ground."
  69.                         print "\nYOU ARE VICTORIOUS!"
  70.  
  71.                         condition = 2
  72.  
  73.                     else:
  74.                         condition = 1
  75.                         raw_input("<enter>\n")
  76.                        
  77.                 else:
  78.                     condition = 1
  79.                     print "\nYour attack did nothing."
  80.                     raw_input("<enter>\n")
  81.  
  82.         elif x == "2": # Using Battle Cry
  83.             you[1] = you[1] + 1
  84.             you[2] = you[2] + 1
  85.  
  86.             print "\nYou let out a heroic battle cry!"
  87.             print "(Your attack and defence are increased)"
  88.  
  89.             condition = 1
  90.             raw_input("<enter>\n")
  91.  
  92.         elif x == "3": # Using Heal
  93.             you[0] = 20
  94.             you[1] = you[1] - 2
  95.             you[2] = you[2] - 2
  96.  
  97.             print "\nYou use bitter medicene to restore your health."
  98.             print "(Health imcreased. Attack and defence decreased.)"
  99.  
  100.             if you[2] <= 0:
  101.                 you[1] = 1
  102.                 you[2] = 0
  103.  
  104.                 print "(Attack and defence now at minimum)"
  105.  
  106.             else:
  107.                 condition = 1
  108.                 raw_input("<enter>\n")
  109.                
  110.         elif x == "4": # Check Stats
  111.             print "\nThe monster's attack is " + `it[1]`
  112.             print "and its defence is " + `it[2]` + "."
  113.             print "Your attack is " + `you[1]`
  114.             print "and your defence is " + `you[2]` + "."
  115.  
  116.         else:
  117.             print"Invalid choice. Enter 1-4"
  118.  
  119.     while condition == 1: #It's turn
  120.  
  121.         y = randint(1,1000)
  122.         z = y % 2 #gets random 0 or 1 to choose monsters action
  123.  
  124.         if z == 0: #It attacking you
  125.  
  126.             its_chance = randint(1,1000) # random used for crit/miss/hit
  127.  
  128.             if its_chance > 750: #Crit
  129.                 print "\nThe monster lands a CRITICAL HIT on you for " + `it[1]` + " damage"
  130.                 print "\nYou lose " + `it[1]` + " health.."
  131.  
  132.                 print "\nThe monster is getting tired."
  133.                 print "(Its attack and defence greatly decrease)"
  134.  
  135.                 you[0] = you[0] - it[1]
  136.  
  137.                 it[1] = it[1] - 2
  138.                 it[2] = it[2] - 2
  139.                
  140.                 if you[0] <= 0:
  141.                     print "And, with nothing left in you, you collapse."
  142.                     print "\nYOU HAVE BEEN DEFEATED!"
  143.  
  144.                     condition = 2
  145.  
  146.                 else:
  147.  
  148.                     if it[2] <= 0:
  149.  
  150.                         it[1] = 1
  151.                         it[2] = 0
  152.  
  153.                         condition = 0
  154.  
  155.                     else:
  156.                         condition = 0                      
  157.  
  158.             elif its_chance < 250: #Miss
  159.                 print "\nThe monster swings, but misses!"
  160.  
  161.                 condition = 0
  162.  
  163.             else: #Hit
  164.                 print "\nThe monster hits you for " + `it[1]` + " damage"
  165.                 print "but you block " + `you[2]` + " of it."
  166.  
  167.                 its_damage = (it[1] - you[2])
  168.  
  169.                 if its_damage > 0:
  170.                     you[0] = you[0] - its_damage
  171.                     print "\nYou lose " + `its_damage` + " health.."
  172.  
  173.                     if you[0] <= 0:
  174.                         print "And, with nothing left in you, you collapse."
  175.                         print "\nYOU HAVE BEEN DEFEATED!"
  176.  
  177.                         condition = 2
  178.  
  179.                     else:
  180.                         condition = 0
  181.  
  182.                 else:
  183.                     condition = 0
  184.                     print "\nIts attack did nothing."
  185.  
  186.         else: #Monster uses Battle cry
  187.             it[1] = it[1] + 2
  188.             it[2] = it[2] + 1
  189.  
  190.             print "\nThe monster bellows with rage!"
  191.             print "(Its attack increases greatly and its defence increases)"
  192.  
  193.             condition = 0
  194.  
  195.     while condition == 2: #Game over
  196.  
  197.         q = raw_input("Play again? y/n? ")
  198.  
  199.         if q == "y":
  200.             you = [20,2,1]
  201.             it = [20,2,1]
  202.             condition = 0
  203.  
  204.         elif q == "n":
  205.             condition = 3
  206.  
  207.     while condition == 3:
  208.         end = 1
  209.         break
  210.  
  211. print "\n\nThanks for playing."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement