diff --git a/your-code/sample-code.ipynb b/your-code/.ipynb_checkpoints/main-checkpoint.ipynb similarity index 99% rename from your-code/sample-code.ipynb rename to your-code/.ipynb_checkpoints/main-checkpoint.ipynb index a6f8a94d..5b7c84e4 100644 --- a/your-code/sample-code.ipynb +++ b/your-code/.ipynb_checkpoints/main-checkpoint.ipynb @@ -226,7 +226,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -240,7 +240,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.9.13" } }, "nbformat": 4, diff --git a/your-code/Sounds_1.rar b/your-code/Sounds_1.rar new file mode 100644 index 00000000..bbac8fa5 Binary files /dev/null and b/your-code/Sounds_1.rar differ diff --git a/your-code/assets.zip b/your-code/assets.zip new file mode 100644 index 00000000..fecf5935 Binary files /dev/null and b/your-code/assets.zip differ diff --git a/your-code/main.ipynb b/your-code/main.ipynb new file mode 100644 index 00000000..5b7c84e4 --- /dev/null +++ b/your-code/main.ipynb @@ -0,0 +1,248 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "# define rooms and items\n", + "\n", + "couch = {\n", + " \"name\": \"couch\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "door_a = {\n", + " \"name\": \"door a\",\n", + " \"type\": \"door\",\n", + "}\n", + "\n", + "key_a = {\n", + " \"name\": \"key for door a\",\n", + " \"type\": \"key\",\n", + " \"target\": door_a,\n", + "}\n", + "\n", + "piano = {\n", + " \"name\": \"piano\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "game_room = {\n", + " \"name\": \"game room\",\n", + " \"type\": \"room\",\n", + "}\n", + "\n", + "outside = {\n", + " \"name\": \"outside\"\n", + "}\n", + "\n", + "all_rooms = [game_room, outside]\n", + "\n", + "all_doors = [door_a]\n", + "\n", + "# define which items/rooms are related\n", + "\n", + "object_relations = {\n", + " \"game room\": [couch, piano, door_a],\n", + " \"piano\": [key_a],\n", + " \"outside\": [door_a],\n", + " \"door a\": [game_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", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "def linebreak():\n", + " \"\"\"\n", + " Print a line break\n", + " \"\"\"\n", + " print(\"\\n\\n\")\n", + "\n", + "def start_game():\n", + " \"\"\"\n", + " Start the game\n", + " \"\"\"\n", + " print(\"You wake up on a couch and find yourself in a strange house with no windows which you have never been to before. You don't remember why you are here and what had happened before. You feel some unknown danger is approaching and you must get out of the house, NOW!\")\n", + " play_room(game_state[\"current_room\"])\n", + "\n", + "def play_room(room):\n", + " \"\"\"\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", + " print(\"You are now in \" + room[\"name\"])\n", + " intended_action = input(\"What would you like to do? Type 'explore' or 'examine'?\").strip()\n", + " if intended_action == \"explore\":\n", + " explore_room(room)\n", + " play_room(room)\n", + " elif intended_action == \"examine\":\n", + " examine_item(input(\"What would you like to examine?\").strip())\n", + " else:\n", + " print(\"Not sure what you mean. Type 'explore' or 'examine'.\")\n", + " play_room(room)\n", + " linebreak()\n", + "\n", + "def explore_room(room):\n", + " \"\"\"\n", + " Explore a room. List all items belonging to this room.\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", + "def examine_item(item_name):\n", + " \"\"\"\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", + " \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", + "\n", + " if(output is None):\n", + " print(\"The item you requested is not found in the current room.\")\n", + " \n", + " if(next_room and input(\"Do you want to go to the next room? Ener 'yes' or 'no'\").strip() == 'yes'):\n", + " play_room(next_room)\n", + " else:\n", + " play_room(current_room)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "You wake up on a couch and find yourself in a strange house with no windows which you have never been to before. You don't remember why you are here and what had happened before. You feel some unknown danger is approaching and you must get out of the house, NOW!\n", + "You are now in game room\n", + "What would you like to do? Type 'explore' or 'examine'?explore\n", + "You explore the room. This is game room. You find couch, piano, door a\n", + "You are now in game room\n", + "What would you like to do? Type 'explore' or 'examine'?examine\n", + "What would you like to examine?door a\n", + "You examine door a. It is locked but you don't have the key.\n", + "You are now in game room\n", + "What would you like to do? Type 'explore' or 'examine'?examine\n", + "What would you like to examine?piano\n", + "You examine piano. You find key for door a.\n", + "You are now in game room\n", + "What would you like to do? Type 'explore' or 'examine'?examine\n", + "What would you like to examine?door a\n", + "You examine door a. You unlock it with a key you have.\n", + "Do you want to go to the next room? Ener 'yes' or 'no'yes\n", + "Congrats! You escaped the room!\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n" + ] + } + ], + "source": [ + "game_state = INIT_GAME_STATE.copy()\n", + "\n", + "start_game()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/your-code/the_last_of_us_escape_room_-updatedv4_w_sounds.ipynb b/your-code/the_last_of_us_escape_room_-updatedv4_w_sounds.ipynb new file mode 100644 index 00000000..931aa955 --- /dev/null +++ b/your-code/the_last_of_us_escape_room_-updatedv4_w_sounds.ipynb @@ -0,0 +1,804 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "bfe9a0fd-b3dd-443e-a2ed-26f0a9fb1597", + "metadata": {}, + "source": [ + "# The Last Of Us Escape Room" + ] + }, + { + "cell_type": "markdown", + "id": "2b1332ea-5868-426e-812d-7c3a080038df", + "metadata": {}, + "source": [ + "#### Libraries used" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "887ac1d1-7836-421b-af9e-c369c3a7766b", + "metadata": {}, + "outputs": [], + "source": [ + "from PIL import Image #to load images\n", + "from playsound import playsound\n", + "#To install library in terminal follow this https://pillow.readthedocs.io/en/stable/installation.html" + ] + }, + { + "cell_type": "markdown", + "id": "f4d82c60-0d9d-45d4-a82d-1076a0afa625", + "metadata": {}, + "source": [ + "#### Rooms\n", + "\n", + "* orphanage\n", + "* quarantine zone\n", + "* wilderness\n", + "* fireflies lab\n" + ] + }, + { + "cell_type": "markdown", + "id": "e6703e9c-dc6d-4326-ad9c-e82073a6dae1", + "metadata": {}, + "source": [ + "#### Common items and main rooms" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "3b4a139d-68bc-41ac-8ab1-b22c15dcc7e8", + "metadata": {}, + "outputs": [], + "source": [ + "# define rooms and items\n", + "\n", + "outside = {\n", + " \"name\": \"outside\"\n", + "}\n", + "\n", + "orphanage = { #Sabir's code\n", + " \"name\": \"orphanage\",\n", + " \"type\": \"room\",\n", + "}\n", + "\n", + "quarantine_zone = { #Flor's code\n", + " \"name\": \"quarantine zone\",\n", + " \"type\": \"room\",\n", + "}\n", + "\n", + "\n", + "wilderness = { #Geet's code\n", + " \"name\": \"wilderness\", \n", + " \"type\": \"room\",\n", + "}\n", + " \n", + "fireflies_lab = { #Andre's code\n", + " \"name\": \"fireflies lab\",\n", + " \"type\": \"room\",\n", + "}" + ] + }, + { + "cell_type": "markdown", + "id": "d7b229b3-6df1-4533-8d8a-e7fc689eaf2d", + "metadata": {}, + "source": [ + "#### Orphanage items" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "7c01c82e-ca99-4235-9ee6-3e97037fd9b7", + "metadata": {}, + "outputs": [], + "source": [ + "# define rooms and items\n", + "\n", + "bunk_bed = {\n", + " \"name\": \"bunk bed\",\n", + " \"type\": \"furniture\"\n", + "}\n", + "\n", + "\n", + "doll = {\n", + " \"name\": \"doll\",\n", + " \"type\": \"item\"\n", + "}\n", + "\n", + "door = {\n", + " \"name\": \"door\",\n", + " \"type\": \"furniture\"\n", + "}\n", + "\n", + "window = {\n", + " \"name\": \"window\",\n", + " \"type\": \"exit\",\n", + " \"broken\": False\n", + "}\n", + "\n", + "hammer = {\n", + " \"name\": \"hammer\",\n", + " \"type\": \"item\"\n", + "}" + ] + }, + { + "cell_type": "markdown", + "id": "c99bc713-d6d6-406d-90f7-5bc1066c85a4", + "metadata": {}, + "source": [ + "#### Quarantine zone items" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "12672f68-78a2-4d55-9f26-82ac03b94ebf", + "metadata": {}, + "outputs": [], + "source": [ + "# define rooms and items\n", + "\n", + "first_aid_kit = {\n", + " \"name\": \"first aid kit\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "ammo = {\n", + " \"name\": \"ammo\",\n", + " \"type\": \"item\",\n", + "}\n", + "\n", + "warehouse_door = {\n", + " \"name\": \"warehouse door\",\n", + " \"type\": \"door\",\n", + "}\n", + "\n", + "\n", + "warehouse_key = {\n", + " \"name\": \"key for warehouse door\",\n", + " \"type\": \"key\",\n", + " \"target\": warehouse_door,\n", + "}\n", + "\n", + "safe = {\n", + " \"name\": \"safe\",\n", + " \"type\": \"item\",\n", + "}" + ] + }, + { + "cell_type": "markdown", + "id": "96c5c114-c70a-4705-885b-12a300a4b914", + "metadata": {}, + "source": [ + "#### Wilderness items" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "ebe08e7a-dcfc-4c6f-8c47-0f343d94884b", + "metadata": {}, + "outputs": [], + "source": [ + "tommys_hideout = {\n", + " \"name\": \"tommys hideout\",\n", + " \"type\": \"location\",\n", + "}\n", + "\n", + "henry_and_sams_hideout = {\n", + " \"name\":\"henry and sams hideout\",\n", + " \"type\": \"location\",\n", + "}\n", + "\n", + "bill_and_franks_place = {\n", + " \"name\":\"bill and franks place\",\n", + " \"type\": \"location\",\n", + "}\n", + "\n", + "\n", + "infected = { \n", + " \"name\": \"infected\",\n", + " \"type\": \"item\",\n", + "}\n", + "\n", + "bag = {\n", + " \"name\": \"bag\", \n", + " \"type\": \"item\"\n", + "}\n", + "\n", + "gun = {\n", + " \"name\": \"gun\",\n", + " \"type\": \"weapon\",\n", + "}\n", + "\n", + "death = {\n", + " \"name\": \" death\",\n", + " \"type\": 'item'\n", + "}\n", + "\n", + "knife = {\n", + " \"name\": \"knife\",\n", + " \"type\": \"weapon\",\n", + "}\n", + "\n", + "garage = {\n", + " \"name\": \"fireflies lab garage\",\n", + " \"type\": \"door\",\n", + "}\n", + "\n", + "car = {\n", + " \"name\": \"car to drive to fireflies\",\n", + " \"type\": \"item\", \n", + "}\n", + "\n", + "car_key = {\n", + " \"name\": \"car with control key to access fireflies lab garage\",\n", + " \"target\": garage, \n", + "}" + ] + }, + { + "cell_type": "markdown", + "id": "c017b529-0716-4135-a088-7ffb11c18f67", + "metadata": {}, + "source": [ + "#### Fireflies lab items" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "d6a17922-fefc-4eda-bb2d-4b83a3de68b8", + "metadata": {}, + "outputs": [], + "source": [ + "# define rooms and items\n", + "\n", + "labs_door = {\n", + " \"name\": \"lab's door\",\n", + " \"type\": \"door\",\n", + "}\n", + "\n", + "labs_key = {\n", + " \"name\": \"key for lab's door\",\n", + " \"type\": \"key\",\n", + " \"target\": labs_door,\n", + "}\n", + "\n", + "marlene = {\n", + " \"name\": \"Marlene\",\n", + " \"type\": \"person\",\n", + "}\n", + "\n", + "wooden_box = {\n", + " \"name\": \"wooden box\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "\n", + "grey_box = {\n", + " \"name\": \"grey_box\",\n", + " \"type\": \"gun\",\n", + " \"target\": marlene,\n", + "}\n", + "\n", + "\n", + "medical_table = {\n", + " \"name\": \"medical table\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "surgical_bed = {\n", + " \"name\": \"surgical bed\",\n", + " \"type\": \"furniture\",\n", + "}" + ] + }, + { + "cell_type": "markdown", + "id": "8e1ca150-c6f6-4b8e-8aee-dd70a9b64858", + "metadata": {}, + "source": [ + "#### Relationships between elements" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "cb663c61-f1ba-42c8-9ea7-88ac521c151b", + "metadata": {}, + "outputs": [], + "source": [ + "# define which items/rooms are related\n", + "\n", + "all_rooms = [orphanage , quarantine_zone, wilderness, fireflies_lab, outside]\n", + "\n", + "all_doors = [window, warehouse_door, garage, labs_door] \n", + "\n", + "\n", + "object_relations = {\n", + " \"orphanage\": [doll, door, window, bunk_bed], \n", + " \"hammer\": [window],\n", + " \"bunk bed\": [hammer],\n", + " \n", + " \"quarantine zone\": [window, first_aid_kit, ammo, warehouse_door, safe],\n", + " \"open safe\": [warehouse_key],\n", + " \n", + " \"wilderness\": [henry_and_sams_hideout, bill_and_franks_place, infected, garage, tommys_hideout], \n", + " \"tommys hideout\": [car, car_key],\n", + " \"henry_and_sams_hideout\":[infected],\n", + " \"bill_and_franks_place\": [bag],\n", + " \"infected\": [death],\n", + " \"bag\": [knife, gun],\n", + " \n", + " \"fireflies lab\": [medical_table, wooden_box, labs_door, surgical_bed], \n", + " \"medical table\": [],\n", + " \"wooden box\": [grey_box],\n", + " \"grey box\": [marlene],\n", + " \"surgical bed\": [labs_key],\n", + " \"outside\": [labs_door],\n", + " \n", + " \"window\": [orphanage, quarantine_zone],\n", + " \"warehouse door\": [quarantine_zone, wilderness],\n", + " \"fireflies lab garage\": [wilderness, fireflies_lab],\n", + " \"lab's door\": [fireflies_lab, outside],\n", + "}" + ] + }, + { + "cell_type": "markdown", + "id": "db8bfdf4-777e-4445-b42f-d4bb34a630d4", + "metadata": {}, + "source": [ + "#### Initialize game" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "c5fa7762-fb0d-4974-891c-ffe014dcdef6", + "metadata": {}, + "outputs": [], + "source": [ + "# 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\": orphanage,\n", + " \"keys_collected\": [],\n", + " \"items_collected\": [],\n", + " \"target_room\": outside\n", + "}" + ] + }, + { + "cell_type": "markdown", + "id": "77da7212-ad64-45de-91c0-b9a23cc3e44b", + "metadata": {}, + "source": [ + "#### In-game actions" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "4c7c6ede-b8b2-4aab-81b5-cea6475b454b", + "metadata": {}, + "outputs": [], + "source": [ + "def linebreak():\n", + " \"\"\"\n", + " Print a line break\n", + " \"\"\"\n", + " print(\"\\n\\n\")\n", + "\n", + "def start_game():\n", + " \"\"\"\n", + " Start the game\n", + " \"\"\"\n", + " print(\"Ellie wakes up on a bunk bed in the orphanage. She wants to escape this place as she feels a danger is incoming, but realizes that the door is locked from the outside, so she needs to find another way out.\")\n", + " with Image.open(r'C:\\Users\\User\\OneDrive\\Desktop\\Ironhack Bootcamp\\Labs\\python-project\\your-code\\assets\\1_ellie_initial.jpeg') as img: img.show()\n", + " play_room(game_state[\"current_room\"])\n", + " \n", + "def play_room(room):\n", + " \"\"\"\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(\"You escaped the room, but... Marlene, the leader of the Fireflies, is here and she has a gun!\")\n", + " with Image.open(r'C:\\Users\\User\\OneDrive\\Desktop\\Ironhack Bootcamp\\Labs\\python-project\\your-code\\assets\\2_Marlene1.jpg') as img: img.show()\n", + " choice = input(\"Do you want to speak or shoot her? Quick! (speak/shoot)\")\n", + " end_game(choice) #The end of the game is activated\n", + " else:\n", + " print(\"You are now in \" + room[\"name\"])\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", + " play_room(room)\n", + " elif intended_action == \"2\":\n", + " examine_item(input(\"What would you like to examine?\").strip())\n", + " else:\n", + " print(\"Not sure what you mean. Type '1' or '2'.\")\n", + " play_room(room)\n", + " linebreak()\n", + "\n", + "def explore_room(room):\n", + " \"\"\"\n", + " Explore a room. List all items belonging to this room.\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", + "\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):\n", + " \"\"\"\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", + "\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\"] == \"safe\"): #Additional interactions with elements\n", + " open_safe(item_name)\n", + " return \n", + " elif(item[\"name\"] == \"wooden box\"): #Additional interactions with elements\n", + " open_box(item_name)\n", + " return \n", + " elif(item[\"name\"] == \"medical table\"): #Additional interactions with elements\n", + " open_note(item_name)\n", + " return \n", + " elif(item[\"name\"] == \"surgical bed\"): #Additional interactions with elements\n", + " find_ellie(item_name)\n", + " return\n", + " elif(item[\"name\"] == \"window\"):\n", + " if item[\"broken\"]:\n", + " intended_action = input(\"The window is broken. Do you want to go through? 'yes' or 'no'\")\n", + " if intended_action == 'yes':\n", + " next_room = get_next_room_of_door(item, current_room)\n", + " play_room(next_room)\n", + " return\n", + " elif intended_action == 'no':\n", + " play_room(current_room)\n", + " return\n", + " else:\n", + " if hammer in game_state[\"items_collected\"]: \n", + " break_window(item)\n", + " return\n", + " else:\n", + " print(\"Maybe I can find something to break it with\")\n", + " play_room(current_room)\n", + " return\n", + " elif(item[\"name\"] == \"doll\"):\n", + " print(\"Looks like a teddy bear\")\n", + " play_room(current_room)\n", + " return\n", + " elif(item[\"name\"] == \"door\"):\n", + " print(\"The door is locked from the outside, no way to open it\")\n", + " play_room(current_room)\n", + " return\n", + " elif(item[\"name\"] == \"bunk bed\"):\n", + " print(\"An uncomfortable bed Ellie used to sleep in.\")\n", + " intended_action = input(\"Do you want to look under the bed. 'yes' or 'no'\")\n", + " if intended_action == \"yes\":\n", + " pickup_hammer(item_name)\n", + " return\n", + " elif intended_action == \"no\":\n", + " play_room(current_room)\n", + " else:\n", + " print(\"Invalid choice. Please enter 'yes' or 'no'.\")\n", + " play_room(current_room)\n", + " \n", + " elif(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", + " with Image.open(r'C:\\Users\\User\\OneDrive\\Desktop\\Ironhack Bootcamp\\Labs\\python-project\\your-code\\assets\\3_key.jpeg') as img: img.show()\n", + " playsound(r'C:\\Users\\User\\OneDrive\\Desktop\\Ironhack Bootcamp\\Labs\\python-project\\your-code\\Sounds\\car.wav')\n", + " else:\n", + " output += \"There isn't anything interesting about it.\"\n", + " print(output)\n", + " break\n", + "\n", + " if(output is None):\n", + " print(\"The item you requested is not found in the current room.\")\n", + " \n", + " if(next_room and input(\"Do you want to go to the next room? Enter 'yes' or 'no'\").strip() == 'yes'):\n", + " if (game_state[\"current_room\"]['name'] == \"quarantine zone\"):\n", + " playsound(r'C:\\Users\\User\\OneDrive\\Desktop\\Ironhack Bootcamp\\Labs\\python-project\\your-code\\Sounds\\warehousekey.mp3')\n", + " print(\"This place is plagued with infected people. You need to find out safe place to protect yourself and plan your next step.\")\n", + " with Image.open(r'C:\\Users\\User\\OneDrive\\Desktop\\Ironhack Bootcamp\\Labs\\python-project\\your-code\\assets\\4_Ellie_Joel.jpg') as img: img.show()\n", + " elif (game_state[\"current_room\"]['name'] == \"wilderness\"):\n", + " print(\"Ellie and Joel finally arrived at the Fireflies' lab, but suddenly… Joel was attacked by some Fireflies members and wakes up in a hospital bed. \\nHe was informed that the Fireflies planned to operate on Ellie in order to find a cure for the virus. However, they warned Joel that the chances of Ellie's survival were low. \\nSo, Joel made the decision to rescue Ellie!!!\")\n", + " with Image.open(r'C:\\Users\\User\\OneDrive\\Desktop\\Ironhack Bootcamp\\Labs\\python-project\\your-code\\assets\\5_FirleFliesLab.jpeg') as img: img.show()\n", + " play_room(next_room)\n", + " else:\n", + " play_room(current_room) \n", + "\n" + ] + }, + { + "cell_type": "markdown", + "id": "f34a0035-e299-4912-a30d-c780c6ab73e3", + "metadata": {}, + "source": [ + "#### Additional interactions" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "062564ca-32ed-495a-91a4-1c435a2bd152", + "metadata": {}, + "outputs": [], + "source": [ + "def pickup_hammer(item_name):\n", + " item_found = object_relations[item_name].pop()\n", + " game_state[\"items_collected\"].append(item_found)\n", + " print(\"You have found \"+item_found[\"name\"]+\".\")\n", + " with Image.open(r'C:\\Users\\User\\OneDrive\\Desktop\\Ironhack Bootcamp\\Labs\\python-project\\your-code\\assets\\6_hammer.jpeg') as img: img.show()\n", + " play_room(game_state[\"current_room\"])\n", + " \n", + "def break_window(item):\n", + " intended_action = input(\"The found hammer might be able to break the window. Do you want to try and break it? 'yes' or 'no'\").strip()\n", + " if intended_action == 'yes':\n", + " window[\"broken\"] = True\n", + " playsound(r'C:\\Users\\User\\OneDrive\\Desktop\\Ironhack Bootcamp\\Labs\\python-project\\your-code\\Sounds\\glassbreak.mp3')\n", + " intended_action_2 = input(\"You broke the window. Do you want to go through? 'yes' or 'no'\")\n", + " if intended_action_2 == 'yes':\n", + " with Image.open(r'C:\\Users\\User\\OneDrive\\Desktop\\Ironhack Bootcamp\\Labs\\python-project\\your-code\\assets\\7_warehouse.jpeg') as img: img.show()\n", + " print(\"After going through the window, Ellie enters a big warehouse where she can read the words 'Quarantine Zone' on the wall, she hides behind a pallet of boxes. \\nShe hears a familiar voice, it's her friend Marlene! but oh no!... she is hurt, they were supposed to escape together, but now Marlene needs to get medical attention so she asks Ellie to escape with Joel that was with her. \\nEllie doesn't trust him, and she doesn't want to leave Marlene behind, but Marlene asks her to go with him, now they need to decipher a way to get out this place.\")\n", + " next_room = get_next_room_of_door(item, game_state[\"current_room\"])\n", + " play_room(next_room)\n", + " elif intended_action_2 == 'no':\n", + " play_room(game_state[\"current_room\"])\n", + " else:\n", + " print(\"Invalid choice. Please enter 'yes' or 'no'.\")\n", + " play_room(game_state[\"current_room\"])\n", + " elif intended_action == 'no':\n", + " play_room(game_state[\"current_room\"])\n", + " else:\n", + " print(\"Invalid choice. Please enter 'yes' or 'no'.\")\n", + " play_room(game_state[\"current_room\"])\n", + " \n", + "def open_safe(item_name):\n", + " 'The safe contains a key, but to access it you have to open the safe by completing the missing code'\n", + " current_room = game_state[\"current_room\"]\n", + " print(\"You find a safe. To open it, you have to figure out the missing digits in the pasword. See if there is a pattern behind the numbers shown.\")\n", + " intended_action = input(\"Do you want to try? Enter 'yes' or 'no'\").strip()\n", + " if intended_action == \"yes\":\n", + " with Image.open(r'C:\\Users\\User\\OneDrive\\Desktop\\Ironhack Bootcamp\\Labs\\python-project\\your-code\\assets\\8_safe.jpeg') as img: img.show()\n", + " #print('| 4 | 3 | 9 | 4 | 5 | 7 |')\n", + " #print('| 1 | 0 | 6 | ? | ? | 4 |')\n", + " print(\"What are the missing digits?\")\n", + " first_digit = input('indicate first missing digit ').strip()\n", + " second_digit = input('indicate second missing digit ').strip() \n", + " if first_digit == \"1\" and second_digit == \"2\":\n", + " playsound(r'C:\\Users\\User\\OneDrive\\Desktop\\Ironhack Bootcamp\\Labs\\python-project\\your-code\\Sounds\\safe.mp3')\n", + " playsound(r'C:\\Users\\User\\OneDrive\\Desktop\\Ironhack Bootcamp\\Labs\\python-project\\your-code\\Sounds\\keys.mp3')\n", + " safe = {\n", + " \"name\": \"open safe\",\n", + " \"type\": \"item\",\n", + " }\n", + " item_found = object_relations['open safe'].pop()\n", + " game_state[\"keys_collected\"].append(item_found)\n", + " output = \"You opened the safe and found \" + item_found[\"name\"] + \".\"\n", + " with Image.open(r'C:\\Users\\User\\OneDrive\\Desktop\\Ironhack Bootcamp\\Labs\\python-project\\your-code\\assets\\3_key.jpeg') as img: img.show()\n", + " print(output)\n", + " play_room(current_room)\n", + " else:\n", + " print(\"Incorrect password, safe did not open.\")\n", + " play_room(current_room)\n", + " else:\n", + " print('we can check it later then')\n", + " play_room(current_room)\n", + " \n", + "def open_box(item_name):\n", + " 'You have to decide between two boxes and open one, one explodes and you die, and the other one contains a gun to use later'\n", + " current_room = game_state[\"current_room\"]\n", + " print(\"You found a wooden box. Inside there are two boxes, a grey one and a black one.\")\n", + " with Image.open(r'C:\\Users\\User\\OneDrive\\Desktop\\Ironhack Bootcamp\\Labs\\python-project\\your-code\\assets\\9_wooden_box.jpeg') as img: img.show()\n", + " choice = input(\"Which box do you want to open? (grey/black)\")\n", + " if (choice == \"grey\"):\n", + " print(\"You open the grey box and find a gun inside. You add it to your items collection.\")\n", + " with Image.open(r'C:\\Users\\User\\OneDrive\\Desktop\\Ironhack Bootcamp\\Labs\\python-project\\your-code\\assets/10_gun_lab.jpg') as img: img.show()\n", + " item_found = object_relations[\"grey box\"].pop()\n", + " game_state[\"items_collected\"].append(item_found)\n", + " play_room(current_room)\n", + " elif (choice == \"black\"):\n", + " print(\"You open the black box and it explodes! You die! - \\n YOU LOST\")\n", + " playsound(r'C:\\Users\\User\\OneDrive\\Desktop\\Ironhack Bootcamp\\Labs\\python-project\\your-code\\Sounds\\explosion.wav')\n", + " with Image.open(r'C:\\Users\\User\\OneDrive\\Desktop\\Ironhack Bootcamp\\Labs\\python-project\\your-code\\assets\\11_bomb.jpeg') as img: img.show()\n", + " game_over()\n", + " else:\n", + " print(\"Invalid choice.\")\n", + " play_room(current_room)\n", + " \n", + "def open_note(item_name):\n", + " current_room = game_state[\"current_room\"]\n", + " print(\"There is a note! \\n She is too important for us! We will do everything to protect her!\")\n", + " with Image.open(r'C:\\Users\\User\\OneDrive\\Desktop\\Ironhack Bootcamp\\Labs\\python-project\\your-code\\assets\\12_medical_bed.jpeg') as img: img.show()\n", + " play_room(current_room)\n", + "\n", + "\n", + "def find_ellie(item_name):\n", + " current_room = game_state[\"current_room\"]\n", + " item_found = object_relations[\"surgical bed\"].pop()\n", + " game_state[\"keys_collected\"].append(item_found)\n", + " print(\"You found Ellie! Now she is with you! And there is also a key for lab's door!\")\n", + " with Image.open(r'C:\\Users\\User\\OneDrive\\Desktop\\Ironhack Bootcamp\\Labs\\python-project\\your-code\\assets\\13_Surgical_Table.jpeg') as img: img.show()\n", + " play_room(current_room) \n", + "\n", + "def end_game (choice):\n", + " current_room = game_state[\"current_room\"]\n", + " if (choice == \"speak\"):\n", + " print(\"She does not want to chat! Marlene killed you and she is tacking Ellie with her! - \\n YOU LOST\")\n", + " with Image.open(r'C:\\Users\\User\\OneDrive\\Desktop\\Ironhack Bootcamp\\Labs\\python-project\\your-code\\assets\\14_Marlene_killed2.jpeg') as img: img.show()\n", + " game_over()\n", + " elif (choice == \"shoot\"):\n", + " have_gun = False\n", + " for item in game_state[\"items_collected\"]:\n", + " if (item[\"name\"] == \"Marlene\"):\n", + " have_gun = True\n", + " if (have_gun):\n", + " playsound(r'C:\\Users\\User\\OneDrive\\Desktop\\Ironhack Bootcamp\\Labs\\python-project\\your-code\\Sounds\\gunshot2.mp3')\n", + " print(\"You killed Marlene and saved Ellie! Our mission just started... Let´s go! - \\n YOU WON\")\n", + " with Image.open(r'C:\\Users\\User\\OneDrive\\Desktop\\Ironhack Bootcamp\\Labs\\python-project\\your-code\\assets\\15_victory_image.jpg') as img: img.show()\n", + " game_over()\n", + " else:\n", + " print(\"You have no bullets! F***! Marlene killed you and she is tacking Ellie with her!! - \\n YOU LOST.\")\n", + " with Image.open(r'C:\\Users\\User\\OneDrive\\Desktop\\Ironhack Bootcamp\\Labs\\python-project\\your-code\\assets\\14_Marlene_killed2.jpeg') as img: img.show()\n", + " game_over()\n", + "\n", + " else:\n", + " print(\"Invalid choice. Please enter 'speak' or 'shoot'.\")\n", + " play_room(current_room) \n", + " \n", + "\n", + "def game_over():\n", + " intended_action = input(\"Want to start over? 'yes' or 'no'\")\n", + " if intended_action == 'yes':\n", + " INIT_GAME_STATE = {\n", + " \"current_room\": orphanage,\n", + " \"keys_collected\": [],\n", + " \"items_collected\": [],\n", + " \"target_room\": outside\n", + " }\n", + " print(\"Ellie wakes up on a bunk bed in the orphanage. She wants to escape this place as she feels a danger is incoming, but realizes that the door is locked from the outside, so she needs to find another way out.\")\n", + " play_room(orphanage)\n", + " else:\n", + " print('Thanks for playing!')\n", + "\n", + " \n", + " " + ] + }, + { + "cell_type": "markdown", + "id": "cc96ea0c-2f30-4ade-90c7-f792fd859100", + "metadata": {}, + "source": [ + "#### Play" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a1b650b1-f08e-40a9-b08c-56aaeb5e8878", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ellie wakes up on a bunk bed in the orphanage. She wants to escape this place as she feels a danger is incoming, but realizes that the door is locked from the outside, so she needs to find another way out.\n", + "You are now in orphanage\n", + "What would you like to do? Type 1 for 'explore' or 2 for 'examine'?2\n", + "What would you like to examine?bunk bed\n", + "An uncomfortable bed Ellie used to sleep in.\n", + "Do you want to look under the bed. 'yes' or 'no'yes\n", + "You have found hammer.\n", + "You are now in orphanage\n" + ] + } + ], + "source": [ + "game_state = INIT_GAME_STATE.copy()\n", + "\n", + "start_game()" + ] + }, + { + "cell_type": "markdown", + "id": "0edee7f1", + "metadata": {}, + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7f151911", + "metadata": {}, + "outputs": [], + "source": [ + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bd72180d", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}