-
Notifications
You must be signed in to change notification settings - Fork 2
/
classes.py
98 lines (88 loc) · 3.34 KB
/
classes.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
import random
import time
from pygame import mixer
mixer.init()
punch_se = mixer.Sound("audio/Punch.wav")
kick_se = mixer.Sound("audio/Kick.wav")
special_se = mixer.Sound("audio/rage_of_blades.wav")
class Character():
def __init__(self, name, health, punch_power, kick_power, special_power, special_name, defense, sex):
self.name = name
self.health = health
self.punch_power = punch_power
self.kick_power = kick_power
self.special_power = special_power
self.special_name = special_name
self.defense = defense
self.sex = sex
def __str__(self):
return """
Name: %s
Health: %s
Punch Power: %s
Kick Power: %s
Special Power: %s (%d)
Defense: %s
""" % (self.name, self.health, self.punch_power, self.kick_power, self.special_name, self.special_power, self.defense)
def kick(self, opponent):
if self.kick_power == "low":
kick = random.randint(1, 3)
if self.kick_power == "medium":
kick = random.randint(4, 6)
if self.kick_power == "high":
kick = random.randint(7, 9)
defense = opponent.add_defense()
if defense > kick:
defense = kick
opponent.health -= (kick - defense)
mixer.Sound.play(kick_se)
time.sleep(1)
print("\n\n%s kicked for %d damage to %s." %
(self.name, kick, opponent.name))
print("%s blocked with %d defense and has %d health left." %
(opponent.name, defense, opponent.health))
def punch(self, opponent):
if self.punch_power == "low":
punch = random.randint(1, 3)
if self.punch_power == "medium":
punch = random.randint(4, 6)
if self.punch_power == "high":
punch = random.randint(7, 9)
defense = opponent.add_defense()
if defense > punch:
defense = punch
opponent.health -= (punch - defense)
mixer.Sound.play(punch_se)
time.sleep(1)
print("\n\n%s punched for %d damage to %s." %
(self.name, punch, opponent.name))
print("%s blocked with %d defense and has %d health left." %
(opponent.name, defense, opponent.health))
def special(self, opponent):
defense = opponent.add_defense()
if defense > self.special_power:
defense = self.special_power
opponent.health -= (self.special_power - defense)
mixer.Sound.play(special_se)
time.sleep(4)
print("\n\n%s used %s for %d damage to %s." %
(self.name, self.special_name, self.special_power, opponent.name))
print("%s blocked with %d defense and has %d health left." %
(opponent.name, defense, opponent.health))
def rand_attack(self, opponent):
random_selection = random.randint(1, 3)
if random_selection == 1:
self.punch(opponent)
if random_selection == 2:
self.kick(opponent)
if random_selection == 3:
self.special(opponent)
def is_alive(self):
return self.health > 0
def add_defense(self):
if self.defense == "low":
return random.randint(1, 3)
if self.defense == "medium":
return random.randint(4, 6)
if self.defense == "high":
return random.randint(7, 9)