-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattacks.py
More file actions
65 lines (50 loc) · 2.54 KB
/
attacks.py
File metadata and controls
65 lines (50 loc) · 2.54 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
56
57
58
59
60
61
62
63
64
65
import random as rd
from copy import copy
class Attack(object):
def __init__(self, name, power, accuracy, group, combo={}):
self.name = name
self.power = power
self.accuracy = accuracy
self.group = group
self.combo = combo
def show(self, index=None):
index_amend = '' if index is None else f'{index}) '
print(f'{index_amend}A {self.group} attack:\n Name: {self.name}\n Power: {self.power}\n Accuracy: {self.accuracy}%')
if self.combo:
print(f' NOTE: This attack does {list(self.combo.values())[0]} more damage for enemies of type {list(self.combo.keys())[0]}')
print()
def damage(self, enemy):
random_chance = rd.randint(0, 100)
damage = 0
if random_chance <= self.accuracy:
damage = rd.randint(int(self.power/10), 20)
else:
print('\nThis attack was not accurate. It missed the enemy.\n')
combo_value = self.combo[enemy.pok_type.lower()] if enemy.pok_type.lower() in self.combo else 1
return int(damage * combo_value)
class TypeAttack(object):
def __init__(self, pok_type):
self.pok_type = pok_type
self.attacks = self.set_attacks()
def __getitem__(self, index):
return self.attacks[index]
def __len__(self):
return len(self.attacks)
def set_attacks(self):
if self.pok_type.lower() == "water":
return [Attack("Bubble", 40, 100, self.pok_type.capitalize(), {"fire": 1.5}),
Attack("Hydro Pump", 185, 30, self.pok_type.capitalize(), {"fire": 1.5}),
Attack("Surf", 70, 90, self.pok_type.capitalize(), {"fire": 1.5})]
elif self.pok_type.lower() == "fire":
return [Attack("Ember", 60, 100, self.pok_type.capitalize(), {"grass": 1.5}),
Attack("Fire Punch", 85, 80, self.pok_type.capitalize(), {"grass": 1.5}),
Attack("Flame Wheel", 70, 90, self.pok_type.capitalize(), {"grass": 1.5})]
elif self.pok_type.lower() == "grass":
return [Attack("Leaf Storm", 130, 90, self.pok_type.capitalize(), {"water": 1.5}),
Attack("Mega Drain", 50, 100, self.pok_type.capitalize(), {"water": 1.5}),
Attack("Razor Leaf", 55, 95, self.pok_type.capitalize(), {"water": 1.5})]
else:
raise Exception(f'Invalid Pokemon type {self.pok_type}.')
def list_attacks(self):
for index, attack in enumerate(self.attacks, start=1):
attack.show(index)