-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcombat.py
86 lines (73 loc) · 2.81 KB
/
combat.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
import random
from characters import *
from party import *
from pygame import mixer
mixer.init()
mixer.music.set_volume(0.1)
def combat(party):
print("You have entered combat!")
#Generate random enemy
enemy = generate_random_enemy()
party_health = party.get_total_health()
#Greet enemy
print("A " + enemy.name + " approaches!")
pause = input("\nPress any key to continue")
print("\033c")
#While party health + enemy health are > 0, alternate between these
while ((party_health and enemy.health) > 0):
print("Party Health: " + str(party_health) + "\nEnemy Health: " + str(enemy.health) + "\n")
party_health -= enemy_attack(enemy)
print("Party Health: " + str(party_health) + "\nEnemy Health: " + str(enemy.health) + "\n")
pause = input("\nPress any key to continue")
enemy.health -= party_attack(party)
print("Party Health: " + str(party_health) + "\nEnemy Health: " + str(enemy.health) + "\n")
pause = input("\nPress any key to continue")
if(party_health <= 0):
lose_fight(party, enemy)
if(enemy.health <= 0):
win_fight(party, enemy)
def lose_fight(party, enemy):
print("You lost the fight! Your party will take " + str(enemy.power) + " points of damage distributed across all members")
print("The enemies stole some of your supplies!")
for character in party.party_list:
character.health -= enemy.power/party.total_alive_members()
party.food -= 10
party.hand_sanitizer -= 10
party.fuel -= 10
party.phone_charge -= 10
def win_fight(party, enemy):
print("You won the fight! Your party scavenges some supplies from the loot")
party.food += 10
party.hand_sanitizer += 10
party.fuel += 10
party.phone_charge += 10
#Enemy attacks
def enemy_attack(enemy):
sound("battle.wav")
print(enemy.name + " attacks the party for " + str(enemy.power) + " Damage!")
return enemy.power
#Player attacks
def party_attack(party):
sound("battle.wav")
party_power = party.get_total_morale()/25 + party.get_total_health()/25
print("You attack the enemy for " + str(party_power) + " Damage!")
return party_power
def generate_random_enemy():
enemy_type = random.randrange(0,3)
if enemy_type == 0:
enemy = Enemy("Gathering of Rabid Millenials", 100, 100)
if enemy_type == 1:
enemy = Enemy("Pack of Zombies", 75, 75)
if enemy_type == 2:
enemy = Enemy("Group of Anti-Vaxx Karens", 50, 125)
if enemy_type == 3:
enemy = Enemy("Rave of Spring Breakers", 125, 50)
return enemy
class Enemy:
def __init__(self, name, power, health):
self.name = name
self.power = power
self.health = health
def sound(file):
sound = mixer.Sound("audio/%s" % file)
return mixer.Sound.play(sound)