Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·108 lines (89 loc) · 3.34 KB
/
Copy pathmain.py
File metadata and controls
executable file
·108 lines (89 loc) · 3.34 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
# Check difference between randint and randrange
# Move "common_enemies" variable so it's not global
import random
from boss import Boss
from character import Character
from player import Player
from item import Item
from shop import Shop
import utils
bosses = []
common_enemies = []
shop_items = []
potion_types = []
all_potions = []
def start_battle(player, enemy=None):
global common_enemies, all_potions
if (enemy == None):
enemy = common_enemies[random.randint(0, len(common_enemies) - 1)]
print("\t# " + enemy.name + " appears! #\n")
fighting = True
while (fighting and enemy.is_alive() and player.is_alive()):
utils.display_status(player, enemy)
battle_choice = utils.get_battle_choice(player, enemy)
if (battle_choice == 1):
damage_dealt = random.randint(0, player.strength - 1)
damage_taken = enemy.do_attack()
enemy.health -= damage_dealt
player.health -= damage_taken
print("\t> You strike the " + enemy.name +
" for " + str(damage_dealt) + " damage.")
print("\t> You receive " + str(damage_taken) + " in retaliation!")
if (battle_choice == 2):
potion = utils.get_potion_choice(all_potions)
if (potion in player.inventory):
player.drink(potion)
else:
print("\tYou don't have any " + potion.name + "!")
if (battle_choice == 3):
print("------")
print("\tYou run away from the " + enemy.name + "!")
print("------")
fighting = False
if (not player.is_alive()):
print("\n****** You crawl out of the dungeon to live and fight another day. ******\n\n")
return
if (not enemy.is_alive()):
dropped_illbane = random.randint(1, 3)
player.illbane += dropped_illbane
print("------")
print("\t" + enemy.name + " has been defeated!")
print("\tYou find " + str(enemy.gold) +
" gold on the " + enemy.name + "!")
print("\tYou collect " + str(dropped_illbane) +
" illbane from " + enemy.name + "!")
player.gold += enemy.gold
item = enemy.get_dropped_object()
if item != None:
print("\t" + enemy.name + " has dropped " + item.name + "!")
player.inventory.append(item)
print("------")
def sacrifice_illbane(player):
global bosses
if player.illbane >= 4:
player.illbane -= 4
start_battle(player, bosses[random.randint(0, len(bosses) - 1)])
else:
print("\nYou do not have enough illbane!\n")
def run_game():
global bosses, common_enemies, shop_items, all_potions
common_enemies = utils.init_common_enemies()
bosses = utils.init_bosses()
all_potions = utils.get_all_potions()
shop = Shop(all_potions)
player = Player("The player", 100, 30, 20, 1000,
[all_potions[0]])
player.illbane = 1
must_quit = False
while player.is_alive() and not must_quit:
idle_choice = utils.get_idle_choice(player)
if (idle_choice == 1):
start_battle(player)
if (idle_choice == 2):
shop.visit(player)
if (idle_choice == 3):
sacrifice_illbane(player)
if (idle_choice == 4):
must_quit = True
if __name__ == "__main__":
run_game()