-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharacter.py
89 lines (65 loc) · 2.18 KB
/
character.py
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
# A file that defines all the character classes, including fighters and NPCs
import abc
# Global constants
HP_IND = 0
STR_IND = 1
MAG_IND = 2
SKL_IND = 3
SPD_IND = 4
LUK_IND = 5
DEF_IND = 6
RES_IND = 7
# The character class only has a name, a spawn location, and an icon.
class Character:
def __init__(self, name, position, icon):
self.name = name
self.position = position
# The NPC class doesn't do anything special at this point.
# Shopkeeping and etc will be implemented later.
class NPC:
def __init__(self, name):
self.Character = Character(name, position, icon)
# The fighter class is an abstract class for the hero and the enemy.
# Contains everything both a hero and an enemy can do.
class Fighter:
def __init__(self, name, position, growthRate, base, icon):
# Delegate to superclass ctor
self.Character = Character(name, position, icon)
# Assign and initialize some attributes
self.level = 1
self.growthRate = growthRate
self.setStats(base)
def levelUp(self):
def setStats(self, base):
self.maxHP = self.HP = base[HP_IND]
self.strength = base[STR_IND]
self.magic = base[MAG_IND]
self.skill = base[SKL_IND]
self.speed = base[SPD_IND]
self.defense = base[DEF_IND]
self.resist = base[RES_IND]
# A hero class.
class Hero:
def __init__(self, name, position, growthRate, base, icon):
# Delegate to superclass ctor
self.Fighter = Fighter(name, position, growthRate, base, icon)
# Initialize stuff
self.EXP = 0
self.initialize()
def initialize(self):
'''
Initialize the hero.
'''
# An enemy class.
class Enemy:
def __init__(self, name, position, growthRate, base, icon, floorNumber):
# Deletegate to superclass ctor
self.Fighter = Fighter(name, position, growthRate, icon)
self.initialize(floorNumber)
def initialize(self, floorNumber):
'''
Initialize the enemy based on current floor.
'''
# Based on floor number, level up this many times
for levelTime in range(floorNumber):
self.Fighter.levelUp()