-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbattle.py
More file actions
141 lines (125 loc) · 7.2 KB
/
battle.py
File metadata and controls
141 lines (125 loc) · 7.2 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
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
import random
import sys
import time
def battle_prep(game_state):
from enemy import Enemy
from game_data import get_enemy_templates
enemy_templates = get_enemy_templates()
enemy_template = random.choice(enemy_templates)
game_state.current_enemy = Enemy(enemy_template, game_state.player.level, game_state.player.bonus_agility)
game_state.current_enemy.choose_next_action()
game_state.player.current_health = game_state.player.get_effective_health()
print("A " + game_state.current_enemy.name + " approaches...")
battle(game_state)
def battle(game_state):
if game_state.player.current_health <= 0:
print("You Lost")
sys.exit(0)
if game_state.current_enemy.health <= 0:
print("You Won")
game_state.player.coins += game_state.current_enemy.coin_value
game_state.player.current_health = game_state.player.get_effective_health()
print(f"While looting the body you found {game_state.current_enemy.coin_value} coins!")
game_state.player.level += 1
from shop import shop_loop
shop_loop(game_state)
battle_choice = input("Check enemy stats, see next action, check stats, use consumable, attack, or defend? ").lower()
if battle_choice == "check enemy stats":
print("It's a " + game_state.current_enemy.name + "!")
print("It has " + str(game_state.current_enemy.health) + " remaining health!")
print("It does " + str(game_state.current_enemy.damage) + " damage!")
print("Its agility is " + str(game_state.current_enemy.agility) + "!")
print(f"It looks {game_state.current_enemy.get_aggressive_text()}!")
battle(game_state)
elif battle_choice == "use consumable":
local_potion_list = [item for item in game_state.player.inventory if "potion" in item.lower()]
for item in local_potion_list:
print(item)
consume = input("Which consumable? ").lower()
match_found = False
for item in game_state.shop_items["potions"]:
if consume == item["name"].lower():
match_found = True
game_state.player.use_potion(item)
game_state.current_enemy.update_agility(game_state.player.bonus_agility)
game_state.player.inventory.remove(item["name"])
break
if not match_found:
print("Item not found!")
battle(game_state)
elif battle_choice == "check stats":
equipped_names = game_state.player.equipment.get_equipped_names()
print("Your equipped sword is " + equipped_names["sword"] + "!")
print("Your equipped armor is " + equipped_names["armor"] + "!")
print("Your current health is " + str(game_state.player.current_health) + "!")
print("Your max health is " + str(game_state.player.get_effective_health()) + "!")
print("Your damage is " + str(game_state.player.get_effective_damage()) + "!")
battle(game_state)
elif battle_choice == "see next action":
if game_state.current_enemy.detectable == True:
print("It looks like the " + game_state.current_enemy.name + " will " + game_state.current_enemy.next_action + "!")
battle(game_state)
else:
print("The enemy isn't readable")
battle(game_state)
elif battle_choice == "defend":
game_state.player.update_potion_effects()
input("Press any key to continue... ")
qte_choices = ['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l']
qte_key = random.choice(qte_choices)
start_time = time.time()
qte_response = input("Quick press " + qte_key + "! ").lower()
elapsed = time.time() - start_time
if qte_response == qte_key and elapsed < game_state.current_enemy.agility and game_state.current_enemy.next_action == "attack":
print("You managed to defend! ")
elif qte_response != qte_key and elapsed < game_state.current_enemy.agility and game_state.current_enemy.next_action == "attack":
print("You pressed the wrong key! ")
game_state.player.current_health -= game_state.current_enemy.damage
print("You took " + str(game_state.current_enemy.damage) + " damage!")
elif qte_response != qte_key and elapsed > game_state.current_enemy.agility and game_state.current_enemy.next_action == "attack":
print("You pressed the wrong key and took too long! ")
game_state.player.current_health -= game_state.current_enemy.damage
print("You took " + str(game_state.current_enemy.damage) + " damage!")
elif qte_response == qte_key and elapsed > game_state.current_enemy.agility and game_state.current_enemy.next_action == "attack":
print("You took too long! ")
game_state.player.current_health -= game_state.current_enemy.damage
print("You took " + str(game_state.current_enemy.damage) + " damage!")
elif game_state.current_enemy.next_action == "defend":
print("There was nothing to defend...")
if game_state.player.current_health <= 0:
print("You Lost")
sys.exit(0)
game_state.current_enemy.choose_next_action()
battle(game_state)
elif battle_choice == "attack":
game_state.player.update_potion_effects()
input("Press any key to continue... ")
qte_choices = ['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l']
qte_key = random.choice(qte_choices)
start_time = time.time()
qte_response = input("Quick press " + qte_key + "! ").lower()
elapsed = time.time() - start_time
if qte_response == qte_key and elapsed < game_state.current_enemy.agility and game_state.current_enemy.next_action == "defend":
print("You managed to attack despite the opponent defending! ")
print("It took " + str(game_state.player.get_effective_damage()) + " damage!")
game_state.current_enemy.health -= game_state.player.get_effective_damage()
elif qte_response != qte_key and elapsed < game_state.current_enemy.agility and game_state.current_enemy.next_action == "defend":
print("You pressed the wrong key! ")
elif qte_response != qte_key and elapsed > game_state.current_enemy.agility and game_state.current_enemy.next_action == "defend":
print("You pressed the wrong key and took too long! ")
elif qte_response == qte_key and elapsed > game_state.current_enemy.agility and game_state.current_enemy.next_action == "defend":
print("You took too long! ")
elif game_state.current_enemy.next_action == "attack":
print("It didn't try to block instead it attacked")
print("It took " + str(game_state.player.get_effective_damage()) + " damage!")
print("You took " + str(game_state.current_enemy.damage) + " damage!")
game_state.current_enemy.health -= game_state.player.get_effective_damage()
game_state.player.current_health -= game_state.current_enemy.damage
if game_state.player.current_health <= 0:
print("You Lost")
sys.exit(0)
game_state.current_enemy.choose_next_action()
battle(game_state)
else:
print("Invalid Option")
battle(game_state)