Skip to content
This repository was archived by the owner on May 10, 2021. It is now read-only.

Commit 58cedb1

Browse files
HexTreecowboy8625
authored andcommitted
add inventory screen mechanics
1 parent 951eaf9 commit 58cedb1

5 files changed

Lines changed: 57 additions & 69 deletions

File tree

Main.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import time
99

1010
from Mechanics.core_mechanics import *
11-
from script import Screen, Story
1211
from Mechanics.ui_mechanics import *
12+
from script import Screen, Story
1313
import ChangeLog
1414

1515

@@ -56,7 +56,13 @@ def main_game_loop(player, opening=True):
5656

5757
while True:
5858
clear()
59-
move_to = input(
59+
directions = {
60+
"1": "North",
61+
"2": "South",
62+
"3": "East",
63+
"4": "West"
64+
}
65+
choice = input(
6066
"Which way do you want to travel?\n"
6167
f"Coords: {player.pos_x}:{player.pos_y}\n\n"
6268
"(1): North\n"
@@ -67,21 +73,19 @@ def main_game_loop(player, opening=True):
6773
"(6): Inventory\n"
6874
"(7): Look For Resources\n"
6975
"Input a Number:> ")
70-
directions = {
71-
"1": "North",
72-
"2": "South",
73-
"3": "East",
74-
"4": "West"
75-
}
76-
try:
77-
if move_to == 'Quit': # QUIT, I'll take this out after testing
78-
sys.exit()
79-
if move_to == "5":
80-
player.inspect_area()
81-
else:
82-
player.move(directions[move_to])
83-
except KeyError:
76+
if choice in ['1', '2', '3', '4']:
77+
player.move(directions[choice])
78+
elif choice == "5":
79+
player.inspect_area()
80+
elif choice == "6":
81+
inventory_mode(player)
82+
elif choice == "7":
8483
pass
84+
elif choice == 'Quit': # QUIT, I'll take this out after testing
85+
sys.exit()
86+
else:
87+
print(f'Invalid choice {choice}')
88+
pause()
8589

8690
if __name__ == "__main__":
8791
main()

Mechanics/core_mechanics.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def player_select_class():
5353
while True:
5454
choice = input('\n\n'
5555
'SELECT A NUMBER OR TYPE HELP THEN NUMBER:> ')
56-
if choice in "1234":
56+
if choice in ['1', '2', '3', '4']:
5757
return player_options[int(choice) - 1]
5858
# lore is the story and it is found in InfoDics
5959
elif choice[0:4].lower() == 'info':
@@ -145,3 +145,29 @@ def player_select_gender(__pname, __pclass):
145145
gold=100,
146146
equipped_weapon=Items.rusty_dagger
147147
)
148+
149+
# Handle inventory management
150+
def inventory_mode(player):
151+
while True:
152+
Screen.display('INVENTORY')
153+
print('Stored inventory:\n\n' + '\n'.join([f'({i+1}) {item}' for i, item in enumerate(player.inventory)]))
154+
print('\nEquipped weapon: ' + str(player.equipped_weapon))
155+
print('\nEquipped armor: ' + str(player.equipped_armor))
156+
# TODO handle equipping and unequipping
157+
option = input('\n\n'
158+
'(1): Examine item\n'
159+
'(2): Drop item\n'
160+
'(x): Exit inventory screen\n'
161+
'Enter your choice:> ')
162+
if option in ['1', '2']:
163+
index = input('\n\nWhich item? '
164+
'Enter item number: ')
165+
if index.isdigit() and int(index) in range(1, len(player.inventory) + 1):
166+
if option == '1':
167+
clear()
168+
print(player.inventory[int(index)-1].desc())
169+
pause()
170+
elif option == '2':
171+
del player.inventory[int(index)-1]
172+
elif option == 'x':
173+
break

