-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenemy.py
More file actions
55 lines (48 loc) · 1.96 KB
/
enemy.py
File metadata and controls
55 lines (48 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import random
from Person import Person
from random import randint
from weapon_and_spells import Weapon
from weapon_and_spells import Spell
class Enemy(Person):
def __init__(self, health, mana, damage, spell=None, weapon=None):
assert type(health) is int, 'health is not int'
assert type(mana) is int, 'mana is not int'
assert type(damage) is float or type(damage) is int, 'damage is not float'
assert damage > 0, 'damage must be positeve'
super().__init__(health, mana, spell, weapon)
self.damage = damage
self.max_mana = mana
self.spell = None
self.weapon = None
@classmethod
def generate_enemy(self):
ran = randint(0, 1)
enemy = Enemy(health=random.randint(80, 100), mana=random.randint(
50, 80), damage=random.randint(20, 40))
if ran == 1:
enemy.equip(Weapon(name='Base Sword', damage=randint(40, 60)))
else:
enemy.learn(Spell(name='Dark Magic', damage=randint(
40, 60), mana_cost=randint(10, 20), cast_range=2))
return enemy
def attack(self, by=None):
if by == None:
damage = self.damage
assert type(by) is str, 'by is not string'
assert by == 'weapon' or by == 'spell', 'by= is not spell or weapon'
if by == "spell" and isinstance(self.spell, Spell):
if self.can_cast():
damage = self.spell.get_damage()
self.mana = self.used_mana_to_cast_spell()
else:
damage = 0
print(f"The enemy can\'t cast spell.")
if by == 'weapon' and isinstance(self.weapon, Weapon):
if self.weapon != None:
damage = self.weapon.get_damage()
else:
damage = 0
print(f"The enemy currently doesn\'t have any weapons.")
return damage
def __str__(self):
return f'Enemy (health = {self.health} , mana = {self.mana}))'