Skip to content

Commit 36ee87e

Browse files
author
Christopher Barnes
committed
add inventory, start of save, adjust printables to seperate file
1 parent 42ac2a5 commit 36ee87e

File tree

7 files changed

+424
-136
lines changed

7 files changed

+424
-136
lines changed

dungeon_heroes.py

Lines changed: 71 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from sty import fg, bg, ef, rs, RgbFg
2+
from printables import print_case, print_chest
3+
from save_game import Save_Game
24
from prompts import prompt_usr
35
from hero import Hero
46
from loot import Loot
@@ -32,30 +34,27 @@
3234

3335
def intro():
3436
#Display for Intro
35-
print("""
37+
print(fg.green, bg.black +"""
3638
******----******----******
3739
Welcome to Dungeon Heroes!
38-
******----******----******
40+
******----******----******""" + fg.red + """
41+
\^~~~~\\ ) ( /~~~~^/
42+
) *** \\ {**} / *** (
43+
) *** \\_ ^^ _/ *** (
44+
) **** vv **** (
45+
)_**** ****_(
46+
)*** m m ***( """ + fg.rs, bg.rs)
3947

40-
\^~~~~\\ ) ( /~~~~^/
41-
) *** \\ {**} / *** (
42-
) *** \\_ ^^ _/ *** (
43-
) **** vv **** (
44-
)_**** ****_(
45-
)*** m m ***(
46-
""")
47-
4848
def load_game():
49-
response = prompt_usr(
50-
"Select (N)ew game or (C)ontinue: \t", "string").upper()
49+
response = prompt_usr("Select (N)ew game or (C)ontinue: \t", "string").upper()
5150
if(response == "C"):
52-
#try:
53-
#hero = SaveGame.load("saveGame.txt")
54-
#print("File Loaded")
55-
#catch(FileNotFoundException e):
56-
#print("SaveGame not found")
57-
#createCharacter(g_input)
58-
hero = Hero("bill", "warrior")
51+
try:
52+
hero = Save_Game.load("saveGame.txt")
53+
print("File Loaded")
54+
except FileNotFoundError:
55+
print("SaveGame not found")
56+
create_character()
57+
#hero = Hero("bill", "warrior")
5958
return hero
6059
elif(response == "N"):
6160
hero = restart()
@@ -121,16 +120,16 @@ def enter_room():
121120
print("***************************")
122121
print("You have entered a new room")
123122
treasure = 0
124-
"""
123+
125124
levelUp = False
126125

127126
if(hero.level == 4 or hero.level == 8 or hero.level == 12):
128127
if(hero.xp == 0):
129-
print()
130-
treasure = (int)(Math.floor(Math.random()*2) + 1) * 1 #1 or 2
131-
getlevelUp(treasure)
132-
levelUp = False
133-
"""
128+
print()
129+
treasure = random.randint()*2 + 1 * 1 #1 or 2
130+
#self.getlevelUp(treasure)
131+
levelUp = False
132+
134133
#get our random room
135134
room_type = random.random()*100# 0.0 --> 99.9999
136135
#are we at the end of the dungeon?
@@ -141,19 +140,19 @@ def enter_room():
141140
if(room_type >= EPIC_TREASURE_CHANCE):
142141
print("$$$EPIC TREASURE ROOM$$$")
143142
print_chest()
144-
#treasure = (int)(Math.floor(Math.random()*2) + 1) * 100 #100 or 200
143+
treasure = random.randint()*2 + 1 * 100 #100 or 200
145144

146145
#is this an advanced treasure room?
147146
elif(room_type >= ADVANCED_TREASURE_CHANCE):
148147
print("$$$Advanced Treasure Room$$")
149148
print_chest()
150-
#treasure = (int)(Math.floor(Math.random()*2) + 1) * 10 #10 or 20
149+
treasure = random.randint()*2 + 1 * 10 #10 or 20
151150

152151
#is this a basic treasure room?
153152
elif(room_type >= BASIC_TREASURE_CHANCE):
154153
print("Basic Treasure Room!")
155154
print_chest()
156-
#treasure = (int)(Math.floor(Math.random()*2) + 1) * 1 #1 or 2
155+
treasure = random.randint()*2 + 1 * 1 #1 or 2
157156

158157
#otherwise we fight a monster.
159158
else:
@@ -162,7 +161,7 @@ def enter_room():
162161
return False #they have died... game over
163162

164163
#gives the player randomly rolled treasure
165-
#self.get_treasure(treasure)
164+
get_treasure(treasure)
166165

167166
#handle Choosing whats next
168167
return choice()
@@ -195,84 +194,60 @@ def choice():
195194
# quit game
196195
elif(response == "Q"):
197196
return False
198-
"""
199197
try:
200-
SaveGame.save(hero, "save_game.txt")
198+
Save_Game.save(hero, "save_game.txt")
201199
return False
202200
except FileNotFoundError:
203201
print("There was a problem Saving, file not found")
204202
return False
205-
"""
206203
return True
207204

