summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-06-05 09:15:37 -0600
committermo khan <mo@mokhan.ca>2025-06-05 09:15:37 -0600
commit7b5cfb4388cf8ab3d0111a2498dd040812fc3fbd (patch)
tree2c450e370aea2bb27129835dedd48f82a72b8e1d
parent974c5037f5cb03d8cccc4c8a035bfdd88ed17087 (diff)
add game objects
-rw-r--r--adventure/AdventureGame.py45
1 files changed, 18 insertions, 27 deletions
diff --git a/adventure/AdventureGame.py b/adventure/AdventureGame.py
index 4d5c7f9..19a3ce4 100644
--- a/adventure/AdventureGame.py
+++ b/adventure/AdventureGame.py
@@ -27,34 +27,34 @@ refresh_objects_visible = True
current_location = FIRST_LOCATION
end_of_game = False
-generic_object = GameObject.GameObject("object", FIRST_LOCATION, True, True, False, "description")
+sword = GameObject.GameObject("sword", FIRST_LOCATION, True, True, True, "Sword")
+shield = GameObject.GameObject("shield", FIRST_LOCATION, True, True, False, "Shield")
+bow = GameObject.GameObject("bow", FIRST_LOCATION, True, False, False, "The Magic Bow")
-game_objects = [generic_object]
+game_objects = [sword, shield, bow]
def perform_command(verb, noun):
-
if (verb == "GO"):
perform_go_command(noun)
elif ((verb == "N") or (verb == "S") or (verb == "E") or (verb == "W")):
- perform_go_command(verb)
+ perform_go_command(verb)
elif ((verb == "NORTH") or (verb == "SOUTH") or (verb == "EAST") or (verb == "WEST")):
- perform_go_command(verb)
+ perform_go_command(verb)
elif (verb == "GET"):
perform_get_command(noun)
elif (verb == "PUT"):
perform_put_command(noun)
elif (verb == "LOOK"):
- perform_look_command(noun)
+ perform_look_command(noun)
elif (verb == "X"):
- perform_x_command(noun)
+ perform_x_command(noun)
else:
- print_to_description("huh?")
-
-def perform_go_command(direction):
+ print_to_description("huh?")
+def perform_go_command(direction):
global current_location
global refresh_location
-
+
if (direction == "N" or direction == "NORTH"):
new_location = get_location_to_north()
elif (direction == "S" or direction == "SOUTH"):
@@ -65,7 +65,7 @@ def perform_go_command(direction):
new_location = get_location_to_west()
else:
new_location = 0
-
+
if (new_location == 0):
print_to_description("You can't go that way!")
else:
@@ -73,10 +73,9 @@ def perform_go_command(direction):
refresh_location = True
def perform_get_command(object_name):
-
global refresh_objects_visible
game_object = get_game_object(object_name)
-
+
if not (game_object is None):
if (game_object.location != current_location or game_object.visible == False):
print_to_description("You don't see one of those here!")
@@ -96,12 +95,10 @@ def perform_get_command(object_name):
else:
print_to_description("You don't see one of those here!")
-#
def perform_put_command(object_name):
-
global refresh_objects_visible
game_object = get_game_object(object_name)
-
+
if not (game_object is None):
if (game_object.carried == False):
print_to_description("You are not carrying one of those.")
@@ -113,20 +110,19 @@ def perform_put_command(object_name):
refresh_objects_visible = True
else:
print_to_description("You are not carrying one of those!")
-#
-def perform_look_command(object_name):
+def perform_look_command(object_name):
global sword_found
global refresh_location
global refresh_objects_visible
-
+
game_object = get_game_object(object_name)
-
- if not (game_object is None):
+ if not (game_object is None):
if ((game_object.carried == True) or (game_object.visible and game_object.location == current_location)):
print_to_description(game_object.description)
else:
+ game_object.visible = true
#recognized but not visible
print_to_description("You can't see one of those!")
@@ -173,23 +169,19 @@ def describe_current_location():
def set_current_image():
if (current_location == FIRST_LOCATION):
- #display a jpg using PIL library
image_label.img = ImageTk.PhotoImage(Image.open ('res/blank-1.gif'))
elif (current_location == SECOND_LOCATION):
- #display image using standard image library (can only be .gif)
image_label.img = PhotoImage(file = 'res/blank-2.gif')
elif (current_location == THIRD_LOCATION):
image_label.img = PhotoImage(file = 'res/blank-3.gif')
elif (current_location == FOURTH_LOCATION):
image_label.img = PhotoImage(file = 'res/blank-4.gif')
else:
- #for safety, display an image... code should never reach here
image_label.img = PhotoImage(file = 'res/blank-4.gif')
image_label.config(image = image_label.img)
def get_location_to_north():
-
if (current_location == THIRD_LOCATION):
return FIRST_LOCATION
elif (current_location == FOURTH_LOCATION):
@@ -280,7 +272,6 @@ def print_to_description(output, user_input=False):
description_widget.see(END)
def build_interface():
-
global command_widget
global image_label
global description_widget