From 20139ddfafbadcb1cba34dd8025473fb3e8eaa81 Mon Sep 17 00:00:00 2001 From: johannapfeil Date: Fri, 25 Oct 2024 16:50:54 +0200 Subject: [PATCH] =?UTF-8?q?Created=20using=20Colab=20|=20Group=201:=20Frie?= =?UTF-8?q?derike,=20Aur=C3=A9lie,=20Cecilia,=20Johanna,=20Filip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PyBreakEscape.ipynb | 426 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 426 insertions(+) create mode 100644 PyBreakEscape.ipynb diff --git a/PyBreakEscape.ipynb b/PyBreakEscape.ipynb new file mode 100644 index 00000000..ca7b787d --- /dev/null +++ b/PyBreakEscape.ipynb @@ -0,0 +1,426 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "0Ypgsd5BkhM-", + "outputId": "38a8ff84-b989-40be-b20e-0c90ac49c06f" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Suddenly, you find yourself waking up on an unfamiliar couch, in an eerie house devoid of windows. Your memory fails to provide any explanation about how you ended up here, or what transpired previously. You can sense an imminent threat lurking somewhere - your gut tells you to escape the house immediately!\n", + "You look around and realize you re in a game room.\n", + "“What should I do?” you ponder.\n", + "You are now in the game room. The couch appears mundane and unexciting.\n", + "What would you like to do? Type 1 for 'explore' or 2 for 'examine'?: 1\n", + "You explore the room. This is game room. You find couch, piano, door a\n", + "You are back in game room.\n", + "What would you like to do? Type 1 for 'explore' or 2 for 'examine'?: piano\n", + "Not sure what you mean. Type 'explore' or 'examine': \n", + "What would you like to do? Type 1 for 'explore' or 2 for 'examine'?: 2\n", + "What would you like to examine?: piano\n", + "You examine piano. You find key for door a.\n", + "You are back in game room.\n", + "What would you like to do? Type 1 for 'explore' or 2 for 'examine'?: 2\n", + "What would you like to examine?: door a\n", + "You examine door a. You unlock it with a key you have.\n", + "Will you step into the unknown through Door A?\n", + "Do you want to go to the next room? Enter Y for 'yes' or N for 'no': y\n", + "You are now in bedroom 1. Again, you find yourself contemplating - to explore or examine? Is it time to venture through door b?\n", + "What would you like to do? Type 1 for 'explore' or 2 for 'examine'?: 2\n" + ] + } + ], + "source": [ + "# define rooms and items\n", + "\n", + "#objects\n", + "piano = {\n", + " \"name\": \"piano\",\n", + " \"type\": \"furniture\"\n", + "}\n", + "\n", + "couch = {\n", + " \"name\": \"couch\",\n", + " \"type\": \"furniture\"\n", + "}\n", + "\n", + "double_bed = {\n", + " \"name\" : \"double bed\",\n", + " \"type\" : \"furniture\"\n", + "}\n", + "\n", + "dresser = {\n", + " \"name\" : \"dresser\",\n", + " \"type\" : \"furniture\"\n", + "}\n", + "\n", + "queen_bed = {\n", + " \"name\" : \"queen bed\",\n", + " \"type\" : \"furniture\"\n", + "}\n", + "\n", + "dining_table = {\n", + " \"name\" : \"dining table\",\n", + " \"type\" : \"furniture\"\n", + "}\n", + "\n", + "#messages\n", + "letter_a = {\n", + " \"name\": \"continue if you dare\",\n", + " \"type\": \"message\"\n", + "}\n", + "\n", + "letter_b = {\n", + " \"name\": \"time is running...\",\n", + " \"type\": \"message\"\n", + "}\n", + "\n", + "#doors\n", + "door_a = {\n", + " \"name\": \"door a\",\n", + " \"type\": \"door\"\n", + "}\n", + "\n", + "door_b = {\n", + " \"name\": \"door b\",\n", + " \"type\": \"door\"\n", + "}\n", + "\n", + "door_c = {\n", + " \"name\": \"door c\",\n", + " \"type\": \"door\"\n", + "}\n", + "\n", + "door_d = {\n", + " \"name\": \"door d\",\n", + " \"type\": \"door\"\n", + "}\n", + "\n", + "#keys\n", + "key_a = {\n", + " \"name\": \"key for door a\",\n", + " \"type\": \"key\",\n", + " \"target\": door_a\n", + "}\n", + "\n", + "key_b = {\n", + " \"name\": \"key for door b\",\n", + " \"type\": \"key\",\n", + " \"target\": door_b\n", + "}\n", + "\n", + "key_c = {\n", + " \"name\": \"key for door c\",\n", + " \"type\": \"key\",\n", + " \"target\": door_c\n", + "}\n", + "\n", + "key_d = {\n", + " \"name\": \"key for door d\",\n", + " \"type\": \"key\",\n", + " \"target\": door_d\n", + "}\n", + "\n", + "#rooms\n", + "game_room = {\n", + " \"name\": \"game room\",\n", + " \"type\": \"room\"\n", + "}\n", + "\n", + "bedroom_1 = {\n", + " \"name\" : \"bedroom 1\",\n", + " \"type\" : \"room\"\n", + "}\n", + "\n", + "bedroom_2 = {\n", + " \"name\" : \"bedroom 2\",\n", + " \"type\" : \"room\"\n", + "}\n", + "\n", + "living_room = {\n", + " \"name\" : \"living room\",\n", + " \"type\" : \"room\"\n", + "}\n", + "\n", + "#end\n", + "outside = {\n", + " \"name\": \"outside\"\n", + "}\n", + "\n", + "# Allrooms\n", + "all_rooms = [game_room, bedroom_1, bedroom_2, living_room, outside]\n", + "# All doors\n", + "all_doors = [door_a, door_b, door_c, door_d]\n", + "\n", + "# define which items/rooms are related\n", + "object_relations = {\n", + " \"game room\": [couch, piano, door_a],\n", + " \"bedroom 1\" : [door_a, queen_bed, door_b, door_c],\n", + " \"bedroom 2\" : [door_b, double_bed, dresser],\n", + " \"living room\" : [dining_table, door_c, door_d],\n", + " \"couch\": [letter_a],\n", + " \"piano\" : [key_a],\n", + " \"double bed\" : [key_c],\n", + " \"dresser\" : [key_d],\n", + " \"queen bed\" : [key_b],\n", + " \"dining table\": [letter_b],\n", + " \"outside\": [door_d],\n", + " \"door a\": [game_room, bedroom_1],\n", + " \"door b\" : [bedroom_1,bedroom_2],\n", + " \"door c\" : [bedroom_1, living_room],\n", + " \"door d\" : [living_room, outside]\n", + "}\n", + "\n", + "# define game state. Do not directly change this dict.\n", + "# Instead, when a new game starts, make a copy of this\n", + "# dict and use the copy to store gameplay state. This\n", + "# way you can replay the game multiple times.\n", + "\n", + "INIT_GAME_STATE = {\n", + " \"current_room\": game_room,\n", + " \"keys_collected\": [],\n", + " \"target_room\": outside\n", + "}\n", + "#if we follow the instruction start : game room then, bedroom 1 then bedroom 2 back to bedroom 1 then living room and final outside\n", + "\n", + "\n", + "\n", + "#2nd part\n", + "def linebreak():\n", + "\n", + " print(\"\\n\\n\")\n", + "\n", + "def start_game(visited_rooms):\n", + " \"\"\"\n", + " Start the game\n", + " \"\"\"\n", + " print(\"Suddenly, you find yourself waking up on an unfamiliar couch, in an eerie house devoid of windows. Your memory fails to provide any explanation about how you ended up here, or what transpired previously. You can sense an imminent threat lurking somewhere - your gut tells you to escape the house immediately!\\nYou look around and realize you re in a game room.\\n“What should I do?” you ponder.\")\n", + " play_room(game_state[\"current_room\"], visited_rooms) # Add visited_rooms here\n", + "\n", + "\n", + "def play_room(room, visited_rooms):\n", + " \"\"\"Play a room. First check if the room being played is the target room.\n", + " If it is, the game will end with success. Otherwise, let player either\n", + " explore (list all items in this room) or examine an item found here.\n", + " \"\"\"\n", + " game_state[\"current_room\"] = room\n", + " if game_state[\"current_room\"] == game_state[\"target_room\"]:\n", + " print(\"Congrats! You escaped the room!\")\n", + " else:\n", + " visited_rooms = enter_room(room, visited_rooms)\n", + " while True: # Keep asking until valid input\n", + " intended_action = input(\"What would you like to do? Type 1 for 'explore' or 2 for 'examine'?: \").strip()\n", + " if intended_action == \"1\":\n", + " explore_room(room)\n", + " break # Exit the loop after exploring\n", + " elif intended_action == \"2\":\n", + " examine_item(input(\"What would you like to examine?: \").strip().lower(), visited_rooms)\n", + " break # Exit the loop after examining\n", + " else:\n", + " print(\"Not sure what you mean. Type 'explore' or 'examine': \")\n", + " play_room(game_state[\"current_room\"], visited_rooms) # Continue with the next room\n", + " linebreak()\n", + "\n", + "\n", + "#Johanna addition\n", + "def enter_room(room, visited_rooms):\n", + " if room[\"name\"] not in visited_rooms:\n", + "\n", + " if room == game_room:\n", + " print('You are now in the game room. The couch appears mundane and unexciting.')\n", + "\n", + " elif room == bedroom_1:\n", + " print('You are now in bedroom 1. Again, you find yourself contemplating - to explore or examine? Is it time to venture through door b?')\n", + "\n", + " elif room == bedroom_2:\n", + " print('You are now in bedroom 2. “What now?” you think. Shall you retrace your steps through door b?')\n", + "\n", + " elif room == living_room:\n", + " print('You are now in the living room. “What secrets does this room hold?” you muse. Is it time to step through Door D and see what lies beyond?''')\n", + "\n", + " visited_rooms.add(room[\"name\"])\n", + "\n", + " else:\n", + " print(f'You are back in {room[\"name\"]}.')\n", + "\n", + " return visited_rooms\n", + "\n", + "\n", + "\n", + "\n", + "def explore_room(room):\n", + " \"\"\"\n", + " Explore a room. List all items belonging to this room.\n", + "\n", + " TO DO\n", + "\n", + " \"\"\"\n", + " items = [i[\"name\"] for i in object_relations[room[\"name\"]]]\n", + " print(\"You explore the room. This is \" + room[\"name\"] + \". You find \" + \", \".join(items))\n", + "\n", + "def get_next_room_of_door(door, current_room):\n", + " \"\"\"\n", + " From object_relations, find the two rooms connected to the given door.\n", + " Return the room that is not the current_room.\n", + " \"\"\"\n", + " connected_rooms = object_relations[door[\"name\"]]\n", + " for room in connected_rooms:\n", + " if(not current_room == room):\n", + " return room\n", + "\n", + "\n", + "def examine_item(item_name, visited_rooms):\n", + " \"\"\"Examine an item which can be a door or furniture.\n", + " First make sure the intended item belongs to the current room.\n", + " Then check if the item is a door. Tell player if key hasn't been\n", + " collected yet. Otherwise ask player if they want to go to the next\n", + " room. If the item is not a door, then check if it contains keys.\n", + " Collect the key if found and update the game state. At the end,\n", + " play either the current or the next room depending on the game state\n", + " to keep playing.\n", + " \"\"\"\n", + " current_room = game_state[\"current_room\"]\n", + " next_room = \"\"\n", + " output = None\n", + " for item in object_relations[current_room[\"name\"]]:\n", + " if item[\"name\"] == item_name:\n", + " output = \"You examine \" + item_name + \". \"\n", + " if item[\"type\"] == \"door\":\n", + " have_key = False\n", + " for key in game_state[\"keys_collected\"]:\n", + " if key[\"target\"] == item:\n", + " have_key = True\n", + " if have_key:\n", + " output += \"You unlock it with a key you have.\"\n", + " next_room = get_next_room_of_door(item, current_room)\n", + " else:\n", + " output += \"It is locked but you don't have the key.\"\n", + " else:\n", + " if item[\"name\"] in object_relations and len(object_relations[item[\"name\"]]) > 0:\n", + " item_found = object_relations[item[\"name\"]].pop()\n", + " game_state[\"keys_collected\"].append(item_found)\n", + " output += \"You find \" + item_found[\"name\"] + \".\"\n", + " else:\n", + " output += \"There isn't anything interesting about it.\"\n", + " print(output)\n", + " break\n", + " if output is None:\n", + " print(\"The item you requested is not found in the current room.\")\n", + "\n", + " # Narrative next room when door is unlocked\n", + " if next_room:\n", + " if current_room[\"name\"] == \"game room\" and next_room[\"name\"] == \"bedroom 1\":\n", + " print(\"Will you step into the unknown through Door A?\")\n", + " elif current_room[\"name\"] == \"bedroom 1\" and next_room[\"name\"] == \"bedroom 2\":\n", + " print(\"Is it time to venture through Door B?\")\n", + " elif current_room[\"name\"] == \"bedroom 1\" and next_room[\"name\"] == \"living room\":\n", + " print(\"Are you ready to brave the unknown behind Door C?\")\n", + " elif current_room[\"name\"] == \"bedroom 2\" and next_room[\"name\"] == \"bedroom 1\":\n", + " print(\"Shall you retrace your steps through Door B?\")\n", + " else:\n", + " print(\"Is it time to step through Door D and see what lies beyond?\")\n", + " if next_room and input(\"Do you want to go to the next room? Enter Y for 'yes' or N for 'no': \").strip().lower() == 'y':\n", + " play_room(next_room, visited_rooms)\n", + " else:\n", + " play_room(current_room, visited_rooms)\n", + " else:\n", + " play_room(current_room, visited_rooms)\n", + "\n", + "# 3rd part (launch)\n", + "visited_rooms = set() # Define an empty set for visited_rooms\n", + "game_state = INIT_GAME_STATE.copy()\n", + "start_game(visited_rooms) # Pass the empty set to start_game\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "XBWwORKZ7vO9" + }, + "source": [ + "**Game Narrative**\n", + "Suddenly, you find yourself waking up on an unfamiliar couch, in an eerie house devoid of windows. Your memory fails to provide any explanation about how you ended up here, or what transpired previously. You can sense an imminent threat lurking somewhere - your gut tells you to escape the house immediately!\n", + "\n", + "You look around and realize you’re in a game room.\n", + "\n", + "“What should I do?” you ponder.\n", + "\n", + "You decide to explore the room, which uncovers a couch, a piano, and a locked Door A. The couch appears mundane and unexciting. However, examining the piano rewards you with a key for Door A. With the newfound key, you manage to unlock Door A.\n", + "\n", + "Will you step into the unknown through Door A?\n", + "\n", + "**Bedroom 1**\n", + "You step into Bedroom 1.\n", + "\n", + "Again, you find yourself contemplating - to explore or examine?\n", + "\n", + "Your exploration reveals a queen bed, Doors A, B, and C. Underneath the queen bed, you find a key for Door B. Door C remains an impenetrable barrier as it’s locked and you lack the key. But with the key you found under the bed, you manage to unlock Door B.\n", + "\n", + "Is it time to venture through Door B?\n", + "\n", + "**Bedroom 2**\n", + "Your journey leads you to Bedroom 2.\n", + "\n", + "“What now?” you think.\n", + "\n", + "A thorough exploration uncovers a double bed, a dresser, and Door B. Hidden in the double bed, you discover a key for Door C, and within the dresser, a key for Door D awaits. Equipped with the key for Door B, you decide to unlock it.\n", + "\n", + "Shall you retrace your steps through Door B?\n", + "\n", + "**Bedroom 1**\n", + "Once again, you find yourself in Bedroom 1.\n", + "\n", + "“What’s the next move?” you wonder.\n", + "\n", + "With the key for Door C in your possession, you manage to unlock it.\n", + "\n", + "Are you ready to brave the unknown behind Door C?\n", + "\n", + "**Living Room**\n", + "Stepping through Door C, you find yourself in the living room.\n", + "\n", + "“What secrets does this room hold?” you muse.\n", + "\n", + "Exploration reveals a dining table, Door C, and Door D. With the key for Door D in your grasp, you unlock it.\n", + "\n", + "Is it time to step through Door D and see what lies beyond?\n", + "\n", + "**Outside**\n", + "Freedom! You’ve managed to escape the room! Congrats on your successful adventure! Now, can you recount the thrilling journey and the clever strategy that got you here" + ] + } + ], + "metadata": { + "colab": { + "provenance": [], + "include_colab_link": true + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file