Advertisement
ivandrofly

Pythong Basic Game

Mar 18th, 2015
527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. import random
  2.  
  3. class Character(object):
  4.     def __init__(self, name, level):
  5.         self.name = name
  6.         self.level = level
  7.         self.health = int(level + 5 ** 2) # if level is'nt number this will throw
  8.  
  9.     def damage(self, dmg):
  10.         block = self.block()
  11.         if dmg-block < 0:
  12.             dmg = 0
  13.         else:
  14.             dmg = dmg - block
  15.  
  16.         self.health - dmg
  17.         if self.health <= 0:
  18.            print("%s has died!" % self.name)
  19.            return 1
  20.         else:
  21.            print("%s has lost %i health!" % (self.name, dmg))
  22.            return 0
  23.  
  24.     def block(self):
  25.         rand = random.randint(0,100)
  26.         if rand % 5 == 0 and rand % 2 == 0:
  27.             return int(self.level / 2 * 1.5 /3)
  28.         return 0
  29.    
  30.     def attack(self):
  31.         dmg = 0
  32.         rand = random.randint(0, 100)
  33.         if rand % 5 == 0:
  34.             dmg = self.level/4 * 1.5
  35.             print("Attack Successful!")
  36.         return dmg
  37.  
  38. def win(char1, char2):
  39.     if(char1.health > char2.health):
  40.         winner = char1.name
  41.     else:
  42.         winner = char2.name
  43.     print("%s has won" % winner)
  44.    
  45. vilan = Character("Megaman", 13) # :)
  46. hero = Character("Metroman", 20)
  47. h = 0
  48. v = 0
  49.  
  50. def fight(char1, char2):
  51.     i = 0
  52.     j = 0
  53.     while j != 1 and i != 1:
  54.         i = char1.damage(vilan.attack())
  55.         j = char2.damage(hero.attack())
  56.     win(char1, char2) #Ivandro Ismael
  57.  
  58. fight(vilan, hero)    
  59. #input() #wait here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement