-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfantasy_RPG.py
More file actions
112 lines (81 loc) · 2.48 KB
/
fantasy_RPG.py
File metadata and controls
112 lines (81 loc) · 2.48 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
#python3
# I am trying to build this kind of RPG from school. I coded it in JAVA before...
'''
-------------------- RULES ---------------------------------------------------------
There are Heroes and there are Monsters
They each have HealthPoints (HP) and an Attack-Value (ATT)
The ATT is constructed out of their Strength (STR) and their Attack-Bonus (BONUS)
The BONUS actually belongs to Weapons and not to a Hero/Monster
Weapons can be equipped by Heroes/Monsters
A Hero can fight a Monster. The One with the Higher Attack-Value (ATT) Wins
The Loser loses a HealthPoint (HP)
When one of the player's HealthPoints (HP) drops below 0 the Battle Ends
Heroes have Names.
'''
# HERO CLASS
class Hero:
# initiation
def __init__(self, name, STR, ATT, HP):
self.name = name
self.STR = STR
self.ATT = ATT
self.HP = HP
# getters
def get_name(self):
return self.name
def get_STR(self):
return self.STR
def get_ATT(self):
return self.ATT
def get_HP(self):
return self.HP
# setters
def set_name(self, new_name):
self.name = new_name
def set_STR(self, new_STR):
self.STR = new_STR
def set_ATT(self, new_ATT):
self.ATT = new_ATT
def set_HP(self, new_HP):
self.HP = new_HP
# methods
def attack(self, Monster):
if Monster.ATT > self.ATT:
self.HP -= 1
else:
Monster.HP -= 1
# MONSTER CLASS
class Monster:
# initiation
def __init__(self, ATT, HP):
self.ATT = ATT
self.HP = HP
# getters
def get_ATT(self):
return self.ATT
def get_HP(self):
return self.HP
# setters
def set_ATT(self, new_ATT):
self.ATT = new_ATT
def set_HP(self, new_HP):
self.HP = new_HP
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# main func
def main():
# creating players
h1 = Hero("James", 10, 5, 100)
m1 = Monster(4, 100)
# testing section for attacks
try:
print("\nBEFORE:\n")
print("Hero's Health: ", h1.get_HP())
print("Monster's Health: ", m1.get_HP())
h1.attack(m1)
print("\nAFTER:\n")
print("Hero's Health: ", h1.get_HP())
print("Monster's Health: ", m1.get_HP())
except:
print("Error(s) occurred")
# calling the main-func
main()