summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-06-25 17:43:10 -0600
committermo khan <mo@mokhan.ca>2025-06-25 17:43:10 -0600
commit09174e0be63bc35779722be970ebe933df8d527f (patch)
tree6e9b117533aa2ca67c618999f40853371b71fb78
parent291d5071fea479e4d04d5a51d4fdefc9b56eb30a (diff)
feat: Add discovered rooms tracking to exploration map
- Rooms now appear as [???] when discovered but not visited - Discover rooms when blocked by locks, guards, or other obstacles - Map shows: β˜… current location, βœ“ visited rooms, ? discovered rooms - Enhanced map legend with visit/discovery statistics - True exploration feeling - map builds as you discover new areas Example: Try to enter a locked door β†’ room appears as [???] on map πŸ€– Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
-rw-r--r--AdventureGame.py173
1 files changed, 102 insertions, 71 deletions
diff --git a/AdventureGame.py b/AdventureGame.py
index cea82b6..b89d6b0 100644
--- a/AdventureGame.py
+++ b/AdventureGame.py
@@ -77,6 +77,7 @@ player_gold = 0
# Track visited rooms for map display
visited_rooms = {ROOM_021} # Start with room 021 as visited
+discovered_rooms = set() # Rooms we know exist but haven't entered (locked doors, etc.)
# Create all game objects based on README specifications
tripwire = GameObject.GameObject("tripwire", ROOM_001, False, True, False, "A dangerous tripwire blocks your path")
@@ -169,32 +170,37 @@ def perform_go_command(direction):
def check_movement_restrictions(from_room, to_room):
"""Check if movement is blocked by locks, guards, etc."""
- global player_gold
+ global player_gold, discovered_rooms
# Room 007 requires pink key
if to_room == ROOM_007 and not has_item_carried("PINK KEY"):
print_to_description("🌸 A pink lock blocks this door. You need a pink key!")
+ discovered_rooms.add(to_room) # You discovered this room exists
return True
# Room 008 requires green key
if to_room == ROOM_008 and not has_item_carried("GREEN KEY"):
print_to_description("πŸ’š A green lock seals this passage. You need a green key!")
+ discovered_rooms.add(to_room) # You discovered this room exists
return True
# Room 014 requires yellow key
if to_room == ROOM_014 and not has_item_carried("YELLOW KEY"):
print_to_description("πŸ’› A yellow lock prevents entry. You need a yellow key!")
+ discovered_rooms.add(to_room) # You discovered this room exists
return True
# Room 022 requires blue key
if to_room == ROOM_022 and not has_item_carried("BLUE KEY"):
print_to_description("πŸ’™ A blue lock blocks this final door. You need a blue key!")
+ discovered_rooms.add(to_room) # You discovered this room exists
return True
# Room 005 requires payment to guard in room 004
if to_room == ROOM_005 and from_room == ROOM_004:
if get_game_object("guard").visible: # Guard still there
print_to_description("βš”οΈ The guard blocks your path! You must pay him gold to pass!")
+ discovered_rooms.add(to_room) # You discovered this room exists
return True
return False
@@ -660,84 +666,109 @@ def print_to_description(output, user_input=False):
description_widget.see(END)
def create_map_display():
- """Create ASCII map showing visited rooms and current location"""
- # Map layout template with placeholders
- map_template = [
- " {001}<->{002}<->{003}<->{004}<->{005}",
- " A ",
- " | ",
- " V ",
- " {006}<->{007}<->{008} ",
- " A ",
- " | ",
- " V ",
- " {009} {010}<->{011} ",
- " A A ",
- " | | ",
- " V V ",
- " {012}<->{013}<->{014} {015}<->{016} ",
- " A A ",
- " | | ",
- " V V ",
- " {017}<->{018}<->{019} ",
- " A A ",
- " | | ",
- " V V ",
- " {020} {021}<->{022} "
- ]
-
- # Build the map by replacing placeholders
- map_text = "\n".join(map_template)
+ """Create ASCII map showing ONLY visited rooms and current location"""
+
+ # Define room positions in the map grid (row, col)
+ room_positions = {
+ 1: (0, 2), 2: (0, 8), 3: (0, 14), 4: (0, 20), 5: (0, 26),
+ 6: (4, 10), 7: (4, 16), 8: (4, 22),
+ 9: (8, 2), 10: (8, 20), 11: (8, 26),
+ 12: (12, 2), 13: (12, 8), 14: (12, 14), 15: (12, 20), 16: (12, 26),
+ 17: (16, 10), 18: (16, 16), 19: (16, 22),
+ 20: (20, 10), 21: (20, 16), 22: (20, 22)
+ }
- # Replace each room placeholder with appropriate display
- for room_num in range(1, 23):
- placeholder = "{" + f"{room_num:03d}" + "}"
-
- if room_num == current_location:
- # Current location - bright highlight with room number
- replacement = f"[β˜…{room_num:02d}]"
- elif room_num in visited_rooms:
- # Visited room - show room number with checkmark
- replacement = f"[βœ“{room_num:02d}]"
- else:
- # Unvisited room - completely hidden
- replacement = "[???]"
-
- map_text = map_text.replace(placeholder, replacement)
-
- # Hide connections to unvisited rooms by replacing arrows with spaces
- lines = map_text.split('\n')
- clean_lines = []
-
- for line in lines:
- # If a line contains ??? rooms, hide the connections to them
- if "[???]" in line:
- # Replace arrows pointing to/from unknown rooms with spaces
- cleaned_line = line
- # Hide horizontal connections
- import re
- # Replace <-> between known and unknown rooms
- cleaned_line = re.sub(r'(\[[\β˜…βœ“]\d{2}\])<->(\[[\?]{3}\])', r'\1 \2', cleaned_line)
- cleaned_line = re.sub(r'(\[[\?]{3}\])<->(\[[\β˜…βœ“]\d{2}\])', r'\1 \2', cleaned_line)
- cleaned_line = re.sub(r'(\[[\?]{3}\])<->(\[[\?]{3}\])', r'\1 \2', cleaned_line)
- clean_lines.append(cleaned_line)
- else:
- clean_lines.append(line)
+ # Define connections between rooms (room1, room2, connection_type, positions)
+ connections = [
+ # Top row
+ (1, 2, 'horizontal', [(0, 3), (0, 4), (0, 5), (0, 6), (0, 7)]),
+ (2, 3, 'horizontal', [(0, 9), (0, 10), (0, 11), (0, 12), (0, 13)]),
+ (3, 4, 'horizontal', [(0, 15), (0, 16), (0, 17), (0, 18), (0, 19)]),
+ (4, 5, 'horizontal', [(0, 21), (0, 22), (0, 23), (0, 24), (0, 25)]),
+ # Vertical connections
+ (2, 6, 'vertical', [(1, 8), (2, 8), (3, 8)]),
+ (6, 7, 'horizontal', [(4, 11), (4, 12), (4, 13), (4, 14), (4, 15)]),
+ (7, 8, 'horizontal', [(4, 17), (4, 18), (4, 19), (4, 20), (4, 21)]),
+ (8, 11, 'vertical', [(5, 22), (6, 22), (7, 22)]),
+ (9, 12, 'vertical', [(9, 2), (10, 2), (11, 2)]),
+ (10, 11, 'horizontal', [(8, 21), (8, 22), (8, 23), (8, 24), (8, 25)]),
+ (11, 15, 'vertical', [(9, 26), (10, 26), (11, 26)]),
+ (12, 13, 'horizontal', [(12, 3), (12, 4), (12, 5), (12, 6), (12, 7)]),
+ (13, 14, 'horizontal', [(12, 9), (12, 10), (12, 11), (12, 12), (12, 13)]),
+ (15, 16, 'horizontal', [(12, 21), (12, 22), (12, 23), (12, 24), (12, 25)]),
+ (13, 17, 'vertical', [(13, 8), (14, 8), (15, 8)]),
+ (15, 19, 'vertical', [(13, 22), (14, 22), (15, 22)]),
+ (17, 18, 'horizontal', [(16, 11), (16, 12), (16, 13), (16, 14), (16, 15)]),
+ (18, 19, 'horizontal', [(16, 17), (16, 18), (16, 19), (16, 20), (16, 21)]),
+ (17, 20, 'vertical', [(17, 10), (18, 10), (19, 10)]),
+ (18, 21, 'vertical', [(17, 16), (18, 16), (19, 16)]),
+ (21, 22, 'horizontal', [(20, 17), (20, 18), (20, 19), (20, 20), (20, 21)])
+ ]
- map_text = "\n".join(clean_lines)
+ # Create empty grid (25 rows x 30 columns should be enough)
+ grid = [[' ' for _ in range(30)] for _ in range(25)]
+
+ # Place visited and discovered rooms on the grid
+ all_known_rooms = visited_rooms.union(discovered_rooms)
+ for room_num in all_known_rooms:
+ if room_num in room_positions:
+ row, col = room_positions[room_num]
+ if room_num == current_location:
+ room_display = f"[β˜…{room_num:02d}]"
+ elif room_num in visited_rooms:
+ room_display = f"[βœ“{room_num:02d}]"
+ else: # room in discovered_rooms but not visited
+ room_display = "[???]"
+
+ # Place room on grid
+ for i, char in enumerate(room_display):
+ if col + i < len(grid[row]):
+ grid[row][col + i] = char
+
+ # Draw connections between known rooms (visited or discovered)
+ for room1, room2, conn_type, positions in connections:
+ if room1 in all_known_rooms and room2 in all_known_rooms:
+ for row, col in positions:
+ if row < len(grid) and col < len(grid[row]):
+ if conn_type == 'horizontal':
+ grid[row][col] = '-'
+ else: # vertical connections
+ if positions.index((row, col)) == 0:
+ grid[row][col] = 'A' if positions[0][0] < positions[-1][0] else 'V'
+ elif positions.index((row, col)) == len(positions) - 1:
+ grid[row][col] = 'V' if positions[0][0] < positions[-1][0] else 'A'
+ else:
+ grid[row][col] = '|'
+
+ # Convert grid to string, removing empty trailing rows
+ map_lines = []
+ for row in grid:
+ line = ''.join(row).rstrip()
+ if line or map_lines: # Keep empty lines if they're between content
+ map_lines.append(line)
+
+ # Remove trailing empty lines
+ while map_lines and not map_lines[-1].strip():
+ map_lines.pop()
+
+ map_text = '\n'.join(map_lines)
# Count visited rooms for stats
visited_count = len(visited_rooms)
total_rooms = 22
- return f"""πŸ—ΊοΈ ADVENTURE MAP πŸ—ΊοΈ
-{'='*40}
-β˜… = You Are Here βœ“ = Visited
-? = Unknown Territory
-Explored: {visited_count}/{total_rooms} rooms
-{'='*40}
+ # Count discovered rooms for stats
+ discovered_count = len(discovered_rooms)
+
+ return f"""πŸ—ΊοΈ EXPLORATION MAP πŸ—ΊοΈ
+{'='*35}
+β˜… = You Are Here βœ“ = Visited ? = Discovered
+Map reveals as you explore!
+Visited: {visited_count} Discovered: {discovered_count} Total: {total_rooms}
+{'='*35}
-{map_text}"""
+{map_text}
+"""
def update_map_display():
"""Update the map widget with current exploration status"""