script/Character.py

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ def __init__(self, name, _class, max_health, melee_attack, magic_attack,
4545
self.equipped_weapon = equipped_weapon
4646
self.equipped_armor = equipped_armor
4747

48-
self.inventory = []
48+
self.inventory = [Items.flint, Items.water]
49+
# start with a couple of things so we can play with inventory management
4950
self.inventory_limit = 10
5051

5152
# Map position
@@ -64,8 +65,9 @@ def move(self, _dir):
6465
print(WorldMap.access_information(new_x, new_y, "Name"))
6566
pause()
6667

68+
# TODO methods like this should probably be moved to mechanics
69+
# the script classes shouldn't be dealing with UI, only handling the class instances
6770
def inspect_area(self):
68-
print("======CALLED=======")
6971
info = {
7072
"Name": WorldMap.access_information(self.pos_x, self.pos_y, "Name"),
7173
"Resources": WorldMap.access_information(self.pos_x, self.pos_y, "Resources"),
@@ -78,45 +80,3 @@ def inspect_area(self):
7880
print("Spawns: " + str(info["Spawns"]))
7981
print("Info: " + str(info["Info"]))
8082
pause()
81-
82-
83-
"""
84-
# enemy mobs
85-
# Zombies are a close fighter, he needs to be with in 1 block from mob to attack
86-
zombie = Mob(name="Zombie", max_health=100, melee_attack=10, magic_attack=0, max_mana=0, max_stamina=20,
87-
defense=15, luck=5, mob_class="Undead", gold_drop=10, exp_drop=10, item_drop="Flesh")
88-
yeti = Mob(name="Yeti", max_health=100, melee_attack=10, magic_attack=0, max_mana=0, max_stamina=20,
89-
defense=15, luck=5, mob_class="Undead", gold_drop=10, exp_drop=10, item_drop="Flesh")
90-
bandit = Mob(name="Bandit", max_health=100, melee_attack=10, magic_attack=0, max_mana=0, max_stamina=20,
91-
defense=15, luck=5, mob_class="Human", gold_drop=10, exp_drop=10, item_drop="Flesh")
92-
mercenary = Mob(name="Mercenary", max_health=100, melee_attack=10, magic_attack=0, max_mana=0, max_stamina=20,
93-
defense=15, luck=5, mob_class="Human", gold_drop=10, exp_drop=10, item_drop="Flesh")
94-
skeleton = Mob(name="Skeleton", max_health=100, melee_attack=10, magic_attack=0, max_mana=0, max_stamina=20,
95-
defense=15, luck=5, mob_class="Undead", gold_drop=10, exp_drop=10, item_drop="Flesh")
96-
golem = Mob(name="Golem", max_health=100, melee_attack=10, magic_attack=0, max_mana=0, max_stamina=20,
97-
defense=15, luck=5, mob_class="Elemental", gold_drop=10, exp_drop=10, item_drop="Flesh")
98-
witch = Mob(name="Witch", max_health=100, melee_attack=10, magic_attack=0, max_mana=0, max_stamina=20,
99-
defense=15, luck=5, mob_class="Human", gold_drop=10, exp_drop=10, item_drop="Flesh")
100-
hellHounds = Mob(name="Hell Hounds", max_health=100, melee_attack=10, magic_attack=0, max_mana=0, max_stamina=20,
101-
defense=15, luck=5, mob_class="Undead", gold_drop=10, exp_drop=10, item_drop="Flesh")
102-
103-
# animal mobs
104-
dog = Mob(name="Dog", max_health=100, melee_attack=10, magic_attack=0, max_mana=0, max_stamina=20,
105-
defense=15, luck=5, mob_class="Animal", gold_drop=10, exp_drop=10, item_drop="Flesh")
106-
107-
# bosses
108-
wyrm = Mob(name="Wyrm", max_health=100, melee_attack=10, magic_attack=0, max_mana=0, max_stamina=20,
109-
defense=15, luck=5, mob_class="Dragon", gold_drop=10, exp_drop=10, item_drop="Dragon Scale",
110-
special_item_drop="Special Drop")
111-
kraken = Mob(name="Kraken", max_health=100, melee_attack=10, magic_attack=0, max_mana=0, max_stamina=20,
112-
defense=15, luck=5, mob_class="Dragon", gold_drop=10, exp_drop=10, item_drop="Dragon Scale",
113-
special_item_drop="Special Drop")
114-
115-
hostile_mobs = {"Zombie": zombie, "Yeti": yeti, "Bandit": bandit, "Mercenary": mercenary, "Skeleton": skeleton,
116-
"Golem": golem, "Witch": witch,
117-
"Hell Hounds": hellHounds}
118-
119-
friendly_mobs = {"Dog": dog}
120-
121-
bosses = {"Wyrm": wyrm, "Kraken": kraken}
122-
"""

script/Items.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ def __init__(self, name, rarity, value):
44
self.name = name
55
self.rarity = rarity
66
self.value = value
7+
def __str__(self):
8+
return f'{self.rarity} {self.name}'
9+
# Give user friendly description of item
10+
# TODO each item subclass should override this desc method
11+
def desc(self):
12+
return f'{self.rarity} {self.name}, value {self.value}'
713

814

915
class Resources(Item):

script/Screen.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,6 @@ def main_game_screen(story):
125125
for i in lines:
126126
print(i)
127127

128-
"""
129-
130-
131-
132-
133-
134-
135-
"""
136128
def display(on_screen, width=44):
137129
# width = 44 max width is 208
138130
side = round(((width / 2) / 2) - 1)

0 commit comments

Comments
 (0)