-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCATopalian_Python_Creature_Class.py
More file actions
113 lines (85 loc) · 2.19 KB
/
CATopalian_Python_Creature_Class.py
File metadata and controls
113 lines (85 loc) · 2.19 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# CATopalian_Python_Creature_Class.py
# base creature data
creature_data = [
{
'name': 'Sparkling',
'power': 'Lightning Burst',
'hp': 35,
'type': 'Electric',
# new property stored directly in the object
'charge': 100
},
{
'name': 'Flarecub',
'power': 'Ember Roar',
'hp': 39,
'type': 'Fire'
},
{
'name': 'Aqualin',
'power': 'Tidal Pulse',
'hp': 47,
'type': 'Water'
}
]
####
# shortcuts
def cl(message):
print(message)
####
# find item by name (case insensitive)
def fibn(array, name):
for item in array:
if item['name'].lower() == name.lower():
return item
return None
####
class Creature:
def __init__(self, info):
# base properties
self.name = info['name']
self.power = info['power']
self.hp = info['hp']
self.type = info['type']
def say_name(self):
cl(self.name)
def attack(self):
cl(self.name + ' used ' + self.power)
####
class Sparkling(Creature):
def __init__(self, info):
super().__init__(info)
# new extended class only properties
self.charge = info['charge']
self.electric_affinity = 0.85
def special_move(self):
cl(self.name + ' unleashed Thunder Spiral!')
def use_charge(self):
# draining charge
self.charge = self.charge - 10
cl(self.name + ' now has ' + str(self.charge) + ' charge left')
def electric_dash(self):
cl(self.name + ' is Dashing with Current.')
####
# create instance from array data
sparkling_info = fibn(creature_data, 'Sparkling')
sparkling = Sparkling(sparkling_info)
####
# sparkling actions
sparkling.say_name()
sparkling.special_move()
sparkling.use_charge()
sparkling.electric_dash()
####
"""
Sparkling
Sparkling unleashed Thunder Spiral!
Sparkling now has 90 charge left
Sparkling is Dashing with Current.
"""
####
# Dedicated to God the Father
# All Rights Reserved Christopher Andrew Topalian Copyright 2000-2025
# https://github.com/ChristopherTopalian
# https://github.com/ChristopherAndrewTopalian
# https://sites.google.com/view/CollegeOfScripting