diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..4d6f5fa0 Binary files /dev/null and b/.DS_Store differ diff --git a/your-code/.DS_Store b/your-code/.DS_Store new file mode 100644 index 00000000..5008ddfc Binary files /dev/null and b/your-code/.DS_Store differ diff --git a/your-code/.ipynb_checkpoints/Bedroom_2-checkpoint.ipynb b/your-code/.ipynb_checkpoints/Bedroom_2-checkpoint.ipynb new file mode 100644 index 00000000..f7cfb0fb --- /dev/null +++ b/your-code/.ipynb_checkpoints/Bedroom_2-checkpoint.ipynb @@ -0,0 +1,178 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "3081742b", + "metadata": {}, + "outputs": [], + "source": [ + "# codes for bedroom 2\n", + "\n", + "# define room and items related to bedroom 2\n", + "\n", + "double_bed = {\n", + " \"name\": \"double bed\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "dresser = {\n", + " \"name\": \"dresser\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "door_b = {\n", + " \"name\": \"door b\",\n", + " \"type\": \"door\",\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", + "\n", + "bedroom_2 = {\n", + " \"name\": \"bedroom 2\",\n", + " \"type\": \"room\",\n", + "}\n", + "\n", + "all_rooms = [bedroom_1, bedroom_2]\n", + "\n", + "all_doors = [door_b]\n", + "\n", + "# define which items/rooms are related\n", + "\n", + "object_relations = {\n", + " \"bedroom_2\": [double_bed, dresser, door_b],\n", + " \"double_bed\": [key_c],\n", + " \"dresser\": [key_d],\n", + " \"bedroom_1\": [door_b],\n", + " \"door b\": [bedroom_1]\n", + "}\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c6caf3a4", + "metadata": {}, + "outputs": [], + "source": [ + "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)" + ] + } + ], + "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.12" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/your-code/.ipynb_checkpoints/Escape_room_final-checkpoint.ipynb b/your-code/.ipynb_checkpoints/Escape_room_final-checkpoint.ipynb new file mode 100644 index 00000000..88705089 --- /dev/null +++ b/your-code/.ipynb_checkpoints/Escape_room_final-checkpoint.ipynb @@ -0,0 +1,394 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "4b957a7e", + "metadata": {}, + "outputs": [], + "source": [ + "# define rooms and items\n", + "# gameroom\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", + "\n", + "\n", + "# bedroom 1\n", + "\n", + "bedroom_1 = {\n", + " \"name\": \"bedroom 1\",\n", + " \"type\": \"room\",\n", + "}\n", + "\n", + "queen_bed = {\n", + " \"name\": \"queen bed\",\n", + " \"type\": \"furniture\",\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", + "key_b = {\n", + " \"name\": \"key for door b\",\n", + " \"type\": \"key\",\n", + " \"target\": door_b,\n", + "}\n", + "\n", + "# bedroom 2\n", + "\n", + "bedroom_2 = {\n", + " \"name\": \"bedroom 2\",\n", + " \"type\": \"room\",\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", + "door_b = {\n", + " \"name\": \"door b\",\n", + " \"type\": \"door\",\n", + "}\n", + "door_d = {\n", + " \"name\": \"door d\",\n", + " \"type\": \"door\",\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", + "# living room\n", + "\n", + "living_room = {\n", + " \"name\": \"living room\",\n", + " \"type\": \"room\",\n", + "}\n", + "dining_table= {\n", + " \"name\": \"dining table\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "#Images for the rooms\n", + "import cv2\n", + "image_start_game = cv2.imread('open game.jpg')\n", + "image_game_room = cv2.imread(\"game room.jpg\")\n", + "image_bedroom1 = cv2.imread(\"bedroom 1.jpg\")\n", + "image_bedroom2 = cv2.imread(\"bedroom 2.jpg\")\n", + "image_living_room = cv2.imread(\"living room.jpg\")\n", + "image_outside = cv2.imread(\"outside.jpg\")\n", + "\n", + "#Images for the objects\n", + "import cv2\n", + "image_piano = cv2.imread(\"piano.jpg\")\n", + "image_couch = cv2.imread(\"couch.jpg\")\n", + "image_door_a = cv2.imread(\"door a.jpg\")\n", + "image_key_a = cv2.imread(\"key a.jpg\")\n", + "image_queen_bed = cv2.imread(\"queen bed.jpg\")\n", + "image_door_b = cv2.imread(\"door b.jpg\")\n", + "image_door_c = cv2.imread(\"door c.jpg\")\n", + "image_double_bed = cv2.imread(\"double bed.jpg\")\n", + "image_dresser = cv2.imread(\"dresser.jpg\")\n", + "image_dining_table = cv2.imread(\"dining table.jpg\")\n", + "image_key_d = cv2.imread(\"key d.jpg\")\n", + "image_door_d = cv2.imread(\"key d.jpg\")\n", + "image_key_b = cv2.imread(\"key b.jpg\")\n", + "image_key_c = cv2.imread(\"key c.jpg\")\n", + "\n", + "\n", + "\n", + "all_images_rooms = [image_game_room, image_bedroom1, image_bedroom2, image_living_room,image_outside]\n", + "\n", + "all_rooms = [game_room, bedroom_1, bedroom_2, living_room]\n", + "\n", + "all_doors = [door_a, door_b, door_c, door_d]\n", + "\n", + "#define which images are related to which room\n", + "\n", + "image_relations_rooms = {\n", + " \"game room\": image_game_room,\n", + " \"living room\": image_living_room,\n", + " \"bedroom 1\": image_bedroom1,\n", + " \"bedroom 2\": image_bedroom2,\n", + " \"living room\": image_living_room\n", + "}\n", + "\n", + "# define which items/rooms are related\n", + "\n", + "object_relations = {\n", + " \"game room\": [couch, piano, door_a],\n", + " \"piano\": [key_a],\n", + " \"living room\": [door_c], \n", + " \"door a\": [game_room, bedroom_1], \n", + " \"bedroom 1\": [queen_bed, door_a, door_b, door_c],\n", + " \"door b\": [bedroom_1, bedroom_2],\n", + " \"queen bed\": [key_b],\n", + " \"door c\": [bedroom_1, living_room],\n", + " \"bedroom 2\": [double_bed, dresser, door_b],\n", + " \"double bed\": [key_c],\n", + " \"dresser\": [key_d],\n", + " \"door d\": [living_room, outside], \n", + " \"living room\":[dining_table,door_d],\n", + " \"outside\": [door_d]\n", + "}\n", + "\n", + "object_picture_relations = {\n", + " \"couch\": image_couch,\n", + " \"piano\": image_piano,\n", + " \"door a\": image_door_a,\n", + " \"key a\" : image_key_a,\n", + " \"queen bed\": image_queen_bed,\n", + " \"door b\": image_door_b,\n", + " \"door c\": image_door_c,\n", + " \"key b\": image_key_b,\n", + " \"double bed\": image_double_bed,\n", + " \"dresser\": image_dresser,\n", + " \"key c\": image_key_c,\n", + " \"key d\": image_key_d,\n", + " \"door d\": image_door_d,\n", + " \"dining table\": image_dining_table\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", + "def play_image_room(x):\n", + " cv2.imshow('image',x)\n", + " cv2.waitKey(4000) #milliseconds\n", + " cv2.destroyAllWindows()\n", + " return x\n", + "\n", + "def play_image_object(picture):\n", + " cv2.imshow('image',picture)\n", + " cv2.waitKey(2000) #milliseconds\n", + " cv2.destroyAllWindows()\n", + " return picture\n", + "\n", + "\n", + "\n", + "INIT_GAME_STATE = {\n", + " \"current_room\": game_room,\n", + " \"keys_collected\": [],\n", + " \"target_room\": outside\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "6d538742", + "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", + "\n", + " print(\"You wake up on a couch and find yourself in an abandoned house which you have never been to before. You don't remember why you are here and what had happened before. You so something and hope you are dreaming. You must get out of the house, NOW!\")\n", + " play_image_room(image_start_game)\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", + " play_image_room(image_outside)\n", + " print(\"Congrats! You are finally free!\")\n", + " else:\n", + " print(\"You are now in \" + room[\"name\"])\n", + " intended_action = input(\"What would you like to do? Type 'explore' or 'check'?\").strip()\n", + " if intended_action == \"explore\":\n", + " explore_room(room)\n", + " play_room(room)\n", + " elif intended_action == \"check\":\n", + " check_item(input(\"What would you like to check?\").strip())\n", + " else:\n", + " print(\"I do not understand what you mean. Type 'explore' or 'check'.\")\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\"])\n", + " play_image_room(image_relations_rooms[room[\"name\"]])\n", + " print(\"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", + "def check_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 check \" + item_name + \". \"\n", + " play_image_object(object_picture_relations[item_name]) ################important\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 the door with a key you have.\"\n", + " next_room = get_next_room_of_door(item, current_room)\n", + " else:\n", + " output += \"The door 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 new to find.\"\n", + " print(output)\n", + " break\n", + "\n", + " if(output is None):\n", + " print(\"The item you asked 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", + " play_room(next_room)\n", + " else:\n", + " play_room(current_room)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e71d49a8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "You wake up on a couch and find yourself in an abandoned house which you have never been to before. You don't remember why you are here and what had happened before. You so something and hope you are dreaming. You must get out of the house, NOW!\n", + "You are now in game room\n" + ] + } + ], + "source": [ + "game_state = INIT_GAME_STATE.copy()\n", + "\n", + "start_game()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ecb14a73", + "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.12" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/your-code/sample-code.ipynb b/your-code/.ipynb_checkpoints/sample-code-checkpoint.ipynb similarity index 99% rename from your-code/sample-code.ipynb rename to your-code/.ipynb_checkpoints/sample-code-checkpoint.ipynb index a6f8a94d..90704b03 100644 --- a/your-code/sample-code.ipynb +++ b/your-code/.ipynb_checkpoints/sample-code-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.12" } }, "nbformat": 4, diff --git a/your-code/Escape_room_final.ipynb b/your-code/Escape_room_final.ipynb new file mode 100644 index 00000000..88705089 --- /dev/null +++ b/your-code/Escape_room_final.ipynb @@ -0,0 +1,394 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "4b957a7e", + "metadata": {}, + "outputs": [], + "source": [ + "# define rooms and items\n", + "# gameroom\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", + "\n", + "\n", + "# bedroom 1\n", + "\n", + "bedroom_1 = {\n", + " \"name\": \"bedroom 1\",\n", + " \"type\": \"room\",\n", + "}\n", + "\n", + "queen_bed = {\n", + " \"name\": \"queen bed\",\n", + " \"type\": \"furniture\",\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", + "key_b = {\n", + " \"name\": \"key for door b\",\n", + " \"type\": \"key\",\n", + " \"target\": door_b,\n", + "}\n", + "\n", + "# bedroom 2\n", + "\n", + "bedroom_2 = {\n", + " \"name\": \"bedroom 2\",\n", + " \"type\": \"room\",\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", + "door_b = {\n", + " \"name\": \"door b\",\n", + " \"type\": \"door\",\n", + "}\n", + "door_d = {\n", + " \"name\": \"door d\",\n", + " \"type\": \"door\",\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", + "# living room\n", + "\n", + "living_room = {\n", + " \"name\": \"living room\",\n", + " \"type\": \"room\",\n", + "}\n", + "dining_table= {\n", + " \"name\": \"dining table\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "#Images for the rooms\n", + "import cv2\n", + "image_start_game = cv2.imread('open game.jpg')\n", + "image_game_room = cv2.imread(\"game room.jpg\")\n", + "image_bedroom1 = cv2.imread(\"bedroom 1.jpg\")\n", + "image_bedroom2 = cv2.imread(\"bedroom 2.jpg\")\n", + "image_living_room = cv2.imread(\"living room.jpg\")\n", + "image_outside = cv2.imread(\"outside.jpg\")\n", + "\n", + "#Images for the objects\n", + "import cv2\n", + "image_piano = cv2.imread(\"piano.jpg\")\n", + "image_couch = cv2.imread(\"couch.jpg\")\n", + "image_door_a = cv2.imread(\"door a.jpg\")\n", + "image_key_a = cv2.imread(\"key a.jpg\")\n", + "image_queen_bed = cv2.imread(\"queen bed.jpg\")\n", + "image_door_b = cv2.imread(\"door b.jpg\")\n", + "image_door_c = cv2.imread(\"door c.jpg\")\n", + "image_double_bed = cv2.imread(\"double bed.jpg\")\n", + "image_dresser = cv2.imread(\"dresser.jpg\")\n", + "image_dining_table = cv2.imread(\"dining table.jpg\")\n", + "image_key_d = cv2.imread(\"key d.jpg\")\n", + "image_door_d = cv2.imread(\"key d.jpg\")\n", + "image_key_b = cv2.imread(\"key b.jpg\")\n", + "image_key_c = cv2.imread(\"key c.jpg\")\n", + "\n", + "\n", + "\n", + "all_images_rooms = [image_game_room, image_bedroom1, image_bedroom2, image_living_room,image_outside]\n", + "\n", + "all_rooms = [game_room, bedroom_1, bedroom_2, living_room]\n", + "\n", + "all_doors = [door_a, door_b, door_c, door_d]\n", + "\n", + "#define which images are related to which room\n", + "\n", + "image_relations_rooms = {\n", + " \"game room\": image_game_room,\n", + " \"living room\": image_living_room,\n", + " \"bedroom 1\": image_bedroom1,\n", + " \"bedroom 2\": image_bedroom2,\n", + " \"living room\": image_living_room\n", + "}\n", + "\n", + "# define which items/rooms are related\n", + "\n", + "object_relations = {\n", + " \"game room\": [couch, piano, door_a],\n", + " \"piano\": [key_a],\n", + " \"living room\": [door_c], \n", + " \"door a\": [game_room, bedroom_1], \n", + " \"bedroom 1\": [queen_bed, door_a, door_b, door_c],\n", + " \"door b\": [bedroom_1, bedroom_2],\n", + " \"queen bed\": [key_b],\n", + " \"door c\": [bedroom_1, living_room],\n", + " \"bedroom 2\": [double_bed, dresser, door_b],\n", + " \"double bed\": [key_c],\n", + " \"dresser\": [key_d],\n", + " \"door d\": [living_room, outside], \n", + " \"living room\":[dining_table,door_d],\n", + " \"outside\": [door_d]\n", + "}\n", + "\n", + "object_picture_relations = {\n", + " \"couch\": image_couch,\n", + " \"piano\": image_piano,\n", + " \"door a\": image_door_a,\n", + " \"key a\" : image_key_a,\n", + " \"queen bed\": image_queen_bed,\n", + " \"door b\": image_door_b,\n", + " \"door c\": image_door_c,\n", + " \"key b\": image_key_b,\n", + " \"double bed\": image_double_bed,\n", + " \"dresser\": image_dresser,\n", + " \"key c\": image_key_c,\n", + " \"key d\": image_key_d,\n", + " \"door d\": image_door_d,\n", + " \"dining table\": image_dining_table\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", + "def play_image_room(x):\n", + " cv2.imshow('image',x)\n", + " cv2.waitKey(4000) #milliseconds\n", + " cv2.destroyAllWindows()\n", + " return x\n", + "\n", + "def play_image_object(picture):\n", + " cv2.imshow('image',picture)\n", + " cv2.waitKey(2000) #milliseconds\n", + " cv2.destroyAllWindows()\n", + " return picture\n", + "\n", + "\n", + "\n", + "INIT_GAME_STATE = {\n", + " \"current_room\": game_room,\n", + " \"keys_collected\": [],\n", + " \"target_room\": outside\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "6d538742", + "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", + "\n", + " print(\"You wake up on a couch and find yourself in an abandoned house which you have never been to before. You don't remember why you are here and what had happened before. You so something and hope you are dreaming. You must get out of the house, NOW!\")\n", + " play_image_room(image_start_game)\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", + " play_image_room(image_outside)\n", + " print(\"Congrats! You are finally free!\")\n", + " else:\n", + " print(\"You are now in \" + room[\"name\"])\n", + " intended_action = input(\"What would you like to do? Type 'explore' or 'check'?\").strip()\n", + " if intended_action == \"explore\":\n", + " explore_room(room)\n", + " play_room(room)\n", + " elif intended_action == \"check\":\n", + " check_item(input(\"What would you like to check?\").strip())\n", + " else:\n", + " print(\"I do not understand what you mean. Type 'explore' or 'check'.\")\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\"])\n", + " play_image_room(image_relations_rooms[room[\"name\"]])\n", + " print(\"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", + "def check_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 check \" + item_name + \". \"\n", + " play_image_object(object_picture_relations[item_name]) ################important\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 the door with a key you have.\"\n", + " next_room = get_next_room_of_door(item, current_room)\n", + " else:\n", + " output += \"The door 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 new to find.\"\n", + " print(output)\n", + " break\n", + "\n", + " if(output is None):\n", + " print(\"The item you asked 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", + " play_room(next_room)\n", + " else:\n", + " play_room(current_room)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e71d49a8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "You wake up on a couch and find yourself in an abandoned house which you have never been to before. You don't remember why you are here and what had happened before. You so something and hope you are dreaming. You must get out of the house, NOW!\n", + "You are now in game room\n" + ] + } + ], + "source": [ + "game_state = INIT_GAME_STATE.copy()\n", + "\n", + "start_game()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ecb14a73", + "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.12" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/your-code/bedroom 1.jpg b/your-code/bedroom 1.jpg new file mode 100644 index 00000000..c04e3a6c Binary files /dev/null and b/your-code/bedroom 1.jpg differ diff --git a/your-code/bedroom 2.jpg b/your-code/bedroom 2.jpg new file mode 100644 index 00000000..0c99bf72 Binary files /dev/null and b/your-code/bedroom 2.jpg differ diff --git a/your-code/couch.jpg b/your-code/couch.jpg new file mode 100644 index 00000000..c52db279 Binary files /dev/null and b/your-code/couch.jpg differ diff --git a/your-code/dining table.jpg b/your-code/dining table.jpg new file mode 100644 index 00000000..70ddda23 Binary files /dev/null and b/your-code/dining table.jpg differ diff --git a/your-code/door a.jpg b/your-code/door a.jpg new file mode 100644 index 00000000..9abab443 Binary files /dev/null and b/your-code/door a.jpg differ diff --git a/your-code/door b.jpg b/your-code/door b.jpg new file mode 100644 index 00000000..5cf25c59 Binary files /dev/null and b/your-code/door b.jpg differ diff --git a/your-code/door c.jpg b/your-code/door c.jpg new file mode 100644 index 00000000..fff0f2c1 Binary files /dev/null and b/your-code/door c.jpg differ diff --git a/your-code/door d.jpg b/your-code/door d.jpg new file mode 100644 index 00000000..ac835d9f Binary files /dev/null and b/your-code/door d.jpg differ diff --git a/your-code/door1.jpg b/your-code/door1.jpg new file mode 100644 index 00000000..47fb36f5 Binary files /dev/null and b/your-code/door1.jpg differ diff --git a/your-code/door3.jpg b/your-code/door3.jpg new file mode 100644 index 00000000..516242bd Binary files /dev/null and b/your-code/door3.jpg differ diff --git a/your-code/double bed.jpg b/your-code/double bed.jpg new file mode 100644 index 00000000..0c99bf72 Binary files /dev/null and b/your-code/double bed.jpg differ diff --git a/your-code/dresser.jpg b/your-code/dresser.jpg new file mode 100644 index 00000000..976019ab Binary files /dev/null and b/your-code/dresser.jpg differ diff --git a/your-code/game room.jpg b/your-code/game room.jpg new file mode 100644 index 00000000..5889d55f Binary files /dev/null and b/your-code/game room.jpg differ diff --git a/your-code/game room5.jpg b/your-code/game room5.jpg new file mode 100644 index 00000000..d79dc732 Binary files /dev/null and b/your-code/game room5.jpg differ diff --git a/your-code/key a copy.jpg b/your-code/key a copy.jpg new file mode 100644 index 00000000..ceef8c40 Binary files /dev/null and b/your-code/key a copy.jpg differ diff --git a/your-code/key a.jpg b/your-code/key a.jpg new file mode 100644 index 00000000..ceef8c40 Binary files /dev/null and b/your-code/key a.jpg differ diff --git a/your-code/key b copy.jpg b/your-code/key b copy.jpg new file mode 100644 index 00000000..3dced7e7 Binary files /dev/null and b/your-code/key b copy.jpg differ diff --git a/your-code/key b.jpg b/your-code/key b.jpg new file mode 100644 index 00000000..3dced7e7 Binary files /dev/null and b/your-code/key b.jpg differ diff --git a/your-code/key c copy.jpg b/your-code/key c copy.jpg new file mode 100644 index 00000000..e71a1b95 Binary files /dev/null and b/your-code/key c copy.jpg differ diff --git a/your-code/key c.jpg b/your-code/key c.jpg new file mode 100644 index 00000000..e71a1b95 Binary files /dev/null and b/your-code/key c.jpg differ diff --git a/your-code/key d copy.jpg b/your-code/key d copy.jpg new file mode 100644 index 00000000..5f82edf6 Binary files /dev/null and b/your-code/key d copy.jpg differ diff --git a/your-code/key d.jpg b/your-code/key d.jpg new file mode 100644 index 00000000..5f82edf6 Binary files /dev/null and b/your-code/key d.jpg differ diff --git a/your-code/living room copy.jpg b/your-code/living room copy.jpg new file mode 100644 index 00000000..9253d536 Binary files /dev/null and b/your-code/living room copy.jpg differ diff --git a/your-code/living room.jpg b/your-code/living room.jpg new file mode 100644 index 00000000..9253d536 Binary files /dev/null and b/your-code/living room.jpg differ diff --git a/your-code/open game copy.jpg b/your-code/open game copy.jpg new file mode 100644 index 00000000..8fc631d0 Binary files /dev/null and b/your-code/open game copy.jpg differ diff --git a/your-code/open game.jpg b/your-code/open game.jpg new file mode 100644 index 00000000..8fc631d0 Binary files /dev/null and b/your-code/open game.jpg differ diff --git a/your-code/outside copy.jpg b/your-code/outside copy.jpg new file mode 100644 index 00000000..c11003d6 Binary files /dev/null and b/your-code/outside copy.jpg differ diff --git a/your-code/outside.jpg b/your-code/outside.jpg new file mode 100644 index 00000000..c11003d6 Binary files /dev/null and b/your-code/outside.jpg differ diff --git a/your-code/piano copy.jpg b/your-code/piano copy.jpg new file mode 100644 index 00000000..c81dedcb Binary files /dev/null and b/your-code/piano copy.jpg differ diff --git a/your-code/piano.jpg b/your-code/piano.jpg new file mode 100644 index 00000000..c81dedcb Binary files /dev/null and b/your-code/piano.jpg differ diff --git a/your-code/queen bed copy.jpg b/your-code/queen bed copy.jpg new file mode 100644 index 00000000..ddfa5ad8 Binary files /dev/null and b/your-code/queen bed copy.jpg differ diff --git a/your-code/queen bed.jpg b/your-code/queen bed.jpg new file mode 100644 index 00000000..ddfa5ad8 Binary files /dev/null and b/your-code/queen bed.jpg differ