Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Common game entity classes
- class World:
- locations = [];
- def doTick(self):
- for location in locations:
- location.doTick()
- class Location:
- persons = [];
- def __init__(self, name):
- self.name = name
- def __repr__(self):
- return self.name
- def doTick(self):
- for person in persons:
- person.doTick()
- class Item:
- weight = None
- price = None
- defence = 0
- attack = 0
- class Kick:
- def __init__(self, source, amount):
- self.source = source
- self.amount = amount
- class Weapon:
- attack = None
- defense = None
- def __init__(self, attack, defense):
- self.attack = attack
- self.defense = defense
- class Armor:
- attack = None
- defense = None
- def __init__(self, attack, defense):
- self.attack = attack
- self.defense = defense
- class Person:
- health = 0
- defense = 0
- attack = 0
- maxWeight = 0
- level = 1
- target = None
- location = None
- money = 0
- inventory = []
- weapon = None
- armor = None
- def __init__(self, name):
- self.name = name
- def __repr__(self):
- return self.name + (" [hp %d, attack %d, defense %d]" % (self.health, self.calcAttack(), self.calcDefense()))
- def doTick(self):
- pass
- def doTarget(self, other):
- self.target = other
- return "Персонаж %s взял на мушку персонажа %s" % (self, other)
- def doSay(self):
- pass
- def doAttack(self):
- self.target.doHurt(Kick(self, self.calcAttack())),
- def doUse(self, itemIndex : int):
- pass
- def doHurt(self, kick : Kick):
- damage = int(kick.amount / self.calcDefense())
- self.health -= min(damage, self.health)
- print("Персонаж %s нанес персонажу %s %d очк. урона" % (kick.source, self, damage))
- if self.health == 0:
- print("Персонаж %s умер" % (self))
- def addItem(self, item):
- self.inventory.push(item)
- def wearArmor(self, armor : Armor):
- self.armor = armor
- def equipWeapon(self, weapon : Weapon):
- self.weapon = weapon
- def calcDefense(self):
- calc = self.defense
- for item in self.inventory:
- calc = calc + item.defense
- if self.armor:
- calc = calc + self.armor.defense
- return calc + calc * (self.level * 0.2)
- def calcAttack(self):
- calc = self.attack
- for item in self.inventory:
- calc = calc + item.attack
- if self.weapon:
- calc = calc + self.weapon.attack
- return calc + calc * (self.level * 0.2)
- # Weapons and Armor
- class IronStick(Weapon):
- def __init__(self):
- Weapon.__init__(self, 10, 1)
- class LightArmor(Armor):
- def __init__(self):
- Armor.__init__(self, 0, 7)
- # Hero
- class Hero(Person):
- def __init__(self):
- Person.__init__(self, "Игрок")
- self.health = 100
- self.defense = 0
- self.attack = 1
- self.maxWeight = 300
- self.level = 1
- class Enemy(Person):
- def __init__(self, name):
- Person.__init__(self, name)
- self.health = 100
- self.defense = 4
- self.attack = 7
- self.level = 2
- me = Hero()
- me.wearArmor(LightArmor())
- me.equipWeapon(IronStick())
- enemy = Enemy("Сраное говно")
- print(me)
- print(enemy)
- me.doTarget(enemy)
- enemy.doTarget(me)
- while (me.health > 0):
- me.doAttack()
- enemy.doAttack()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement