11import random
22
3- from game .player import (
4- add_item_to_inventory ,
5- damage_player ,
6- heal_player ,
7- move_player ,
8- remove_item_from_inventory ,
9- )
10- from game .world import change_location , get_all_locations , get_available_locations
3+ from game .player import (add_item_to_inventory , damage_player , heal_player ,
4+ move_player , remove_item_from_inventory )
5+ from game .world import (change_location , get_all_locations ,
6+ get_available_locations )
117from utils .random_events import generate_random_event
128
139
@@ -30,10 +26,11 @@ def get_item_description(item):
3026 "ancient_artifact" : "A mysterious object from a long-lost civilization. Its purpose is unknown." ,
3127 "magic_ring" : "A ring imbued with magical properties. Its effects are yet to be discovered." ,
3228 "mysterious_potion" : "A vial containing a strange, swirling liquid. Its effects are unknown." ,
33- "sword" : "A well-crafted sword with a sharp blade. Useful for combat and self-defense."
29+ "sword" : "A well-crafted sword with a sharp blade. Useful for combat and self-defense." ,
3430 }
3531 return item_descriptions .get (item , "A mysterious item." )
3632
33+
3734def use_item (player , item , world ):
3835 if item not in player ["inventory" ]:
3936 print (f"You don't have { item } in your inventory." )
@@ -70,17 +67,21 @@ def use_item(player, item, world):
7067 current_location = world ["current_location" ]
7168 if current_location == "Cave" :
7269 print ("You light the torch, illuminating the dark cave around you." )
73- world ["locations" ]["Cave" ]["description" ] += " The cave is now well-lit by your torch."
70+ world ["locations" ]["Cave" ][
71+ "description"
72+ ] += " The cave is now well-lit by your torch."
7473 return True
7574 else :
7675 print ("You light the torch. It provides warmth and light." )
7776 return True
7877 elif item == "gemstone" :
79- print ("You examine the gemstone closely. It glimmers with an otherworldly light." )
78+ print (
79+ "You examine the gemstone closely. It glimmers with an otherworldly light."
80+ )
8081 if world ["current_location" ] == "Village" :
8182 print ("A merchant notices your gemstone and offers to buy it for 50 gold!" )
8283 choice = input ("Do you want to sell the gemstone? (y/n): " ).lower ()
83- if choice == 'y' :
84+ if choice == "y" :
8485 player ["gold" ] += 50
8586 remove_item_from_inventory (player , item )
8687 print ("You sold the gemstone for 50 gold." )
@@ -89,11 +90,15 @@ def use_item(player, item, world):
8990 return True
9091 elif item == "rope" :
9192 if world ["current_location" ] == "Mountain" :
92- print ("You use the rope to safely navigate a treacherous part of the mountain." )
93+ print (
94+ "You use the rope to safely navigate a treacherous part of the mountain."
95+ )
9396 heal_player (player , 5 )
9497 print ("Your climbing technique improves, and you feel more confident." )
9598 else :
96- print ("You coil and uncoil the rope. It might be useful in the right situation." )
99+ print (
100+ "You coil and uncoil the rope. It might be useful in the right situation."
101+ )
97102 return True
98103 elif item == "pickaxe" :
99104 print ("You swing the pickaxe, but there's nothing here to mine." )
@@ -115,35 +120,50 @@ def use_item(player, item, world):
115120 remove_item_from_inventory (player , item )
116121 return True
117122 elif item == "ancient_coin" :
118- print ("You flip the ancient coin. As it spins in the air, you feel a strange energy..." )
119- if generate_random_event (events = [("teleport" , 50 ), ("reveal_secret" , 50 )]) == "teleport" :
123+ print (
124+ "You flip the ancient coin. As it spins in the air, you feel a strange energy..."
125+ )
126+ if (
127+ generate_random_event (events = [("teleport" , 50 ), ("reveal_secret" , 50 )])
128+ == "teleport"
129+ ):
120130 new_location = random .choice (get_all_locations (world ))
121131 change_location (world , new_location )
122132 move_player (player , new_location )
123- print (f"The coin vanishes and you find yourself teleported to { new_location } !" )
133+ print (
134+ f"The coin vanishes and you find yourself teleported to { new_location } !"
135+ )
124136 else :
125137 print ("The coin glows and reveals a secret about your current location!" )
126138 # You might want to add some location-specific secrets here
127139 remove_item_from_inventory (player , item )
128140 return True
129141 elif item == "hermit's_blessing" :
130- print ("You invoke the hermit's blessing. A warm, comforting light envelops you." )
142+ print (
143+ "You invoke the hermit's blessing. A warm, comforting light envelops you."
144+ )
131145 heal_player (player , 50 )
132146 print ("You feel completely refreshed and your mind is clear." )
133147 remove_item_from_inventory (player , item )
134148 return True
135149 elif item == "sword" :
136150 print ("You swing the sword, practicing your combat moves." )
137151 if world ["current_location" ] == "Forest" :
138- print ("Your sword slices through some thick vines, revealing a hidden path!" )
152+ print (
153+ "Your sword slices through some thick vines, revealing a hidden path!"
154+ )
139155 # update_world_state(world, "reveal_hidden_path")
140156 return True
141157 elif item == "gold_coin" :
142158 print ("You flip the gold coin. It catches the light, shimmering brilliantly." )
143159 if world ["current_location" ] == "Village" :
144- print ("A street vendor notices your coin and offers you a mysterious potion in exchange." )
145- choice = input ("Do you want to trade the gold coin for the potion? (y/n): " ).lower ()
146- if choice == 'y' :
160+ print (
161+ "A street vendor notices your coin and offers you a mysterious potion in exchange."
162+ )
163+ choice = input (
164+ "Do you want to trade the gold coin for the potion? (y/n): "
165+ ).lower ()
166+ if choice == "y" :
147167 remove_item_from_inventory (player , item )
148168 add_item_to_inventory (player , "mysterious_potion" )
149169 print ("You traded the gold coin for a mysterious potion." )
@@ -153,19 +173,29 @@ def use_item(player, item, world):
153173 elif item == "silver_necklace" :
154174 print ("You hold up the silver necklace, admiring its craftsmanship." )
155175 if world ["current_location" ] == "Mountain" :
156- print ("The necklace begins to glow, revealing hidden runes on nearby rocks!" )
176+ print (
177+ "The necklace begins to glow, revealing hidden runes on nearby rocks!"
178+ )
157179 print ("You discover a secret path leading to a hidden cave." )
158180 # update_world_state(world, "reveal_hidden_cave")
159181 else :
160182 print ("The necklace sparkles beautifully, but nothing else happens." )
161183 return True
162184 elif item == "ancient_artifact" :
163- print ("You examine the ancient artifact closely, turning it over in your hands." )
164- if generate_random_event (events = [("wisdom" , 40 ), ("curse" , 30 ), (None , 30 )]) == "wisdom" :
185+ print (
186+ "You examine the ancient artifact closely, turning it over in your hands."
187+ )
188+ if (
189+ generate_random_event (events = [("wisdom" , 40 ), ("curse" , 30 ), (None , 30 )])
190+ == "wisdom"
191+ ):
165192 print ("Suddenly, knowledge of the ancient world floods your mind!" )
166193 print ("You gain insight into the history of this land." )
167194 # update_player_knowledge(player, "ancient_history")
168- elif generate_random_event (events = [("wisdom" , 40 ), ("curse" , 30 ), (None , 30 )]) == "curse" :
195+ elif (
196+ generate_random_event (events = [("wisdom" , 40 ), ("curse" , 30 ), (None , 30 )])
197+ == "curse"
198+ ):
169199 print ("A dark energy emanates from the artifact, making you feel weak." )
170200 damage_player (player , 10 )
171201 print ("You quickly put the artifact away, feeling drained." )
@@ -176,22 +206,26 @@ def use_item(player, item, world):
176206 print (f"You're not sure how to use the { item } ." )
177207 return False
178208
209+
179210def get_available_items (world , location ):
180211 return world ["locations" ][location ]["items" ]
181212
213+
182214def add_item_to_world (world , location , item ):
183215 if item not in world ["locations" ][location ]["items" ]:
184216 world ["locations" ][location ]["items" ].append (item )
185217 print (f"A { item } has been added to { location } ." )
186218 else :
187219 print (f"There's already a { item } in { location } ." )
188220
221+
189222def remove_item_from_world (world , location , item ):
190223 if item in world ["locations" ][location ]["items" ]:
191224 world ["locations" ][location ]["items" ].remove (item )
192225 return True
193226 return False
194227
228+
195229def transfer_item (player , world , item , from_inventory_to_world = True ):
196230 current_location = world ["current_location" ]
197231
0 commit comments