diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..9def1ac2 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..7c3f1de4 Binary files /dev/null and b/your-code/.DS_Store differ diff --git a/your-code/.ipynb_checkpoints/TheraPac-checkpoint.ipynb b/your-code/.ipynb_checkpoints/TheraPac-checkpoint.ipynb new file mode 100644 index 00000000..2c363d45 --- /dev/null +++ b/your-code/.ipynb_checkpoints/TheraPac-checkpoint.ipynb @@ -0,0 +1,368 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "dfef61fd", + "metadata": {}, + "outputs": [], + "source": [ + "# define rooms and items\n", + "import cv2\n", + "\n", + "couch = {\n", + " \"name\": \"couch\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\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", + "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", + "key_d = {\n", + " \"name\": \"key for door d\",\n", + " \"type\": \"key\",\n", + " \"target\": door_d,\n", + "}\n", + "piano = {\n", + " \"name\": \"piano\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "queen_bed = {\n", + " \"name\": \"queen bed\",\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", + "dinning_table = {\n", + " \"name\": \"dinning table\",\n", + " \"type\": \"furniture\",\n", + "}\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", + "living_room = {\n", + " \"name\": \"living room\",\n", + " \"type\": \"room\"\n", + "}\n", + "\n", + "outside = {\n", + " \"name\": \"outside\"\n", + "}\n", + "\n", + "all_rooms = [game_room, bedroom_1, bedroom_2,living_room, outside]\n", + "\n", + "all_doors = [door_a, door_b, door_c, door_d]\n", + "\n", + "# define which items/rooms are related\n", + "\n", + "object_relations = {\n", + " \"game room\": [couch, piano, door_a],\n", + " \"bedroom 1\": [door_a, door_b, door_c, queen_bed],\n", + " \"piano\": [key_a],\n", + " \"queen bed\": [key_b],\n", + " \"double bed\": [key_c],\n", + " \"dresser\": [key_d],\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", + " \"bedroom 2\": [dresser, double_bed,door_b],\n", + " \"living room\": [door_d, dinning_table , door_c]\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, + "id": "899fa697", + "metadata": {}, + "outputs": [], + "source": [ + "def linebreak():\n", + " \"\"\"\n", + " Print a line break\n", + " \"\"\"\n", + " print(\"\\n\\n\")\n", + " \n", + "def video ():\n", + " video_path = \"Presentation_Video.mp4\" \n", + " cap = cv2.VideoCapture(video_path)\n", + " print (\"Press Q to exit the video.\")\n", + " while cap.isOpened():\n", + " ret, frame = cap.read()\n", + " if not ret:\n", + " break\n", + "\n", + " cv2.imshow('Video Frame', frame)\n", + "\n", + " if cv2.waitKey(25) & 0xFF == ord('q'):\n", + " break\n", + "\n", + " cap.release()\n", + " cv2.destroyAllWindows()\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' followed by item name?\").strip()\n", + " if intended_action == \"explore\":\n", + " explore_room(room)\n", + " play_room(room)\n", + " # UPDATE: merging the examine from two steps into single input to make it easier\n", + " elif intended_action.find(\"examine \")== 0:\n", + " examine_item(intended_action[8:].strip())\n", + " else:\n", + " print(\"Not sure what you mean. Type 'explore' or 'examine' followed by item name.\")\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", + " # UPDATE: Checking to ensure object exists\n", + " if room[\"name\"] not in object_relations:\n", + " print(\"Something wrong with the game settings! Do something!\")\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", + " \n", + " # UPDATE: Checking to ensure object exists\n", + " if door[\"name\"] not in object_relations:\n", + " # returning empty string to mark it as not found\n", + " return \"\"\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", + " \n", + " \n", + " current_room = game_state[\"current_room\"]\n", + " next_room = \"\"\n", + " output = None\n", + " \n", + " #UPDATE: checking if room exists in the object relations\n", + " if current_room[\"name\"] not in object_relations:\n", + " print(\"Game settings are wrong! Aborting\")\n", + " linebreak()\n", + " return\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": null, + "id": "431bc958", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Press Q to exit the video.\n", + "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' followed by item name?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' followed by item name?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' followed by item name?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'y\n", + "You are now in game room\n" + ] + } + ], + "source": [ + "game_state = INIT_GAME_STATE.copy()\n", + "\n", + "video()\n", + "\n", + "start_game()\n", + "\n", + "\"\"\"\n", + "IMPROVEMENTS\n", + "============\n", + "\n", + "1. Merged the two steps needed for the 'examine' step, to be in single command,\n", + " so instead of writing 'examine' first, and then in another input to type\n", + " 'piano', you can now type 'examine piano' which is easier for the player.\n", + "\n", + "2. Added error checking to ensure object definitions are correct and the game\n", + " will not crash because of bad game settings, like forgetting to add items \n", + " to object_relations, etc.\n", + "\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "52d18dcf", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e2f1e28a", + "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.11.4" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/your-code/sample-code.ipynb b/your-code/.ipynb_checkpoints/sample-code-checkpoint.ipynb similarity index 66% rename from your-code/sample-code.ipynb rename to your-code/.ipynb_checkpoints/sample-code-checkpoint.ipynb index a6f8a94d..ce9e0c32 100644 --- a/your-code/sample-code.ipynb +++ b/your-code/.ipynb_checkpoints/sample-code-checkpoint.ipynb @@ -3,11 +3,16 @@ { "cell_type": "code", "execution_count": 1, - "metadata": {}, + "metadata": { + "id": "QYqC8zMgnRss" + }, "outputs": [], "source": [ + "\n", "# define rooms and items\n", "\n", + "import cv2\n", + "\n", "couch = {\n", " \"name\": \"couch\",\n", " \"type\": \"furniture\",\n", @@ -18,12 +23,46 @@ " \"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", "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", + "\n", "piano = {\n", " \"name\": \"piano\",\n", " \"type\": \"furniture\",\n", @@ -34,47 +73,102 @@ " \"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", + "queen_bed = {\n", + " \"name\": \"queen bed\",\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", + "dining_table = {\n", + " \"name\": \"dining table\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", "outside = {\n", " \"name\": \"outside\"\n", "}\n", "\n", - "all_rooms = [game_room, outside]\n", + "all_rooms = [game_room, bedroom_1, bedroom_2, living_room, outside]\n", "\n", - "all_doors = [door_a]\n", + "all_doors = [door_a, door_b, door_c, door_d]\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", + " \"door a\": [game_room, bedroom_1],\n", + " \"bedroom 1\": [queen_bed, door_a, door_b, door_c],\n", + " \"queen bed\": [key_b],\n", + " \"door b\": [bedroom_1, bedroom_2],\n", + " \"bedroom 2\" : [double_bed, dresser, door_b],\n", + " \"double bed\": [key_c],\n", + " \"dresser\": [key_d],\n", + " \"door c\": [bedroom_1, living_room],\n", + " \"living room\": [dining_table, door_c, door_d],\n", + " \"door d\": [living_room, outside],\n", + " \"outside\": [door_d],\n", "}\n", "\n", - "# define game state. Do not directly change this dict. \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", + "# 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": [ + "}\n", + "\n", "def linebreak():\n", " \"\"\"\n", " Print a line break\n", " \"\"\"\n", " print(\"\\n\\n\")\n", "\n", + "def video ():\n", + " video_path = \"RPReplay_Final1697145190.mp4\" # Replace with the actual path to your video file\n", + " cap = cv2.VideoCapture(video_path)\n", + " print (\"Press Q to exit the video.\")\n", + " while cap.isOpened():\n", + " ret, frame = cap.read()\n", + " if not ret:\n", + " break\n", + "\n", + " cv2.imshow('Video Frame', frame)\n", + "\n", + " if cv2.waitKey(25) & 0xFF == ord('q'):\n", + " break\n", + "\n", + " cap.release()\n", + " cv2.destroyAllWindows()\n", + "\n", + "\n", "def start_game():\n", " \"\"\"\n", " Start the game\n", @@ -85,12 +179,13 @@ "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", + " 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", + " exit()\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", @@ -125,7 +220,7 @@ " \"\"\"\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", + " 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", @@ -135,7 +230,7 @@ " current_room = game_state[\"current_room\"]\n", " next_room = \"\"\n", " output = None\n", - " \n", + "\n", " for item in object_relations[current_room[\"name\"]]:\n", " if(item[\"name\"] == item_name):\n", " output = \"You examine \" + item_name + \". \"\n", @@ -161,72 +256,87 @@ "\n", " if(output is None):\n", " print(\"The item you requested is not found in the current room.\")\n", - " \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)" + " play_room(current_room)\n" ] }, { "cell_type": "code", - "execution_count": 3, - "metadata": {}, + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "executionInfo": { + "elapsed": 226436, + "status": "ok", + "timestamp": 1697026396628, + "user": { + "displayName": "Miguel Mendes", + "userId": "14830331526419101904" + }, + "user_tz": -60 + }, + "id": "1KE_XEcunRsx", + "outputId": "93d3d2a2-29bd-4c6b-a5b1-01d9f2741d3f" + }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ + "Press Q to exit the video.\n", "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" + "You examine door a. You unlock it with a key you have.\n" ] } ], "source": [ "game_state = INIT_GAME_STATE.copy()\n", "\n", + "video ()\n", + "\n", "start_game()" ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "EhQ9OG6cnRsz" + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "t4YRXZSBnRsz" + }, "outputs": [], "source": [] } ], "metadata": { + "colab": { + "provenance": [] + }, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -240,9 +350,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.11.4" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 1 } diff --git a/your-code/.ipynb_checkpoints/sample-code2-checkpoint.ipynb b/your-code/.ipynb_checkpoints/sample-code2-checkpoint.ipynb new file mode 100644 index 00000000..8ac716b3 --- /dev/null +++ b/your-code/.ipynb_checkpoints/sample-code2-checkpoint.ipynb @@ -0,0 +1,348 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "id": "QYqC8zMgnRss" + }, + "outputs": [], + "source": [ + "\n", + "# define rooms and items\n", + "\n", + "import cv2\n", + "\n", + "couch = {\n", + " \"name\": \"couch\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\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", + "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", + "\n", + "piano = {\n", + " \"name\": \"piano\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\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", + "queen_bed = {\n", + " \"name\": \"queen bed\",\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", + "dining_table = {\n", + " \"name\": \"dining table\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "outside = {\n", + " \"name\": \"outside\"\n", + "}\n", + "\n", + "all_rooms = [game_room, bedroom_1, bedroom_2, living_room, outside]\n", + "\n", + "all_doors = [door_a, door_b, door_c, door_d]\n", + "\n", + "# define which items/rooms are related\n", + "\n", + "object_relations = {\n", + " \"game room\": [couch, piano, door_a],\n", + " \"piano\": [key_a],\n", + " \"door a\": [game_room, bedroom_1],\n", + " \"bedroom 1\": [queen_bed, door_a, door_b, door_c],\n", + " \"queen bed\": [key_b],\n", + " \"door b\": [bedroom_1, bedroom_2],\n", + " \"bedroom 2\" : [double_bed, dresser, door_b],\n", + " \"double bed\": [key_c],\n", + " \"dresser\": [key_d],\n", + " \"door c\": [bedroom_1, living_room],\n", + " \"living room\": [dining_table, door_c, door_d],\n", + " \"door d\": [living_room, outside],\n", + " \"outside\": [door_d],\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", + "\n", + "def linebreak():\n", + " \"\"\"\n", + " Print a line break\n", + " \"\"\"\n", + " print(\"\\n\\n\")\n", + "\n", + "def video ():\n", + " video_path = \"Presentation_Video.mp4\" \n", + " cap = cv2.VideoCapture(video_path)\n", + " print (\"Press Q to exit the video.\")\n", + " while cap.isOpened():\n", + " ret, frame = cap.read()\n", + " if not ret:\n", + " break\n", + "\n", + " cv2.imshow('Video Frame', frame)\n", + "\n", + " if cv2.waitKey(25) & 0xFF == ord('q'):\n", + " break\n", + "\n", + " cap.release()\n", + " cv2.destroyAllWindows()\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", + " exit()\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)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "executionInfo": { + "elapsed": 226436, + "status": "ok", + "timestamp": 1697026396628, + "user": { + "displayName": "Miguel Mendes", + "userId": "14830331526419101904" + }, + "user_tz": -60 + }, + "id": "1KE_XEcunRsx", + "outputId": "93d3d2a2-29bd-4c6b-a5b1-01d9f2741d3f" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Press Q to exit the video.\n", + "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" + ] + } + ], + "source": [ + "game_state = INIT_GAME_STATE.copy()\n", + "\n", + "video ()\n", + "\n", + "start_game()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "EhQ9OG6cnRsz" + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "t4YRXZSBnRsz" + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "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.11.4" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/your-code/Demo.mp4 b/your-code/Demo.mp4 new file mode 100644 index 00000000..2688b0cb Binary files /dev/null and b/your-code/Demo.mp4 differ diff --git a/your-code/Presentation_Video.mp4 b/your-code/Presentation_Video.mp4 new file mode 100644 index 00000000..3c8806f4 Binary files /dev/null and b/your-code/Presentation_Video.mp4 differ diff --git a/your-code/Readme_Therapac.md b/your-code/Readme_Therapac.md new file mode 100644 index 00000000..19605ab5 --- /dev/null +++ b/your-code/Readme_Therapac.md @@ -0,0 +1,19 @@ + +With the goal of creating a more reliable and interactive code, we made some modifications to the initial code. 'Therapac' is a mental health-promoting game designed to provide users with a therapeutic and engaging experience. We named it 'Therapac' to enhance its marketability. + +Next, we list the changes made: + + +- Defined multiple rooms (game_room, bedroom_1, bedroom_2, living_room, outside) and various furniture items (couch, piano, queen_bed, etc.). + +- Defined multiple doors (door_a, door_b, door_c, door_d) and corresponding keys (key_a, key_b, key_c, key_d). + +- Specified relationships between rooms, furniture, doors, and keys in the object_relations dictionary. + +- Added error checking to ensure object definitions are correct and the game will not crash because of bad game settings, like forgetting to add items to object_relations, etc. + + +- Merged the two steps needed for the 'examine' step, to be in single command, so instead of writing 'examine' first, and then in another input to type 'piano', you can now type 'examine piano' which is easier for the player. + + +- Used of the OpenCV library to display a video in the application and created a function to display a video. diff --git a/your-code/TheraPac.ipynb b/your-code/TheraPac.ipynb new file mode 100644 index 00000000..eadafa7f --- /dev/null +++ b/your-code/TheraPac.ipynb @@ -0,0 +1,402 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "dfef61fd", + "metadata": {}, + "outputs": [], + "source": [ + "# define rooms and items\n", + "import cv2\n", + "\n", + "couch = {\n", + " \"name\": \"couch\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\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", + "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", + "key_d = {\n", + " \"name\": \"key for door d\",\n", + " \"type\": \"key\",\n", + " \"target\": door_d,\n", + "}\n", + "piano = {\n", + " \"name\": \"piano\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "queen_bed = {\n", + " \"name\": \"queen bed\",\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", + "dinning_table = {\n", + " \"name\": \"dinning table\",\n", + " \"type\": \"furniture\",\n", + "}\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", + "living_room = {\n", + " \"name\": \"living room\",\n", + " \"type\": \"room\"\n", + "}\n", + "\n", + "outside = {\n", + " \"name\": \"outside\"\n", + "}\n", + "\n", + "all_rooms = [game_room, bedroom_1, bedroom_2,living_room, outside]\n", + "\n", + "all_doors = [door_a, door_b, door_c, door_d]\n", + "\n", + "# define which items/rooms are related\n", + "\n", + "object_relations = {\n", + " \"game room\": [couch, piano, door_a],\n", + " \"bedroom 1\": [door_a, door_b, door_c, queen_bed],\n", + " \"piano\": [key_a],\n", + " \"queen bed\": [key_b],\n", + " \"double bed\": [key_c],\n", + " \"dresser\": [key_d],\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", + " \"bedroom 2\": [dresser, double_bed,door_b],\n", + " \"living room\": [door_d, dinning_table , door_c]\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, + "id": "899fa697", + "metadata": {}, + "outputs": [], + "source": [ + "def linebreak():\n", + " \"\"\"\n", + " Print a line break\n", + " \"\"\"\n", + " print(\"\\n\\n\")\n", + " \n", + "def video ():\n", + " video_path = \"Presentation_Video.mp4\" \n", + " cap = cv2.VideoCapture(video_path)\n", + " print (\"Press Q to exit the video.\")\n", + " while cap.isOpened():\n", + " ret, frame = cap.read()\n", + " if not ret:\n", + " break\n", + "\n", + " cv2.imshow('Video Frame', frame)\n", + "\n", + " if cv2.waitKey(25) & 0xFF == ord('q'):\n", + " break\n", + "\n", + " cap.release()\n", + " cv2.destroyAllWindows()\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' followed by item name?\").strip()\n", + " if intended_action == \"explore\":\n", + " explore_room(room)\n", + " play_room(room)\n", + " # UPDATE: merging the examine from two steps into single input to make it easier\n", + " elif intended_action.find(\"examine \")== 0:\n", + " examine_item(intended_action[8:].strip())\n", + " else:\n", + " print(\"Not sure what you mean. Type 'explore' or 'examine' followed by item name.\")\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", + " # UPDATE: Checking to ensure object exists\n", + " if room[\"name\"] not in object_relations:\n", + " print(\"Something wrong with the game settings! Do something!\")\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", + " \n", + " # UPDATE: Checking to ensure object exists\n", + " if door[\"name\"] not in object_relations:\n", + " # returning empty string to mark it as not found\n", + " return \"\"\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", + " \n", + " \n", + " current_room = game_state[\"current_room\"]\n", + " next_room = \"\"\n", + " output = None\n", + " \n", + " #UPDATE: checking if room exists in the object relations\n", + " if current_room[\"name\"] not in object_relations:\n", + " print(\"Game settings are wrong! Aborting\")\n", + " linebreak()\n", + " return\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": null, + "id": "431bc958", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Press Q to exit the video.\n", + "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' followed by item name?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' followed by item name?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' followed by item name?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' followed by item name?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", + "You are now in bedroom 1\n", + "What would you like to do? Type 'explore' or 'examine' followed by item name?explore\n", + "You explore the room. This is bedroom 1. You find door a, door b, door c, queen bed\n", + "You are now in bedroom 1\n", + "What would you like to do? Type 'explore' or 'examine' followed by item name?examine queen bed\n", + "You examine queen bed. You find key for door b.\n", + "You are now in bedroom 1\n", + "What would you like to do? Type 'explore' or 'examine' followed by item name?examine door b\n", + "You examine door b. You unlock it with a key you have.\n", + "Do you want to go to the next room? Ener 'yes' or 'no'yes\n", + "You are now in bedroom 2\n", + "What would you like to do? Type 'explore' or 'examine' followed by item name?explore\n", + "You explore the room. This is bedroom 2. You find dresser, double bed, door b\n", + "You are now in bedroom 2\n", + "What would you like to do? Type 'explore' or 'examine' followed by item name?examine dresser\n", + "You examine dresser. You find key for door d.\n", + "You are now in bedroom 2\n", + "What would you like to do? Type 'explore' or 'examine' followed by item name?examine double bed\n", + "You examine double bed. You find key for door c.\n", + "You are now in bedroom 2\n", + "What would you like to do? Type 'explore' or 'examine' followed by item name?examine door b\n", + "You examine door b. You unlock it with a key you have.\n", + "Do you want to go to the next room? Ener 'yes' or 'no'yes\n", + "You are now in bedroom 1\n" + ] + } + ], + "source": [ + "game_state = INIT_GAME_STATE.copy()\n", + "\n", + "video()\n", + "\n", + "start_game()\n", + "\n", + "\"\"\"\n", + "IMPROVEMENTS\n", + "============\n", + "\n", + "1. Merged the two steps needed for the 'examine' step, to be in single command,\n", + " so instead of writing 'examine' first, and then in another input to type\n", + " 'piano', you can now type 'examine piano' which is easier for the player.\n", + "\n", + "2. Added error checking to ensure object definitions are correct and the game\n", + " will not crash because of bad game settings, like forgetting to add items \n", + " to object_relations, etc.\n", + "\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "52d18dcf", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e2f1e28a", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e222b701", + "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.11.4" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/your-code/TheraPac.pptx b/your-code/TheraPac.pptx new file mode 100644 index 00000000..c279495d Binary files /dev/null and b/your-code/TheraPac.pptx differ diff --git a/your-code/TheraPac.py b/your-code/TheraPac.py new file mode 100644 index 00000000..2cf78d85 --- /dev/null +++ b/your-code/TheraPac.py @@ -0,0 +1,315 @@ +#!/usr/bin/env python +# coding: utf-8 + +# In[ ]: + + +# define rooms and items +import cv2 + +couch = { + "name": "couch", + "type": "furniture", +} + +door_a = { + "name": "door a", + "type": "door", +} + +door_b = { + "name": "door b", + "type": "door", +} + +door_c = { + "name": "door c", + "type": "door", +} + +door_d= { + "name": "door d", + "type": "door", +} +key_a = { + "name": "key for door a", + "type": "key", + "target": door_a, +} + +key_b = { + "name": "key for door b", + "type": "key", + "target": door_b, +} + +key_c = { + "name": "key for door c", + "type": "key", + "target": door_c, +} +key_d = { + "name": "key for door d", + "type": "key", + "target": door_d, +} +piano = { + "name": "piano", + "type": "furniture", +} + +queen_bed = { + "name": "queen bed", + "type": "furniture", +} + +double_bed = { + "name": "double bed", + "type": "furniture", +} + +dresser = { + "name": "dresser", + "type": "furniture", +} + +dinning_table = { + "name": "dinning table", + "type": "furniture", +} +game_room = { + "name": "game room", + "type": "room", +} + +bedroom_1 = { + "name": "bedroom 1", + "type": "room" +} + +bedroom_2 = { + "name": "bedroom 2", + "type": "room" +} +living_room = { + "name": "living room", + "type": "room" +} + +outside = { + "name": "outside" +} + +all_rooms = [game_room, bedroom_1, bedroom_2,living_room, outside] + +all_doors = [door_a, door_b, door_c, door_d] + +# define which items/rooms are related + +object_relations = { + "game room": [couch, piano, door_a], + "bedroom 1": [door_a, door_b, door_c, queen_bed], + "piano": [key_a], + "queen bed": [key_b], + "double bed": [key_c], + "dresser": [key_d], + "outside": [door_d], + "door a": [game_room, bedroom_1], + "door b": [bedroom_1, bedroom_2], + "door c": [bedroom_1, living_room], + "door d": [living_room, outside], + "bedroom 2": [dresser, double_bed,door_b], + "living room": [door_d, dinning_table , door_c] +} + +# define game state. Do not directly change this dict. +# Instead, when a new game starts, make a copy of this +# dict and use the copy to store gameplay state. This +# way you can replay the game multiple times. + +INIT_GAME_STATE = { + "current_room": game_room, + "keys_collected": [], + "target_room": outside +} + + +# In[ ]: + + +def linebreak(): + """ + Print a line break + """ + print("\n\n") + +def video (): + video_path = "Presentation_Video.mp4" + cap = cv2.VideoCapture(video_path) + print ("Press Q to exit the video.") + while cap.isOpened(): + ret, frame = cap.read() + if not ret: + break + + cv2.imshow('Video Frame', frame) + + if cv2.waitKey(25) & 0xFF == ord('q'): + break + + cap.release() + cv2.destroyAllWindows() + + +def start_game(): + """ + Start the game + """ + 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!") + play_room(game_state["current_room"]) + +def play_room(room): + """ + Play a room. First check if the room being played is the target room. + If it is, the game will end with success. Otherwise, let player either + explore (list all items in this room) or examine an item found here. + """ + game_state["current_room"] = room + if(game_state["current_room"] == game_state["target_room"]): + print("Congrats! You escaped the room!") + else: + print("You are now in " + room["name"]) + intended_action = input("What would you like to do? Type 'explore' or 'examine' followed by item name?").strip() + if intended_action == "explore": + explore_room(room) + play_room(room) + # UPDATE: merging the examine from two steps into single input to make it easier + elif intended_action.find("examine ")== 0: + examine_item(intended_action[8:].strip()) + else: + print("Not sure what you mean. Type 'explore' or 'examine' followed by item name.") + play_room(room) + linebreak() + +def explore_room(room): + """ + Explore a room. List all items belonging to this room. + """ + # UPDATE: Checking to ensure object exists + if room["name"] not in object_relations: + print("Something wrong with the game settings! Do something!") + + items = [i["name"] for i in object_relations[room["name"]]] + print("You explore the room. This is " + room["name"] + ". You find " + ", ".join(items)) + +def get_next_room_of_door(door, current_room): + """ + From object_relations, find the two rooms connected to the given door. + Return the room that is not the current_room. + """ + + # UPDATE: Checking to ensure object exists + if door["name"] not in object_relations: + # returning empty string to mark it as not found + return "" + + connected_rooms = object_relations[door["name"]] + for room in connected_rooms: + if(not current_room == room): + return room + +def examine_item(item_name): + """ + Examine an item which can be a door or furniture. + First make sure the intended item belongs to the current room. + Then check if the item is a door. Tell player if key hasn't been + collected yet. Otherwise ask player if they want to go to the next + room. If the item is not a door, then check if it contains keys. + Collect the key if found and update the game state. At the end, + play either the current or the next room depending on the game state + to keep playing. + """ + + + current_room = game_state["current_room"] + next_room = "" + output = None + + #UPDATE: checking if room exists in the object relations + if current_room["name"] not in object_relations: + print("Game settings are wrong! Aborting") + linebreak() + return + + for item in object_relations[current_room["name"]]: + if(item["name"] == item_name): + output = "You examine " + item_name + ". " + if(item["type"] == "door"): + have_key = False + for key in game_state["keys_collected"]: + if(key["target"] == item): + have_key = True + if(have_key): + output += "You unlock it with a key you have." + next_room = get_next_room_of_door(item, current_room) + else: + output += "It is locked but you don't have the key." + else: + if(item["name"] in object_relations and len(object_relations[item["name"]])>0): + item_found = object_relations[item["name"]].pop() + game_state["keys_collected"].append(item_found) + output += "You find " + item_found["name"] + "." + else: + output += "There isn't anything interesting about it." + print(output) + break + + if(output is None): + print("The item you requested is not found in the current room.") + + if(next_room and input("Do you want to go to the next room? Ener 'yes' or 'no'").strip() == 'yes'): + play_room(next_room) + else: + play_room(current_room) + + +# In[ ]: + + +game_state = INIT_GAME_STATE.copy() + +video() + +start_game() + +""" +IMPROVEMENTS +============ + +1. Merged the two steps needed for the 'examine' step, to be in single command, + so instead of writing 'examine' first, and then in another input to type + 'piano', you can now type 'examine piano' which is easier for the player. + +2. Added error checking to ensure object definitions are correct and the game + will not crash because of bad game settings, like forgetting to add items + to object_relations, etc. +""" + + +# In[ ]: + + + + + +# In[ ]: + + + + + +# In[ ]: + + + +