208205
#getTreasure - rolls random treasure and allows the user to take it(or convert to money)
209206
#@param int treasure(1s are basic, 10s are advanced, 100s are epic treasure)
210207
def get_treasure(treasure):
211-
# build a list of items that dropped
212-
lootItems = []
213-
# number of basic items
214-
basic = treasure % 10
215-
# advanced items
216-
advanced = treasure / 10 % 10
217-
# epic items
218-
epic = treasure / 100 % 10
219-
# setup the basic items
220-
for i in range(basic):
221-
lootItems.append(loot.getBasic(hero))
222-
# setup the advanced items
223-
for i in range(advanced):
224-
lootItems.append(loot.getAdvanced(hero))
225-
# setup the epic items
226-
for i in range(epic):
227-
lootItems.append(loot.getEpic(hero))
208+
# build a list of items that dropped
209+
lootItems = []
210+
# number of basic items
211+
basic = treasure % 10
212+
# advanced items
213+
advanced = treasure / 10 % 10
214+
# epic items
215+
epic = treasure / 100 % 10
216+
# setup the basic items
217+
for i in range(basic):
218+
lootItems.append(loot.getBasic(hero))
219+
# setup the advanced items
220+
for i in range(advanced):
221+
lootItems.append(loot.getAdvanced(hero))
222+
# setup the epic items
223+
for i in range(epic):
224+
lootItems.append(loot.getEpic(hero))
228225

229-
if(len(lootItems) > 0):
230-
# print a list of the items
231-
print()
232-
print("***************")
233-
print("Treasure Items")
234-
print("**************")
235-
for i in lootItems:
236-
print("{} {}\n".format(i.uniqueID, i.name))
237-
# ask the user whether they want to(S)ell items or (K)eep items
238-
valid_response = False
239-
response = ""
240-
while(not response == "S" and not response == "K"):
241-
response = prompt_usr(
242-
"Do you want to (S)ell or (K)eep the items (duplicates will be added to your current weapons): \t", "string")
243-
# sell
244-
if(response == "S"):
245-
for i in lootItems:
246-
hero.gold += i.price / 10
247-
print("You wisely sell the items")
248-
else:
249-
# put items in inventory(upgrade if duplicate)
250-
for i in lootItems:
251-
hero.gold += hero.inventory.append(i)
252-
print_case()
253-
print("You wisely put the items in your backpack.")
254-
255-
def print_case():
256-
print("""
257-
____
258-
.--[[__]]---.
259-
.-----------.|
260-
| ||
261-
| ||
262-
|___________|/ """)
263-
264-
def print_chest():
265-
print("""
266-
267-
__________
268-
/\\____;;___\\
269-
| / /
270-
`. ()()vv() .
271-
|\\()()^^() \\
272-
| |---------|
273-
\\ | )) |
274-
\\|_________|
275-
""")
226+
if(len(lootItems) > 0):
227+
# print a list of the items
228+
print()
229+
print("***************")
230+
print("Treasure Items")
231+
print("**************")
232+
for i in lootItems:
233+
print("{} {}\n".format(i.uniqueID, i.name))
234+
# ask the user whether they want to(S)ell items or (K)eep items
235+
valid_response = False
236+
response = ""
237+
while(not response == "S" and not response == "K"):
238+
response = prompt_usr(
239+
"Do you want to (S)ell or (K)eep the items (duplicates will be added to your current weapons): \t", "string")
240+
# sell
241+
if(response == "S"):
242+
for i in lootItems:
243+
hero.gold += i.price / 10
244+
print("You wisely sell the items")
245+
else:
246+
# put items in inventory(upgrade if duplicate)
247+
for i in lootItems:
248+
hero.gold += hero.inventory.append(i)
249+
print_case()
250+
print("You wisely put the items in your backpack.")
276251

277252
if __name__ == "__main__":
278253
#Print a cool intro

hero.py

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from monster_list import MonsterList
22
from prompts import prompt_usr
3+
from printables import print_money, print_food
34

45
class Hero():
56
def __init__(self, name, character_class=None):
@@ -93,14 +94,14 @@ def give_food(self, food):
9394
print("Food Looted: {}! Your new total is: {}".format(food, self.food))
9495
else:
9596
print("You have the max amount of food you can hold")
96-
self.print_food()
97+
print_food()
9798
return self.food
9899

99100
#give_gold --> gives gold to the player
100101
def give_gold(self, gold):
101102
self.gold += gold
102103
print("Gold Looted: {}! Your new total is: {}".format(gold, self.gold))
103-
self.print_money()
104+
print_money()
104105
return self.gold
105106

106107
#give_XP --> gives xp to the player
@@ -168,7 +169,7 @@ def fight_monster(self):
168169
valid_input = True
169170
else:
170171
print("Invalid input!")
171-
# end validInput while
172+
# end valid_input while
172173

173174
# generate an attack
174175
flee = cur_monster.singleAttack(self, response)
@@ -231,7 +232,7 @@ def rest(self):
231232
print("\nYou are out of food and cannot regain stamina. STAMINA: {}".format(
232233
self.stamina))
233234

234-
self.print_food()
235+
print_food()
235236
print("Food remaining: {}".format(self.food))
236237

237238
def __repr__(self):
@@ -243,28 +244,3 @@ def __repr__(self):
243244
and speed of:\t {}
244245
""".format(self.name, self.health, self.max_health, self.stamina, self.max_stamina, self.strength, self.defense, self.protection, self.speed))
245246

246-
def print_food(self):
247-
print("""
248-
.-'''''-.
249-
|'-----'|
250-
|-.....-|
251-
| |
252-
| |
253-
_,._ | |
254-
__.o` o`\"-. | |
255-
.-O o `\"-.o O )_,._ | |
256-
( o O o )--.-\"`O o\"-.`'-----'`
257-
'--------' ( o O o)
258-
`----------` """)
259-
260-
def print_money(self):
261-
print("""
262-
\\`\\/\\/\\/`/
263-
)======(
264-
.' '.
265-
/ _||__ \\
266-
/ (_||_ \\
267-
| __||_) |
268-
| || |
269-
'. .'
270-
'------------' """)

0 commit comments

Comments
 (0)