-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_game.py
176 lines (142 loc) · 5.73 KB
/
my_game.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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import random
# Creating the superClass that the other classes will inherit from:
class Character:
def __init__(self, name, shield=0, life=100):
self.name = name
self.shield = shield
self.life = life
def take_damage(self, damage: int):
"""
Take_damage function will reduce the life or shield of the character based on the damage
inflicted by the opponent
:param damage: based on the attack chosen by the opponent damage my very
:return: self.life and or self.shield after the attack
"""
if damage < self.life > 0: # TODO solve issue if damage > 100
if self.shield:
if damage > self.shield:
damage_took = damage - self.shield
self.life -= damage_took
self.shield = 0
print(f"{self.name} Shield down to {self.shield}, life is now {self.life}")
elif self.shield != 0:
self.shield -= damage
print(f"Shield down to {self.shield}")
elif self.shield == 0:
self.life -= damage
print(f"{self.name} Shield down to {self.shield}, life is now {self.life}")
else:
print(f"{self.name} is dead you won!!!")
self.life = 0
def eat_spam(self):
chance = random.randint(1, 4)
if self.life == 0:
if chance == 2:
self.life = random.randint(40, 60)
print(f"The magical potion worked you got one more chance an winning."
f"life has been restored to: {self.life}")
else:
print("Looks like the potion was a fake you lose!")
# Creating individual characters to choose from *all based on the superclass: Character
class Warrior(Character):
def __init__(self, name, shield=50, life=100):
super().__init__(name, shield, life)
self.name = name
self.shield = shield
self.life = life
self.used = False
@staticmethod
def sword_swing(enemy: Character):
"""
Function that allow us to attack the enemy
:param enemy: The enemy we are attacking
"""
power = random.randint(20, 40)
enemy.take_damage(power)
print(f"You attacked with the sward swing ability, {enemy.name}")
@staticmethod
def spam_trow(enemy: Character):
"""An attack function, you trow a piece of old spam at the enemy and give him damage"""
power = 25
enemy.take_damage(power)
print(f"Spam attack successful enemy life: {enemy.life}")
def kill_them_all(self, enemy):
"""Most powerfull attack function, when used it inflicts the most damage for the Warrior class
Can only be used once and only when playes' life is lower then 50"""
if not self.used:
if self.life <= 50:
damage = random.randint(60, 90)
enemy.take_damage(damage)
self.used = True
print(f"{enemy.name} attacked succesffuly damage done {damage}, {enemy.name} life is {enemy.life}")
else:
print("You can t use this ability yet...")
else:
print("You can only used this ability once...already used...try spam attack")
class Wizard(Character):
def __init__(self, name, shield=50, life=100, mana=200):
super().__init__(name, shield, life)
self.name = name
self.shield = shield
self.life = life
self.name = mana
self.used = False
@staticmethod
def magic_spam(enemy: Character):
damage = random.randint(30, 45)
enemy.take_damage(damage)
print(f"The magic spam worked. Enemy life: {enemy.life}")
@staticmethod
def wand_of_terror(enemy: Character):
damage = random.randint(40, 60)
enemy.take_damage(damage)
print(f"The want of terror attacked enemy life: {enemy.life}")
def thunder_rain(self, enemy: Character):
if not self.used:
if self.life <= 50:
damage = random.randint(60, 90)
enemy.take_damage(damage)
self.used = True
print(f"{enemy.name} attacked successful damage done {damage}, {enemy.name} life is {enemy.life}")
else:
print("You can t use this ability yet...")
else:
print("You can only used this ability once...already used...try spam attack")
def choose_character():
character_choose = input("Please choose 1 to play as a Warrior or 2 to play as a Wizard: ")
global choose_name
choose_name = input("Name your character: ")
global player
if character_choose == "1":
player = Warrior(choose_name)
return player
else:
player = Wizard(choose_name)
return player
def choose_opponent():
global opponent
if player == Warrior:
opponent = Wizard("Slayer")
return opponent
else:
opponent = Warrior("Slayer")
return opponent
def choose_attack():
if isinstance(player, Warrior):
attack = input("Choose your attack move: 1.Sword Swing, 2.Spam Trow, 3.Kill Them All: ")
if attack == "1":
player.sword_swing(opponent)
elif attack == "2":
player.spam_trow(opponent)
elif attack == "3":
player.kill_them_all(opponent)
elif isinstance(player, Wizard):
attack = input("Choose your attack move: 1.Magic Spam, 2.Wand Of Terror, 3.Thunder Rain: ")
if attack == "1":
player.magic_spam(opponent)
elif attack == "2":
player.wand_of_terror(opponent)
elif attack == "3":
player.thunder_rain(opponent)
def main():
pass