Advertisement
roman_gemini

Game:)

Dec 28th, 2015
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.79 KB | None | 0 0
  1. # Common game entity classes
  2.  
  3. class World:
  4.     locations = [];
  5.  
  6.     def doTick(self):
  7.         for location in locations:
  8.             location.doTick()
  9.  
  10.  
  11. class Location:
  12.     persons = [];
  13.    
  14.     def __init__(self, name):
  15.         self.name = name
  16.        
  17.     def __repr__(self):
  18.         return self.name
  19.    
  20.     def doTick(self):
  21.         for person in persons:
  22.             person.doTick()
  23.  
  24.  
  25. class Item:
  26.     weight      = None
  27.     price       = None
  28.     defence     = 0
  29.     attack      = 0
  30.  
  31.  
  32. class Kick:
  33.     def __init__(self, source, amount):
  34.         self.source = source
  35.         self.amount = amount
  36.  
  37.  
  38. class Weapon:
  39.     attack = None
  40.     defense = None
  41.  
  42.     def __init__(self, attack, defense):
  43.         self.attack = attack
  44.         self.defense = defense
  45.  
  46.  
  47. class Armor:
  48.     attack = None
  49.     defense = None
  50.  
  51.     def __init__(self, attack, defense):
  52.         self.attack = attack
  53.         self.defense = defense
  54.  
  55.        
  56. class Person:
  57.     health      = 0
  58.     defense     = 0
  59.     attack      = 0
  60.     maxWeight   = 0
  61.     level       = 1
  62.    
  63.     target      = None
  64.     location    = None
  65.  
  66.     money       = 0
  67.     inventory   = []
  68.    
  69.     weapon      = None
  70.     armor       = None
  71.    
  72.     def __init__(self, name):
  73.         self.name = name
  74.  
  75.     def __repr__(self):
  76.         return self.name + (" [hp %d, attack %d, defense %d]" % (self.health, self.calcAttack(), self.calcDefense()))
  77.        
  78.     def doTick(self):
  79.         pass
  80.        
  81.     def doTarget(self, other):
  82.         self.target = other
  83.         return "Персонаж %s взял на мушку персонажа %s" % (self, other)
  84.        
  85.     def doSay(self):
  86.         pass
  87.        
  88.     def doAttack(self):
  89.         self.target.doHurt(Kick(self, self.calcAttack())),
  90.  
  91.     def doUse(self, itemIndex : int):
  92.         pass
  93.        
  94.     def doHurt(self, kick : Kick):
  95.         damage = int(kick.amount / self.calcDefense())
  96.         self.health -= min(damage, self.health)
  97.         print("Персонаж %s нанес персонажу %s %d очк. урона" % (kick.source, self, damage))
  98.  
  99.         if self.health == 0:
  100.             print("Персонаж %s умер" % (self))
  101.        
  102.     def addItem(self, item):
  103.         self.inventory.push(item)
  104.  
  105.     def wearArmor(self, armor : Armor):
  106.         self.armor = armor
  107.  
  108.     def equipWeapon(self, weapon : Weapon):
  109.         self.weapon = weapon
  110.        
  111.     def calcDefense(self):
  112.         calc = self.defense
  113.         for item in self.inventory:
  114.             calc = calc + item.defense
  115.         if self.armor:
  116.             calc = calc + self.armor.defense
  117.         return calc + calc * (self.level * 0.2)
  118.    
  119.     def calcAttack(self):
  120.         calc = self.attack
  121.         for item in self.inventory:
  122.             calc = calc + item.attack
  123.         if self.weapon:
  124.             calc = calc + self.weapon.attack
  125.         return calc + calc * (self.level * 0.2)
  126.  
  127.  
  128. # Weapons and Armor
  129. class IronStick(Weapon):
  130.     def __init__(self):
  131.         Weapon.__init__(self, 10, 1)
  132.  
  133.  
  134. class LightArmor(Armor):
  135.     def __init__(self):
  136.         Armor.__init__(self, 0, 7)
  137.  
  138.  
  139. # Hero
  140. class Hero(Person):
  141.     def __init__(self):
  142.         Person.__init__(self, "Игрок")
  143.         self.health = 100
  144.         self.defense = 0
  145.         self.attack = 1
  146.         self.maxWeight = 300
  147.         self.level = 1
  148.  
  149.  
  150. class Enemy(Person):
  151.     def __init__(self, name):
  152.         Person.__init__(self, name)
  153.         self.health = 100
  154.         self.defense = 4
  155.         self.attack = 7
  156.         self.level = 2
  157.  
  158.  
  159. me = Hero()
  160. me.wearArmor(LightArmor())
  161. me.equipWeapon(IronStick())
  162.  
  163. enemy = Enemy("Сраное говно")
  164.  
  165. print(me)
  166. print(enemy)
  167.  
  168. me.doTarget(enemy)
  169. enemy.doTarget(me)
  170.  
  171. while (me.health > 0):
  172.     me.doAttack()
  173.     enemy.doAttack()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement