diff --git a/README.md b/README.md index f6800627..cd3ec54f 100644 --- a/README.md +++ b/README.md @@ -1,135 +1,54 @@ Ironhack Logo -# Project: Escape Room Python Game +# Project: Surreal EscaPY ## Overview -The goal of this project is for you to apply the Python programming skills you have learned this week in solving a real problem. We present you the design of a classic game that can be played via text - Escape Room. Your goal is to develop the game using Python based on the game design. +If you happen to know [Zork I: The Great Underground Empire](https://en.wikipedia.org/wiki/Zork) ...congrats! (wow, you must be older than time :wink:). -Read the game narratives and technical requirements carefully. Plan how you will achieve your goal with pseudo codes and/or flowchart. Review the logic and process in order to avoid potential errors. Then implement with Python code. After that, test your code several times with different inputs and make sure it's rock solid. The instructional team is standing by to help you in case you run into any problems. +Text-based adventure games have inspired gaming development since 1977. Our goal for the first team project ([Aris Goulas](https://github.com/ArisGoulas), [Letícia De Marchi](https://github.com/leticiademarchiferreira), [Matheus Freire](https://github.com/MatheusFreir)) was to use our newly-acquired Python programming skills, in order to develop further the design of a classic game - _Escape Room_ that was provided to us. We therefore present you the **Surreal EscaPY**! --- ## Game Design -### Game Map - -![Game Map](escape-room-plan.jpg) - -### Game Narratives - -#### Game Room - -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! - -You are now in game room. - -What would you like to do? - -You explore the room. This is Game Room. You find couch, piano, and Door A. - -You examine couch. There isn't anything interesting about it. - -You examine Door A. It is locked but you don't have the key. - -You examine piano. You find key for Door A. - -You examine Door A. Your unlock it with a key you have. - -Do you want to go to the next room? - -#### Bedroom 1 - -You are now in Bedroom 1. - -What would you like to do? - -You explore the room. This is Bedroom 1. You find queen bed, Door A, Door B, and Door C. - -You examine queen bed. You find key for Door B. - -You examine Door C. It is locked but you don't have the key. - -You examine Door B. Your unlock it with a key you have. - -Do you want to go to the next room? - -#### Bedroom 2 - -You are now in Bedroom 2. - -What would you like to do? - -You explore the room. This is Bedroom 2. You find double bed, dresser, and Door B. +Our development consists of 3 (and a half) features: +- :fearful: Environment thematic customization: _surreal nightmare_ - personalization of the experience (MVP) +- :mag: _"check"_ action addition - gameplay (towards a future "inventory" feature) +- :repeat: Map layout _differentiation_ - replayability (towards a future map layout "randomization" feature and a "random spawn location" feature) +- :hourglass: Player name & _Timer_ introduction - gameplay (towards a future "scoreboard" feature and a "lose condition" feature) -You examine double bed. You find key for Door C. +The Python modules `time` and `random` were used, together with an implementation of an additional function (explore_self). -You examine dresser. You find key for Door D. - -You examine Door B. Your unlock it with a key you have. - -Do you want to go to the next room? - -#### Bedroom 1 - -You are now in Bedroom 1. - -What would you like to do? - -You examine Door C. Your unlock it with a key you have. - -Do you want to go to the next room? - -#### Living Room - -You are now in Living Room. - -What would you like to do? - -You explore the room. This is Living Room. You find dining table, Door C, and Door D. +### Game Map -You examine Door D. Your unlock it with a key you have. +![Game Map adapted](surreal-escapy-plan.jpg) -Do you want to go to the next room? +### Game Narratives -#### Outside +The player is asked to provide a name, and then the game starts in a specific room. They can utilize a menu of three **actions** ("explore", "check", or "examine") in order to advancer in the game: +- Explore: indicates the room they currently are, the furniture and the doors present +- Check: lists the keys that they have collected +- Examine: allows them to inspect furniture in order to find keys, and, if applied to doors while in presence of the respective key, grants access through the door (yes/no option) -Congrats! You escaped the room! +The customized rooms, furnitures, doors and keys that the player can encounter in the game are: +- 4+1 rooms: the room of insomnia, diamond room, the room of Alice, the room of reasoning, outside **(victory condition)** +- 6 furnitures: bed of nails, escritoire desk, steel chest, Red Queen bed, White Knight dresser, bag of problems +- 4 doors: veil of darkness, black hole, open mouth, arch of life +- 4 keys: candle-light, diamond, small pill , large pill **(random assignment)** --- -## Getting Started - -Overwhelmed and don't know where to start? This is a tough challenge we know. But don't worry. We have included a working example for you to reference in which only 1 room (game room) is included. Read the example and make sure you understand it. Then you can expand on top of the example to code the rest of the rooms. - -The provided example is just a Minimal Viable Product (MVP). It is fully functional but not bullet proof. You should be aware of its limitations while you are working and try to make your final product as robust as possible. - -## Technical Requirements - -* Use Python lists and dictionaries to define the rooms, items, and relations of them. - -* Use a Python dictionary to store the game state. Update the state dictionary when progresses are made such as a key is collected. - -* Use Python functions to play the game. Don't use procedural code. - -* After completing each game action, call the next function to continue playing until the winning condition is reached. - -* The winning condition is for the player to successfully make to the "Outside" room. When this happens, congrat the player and end the game. - -## Necessary Deliverables - -The following deliverables should be pushed to your Github repo. - -* `main.ipynb` that contains your solution. - -## Suggested Ways to Get Started - -1. Start Jupyter Notebook from this lab directory. +## How to play the Game -1. Launch `sample-code.ipynb` and read through the file. Also execute the code and play the game. Make sure you understand what each line of the codes does. +1. Clone this repo in your GitHub -1. Create `main.ipynb` and copy the codes from `sample-code.ipynb`. Expand the code following the example to create Bedroom 1. +2. Launch `surreal_escapy.py` (in command prompt, type `python surreal_escape.py`) -1. Test the game with Game Room and Bedroom 1. Make sure everything works then work on Bedroom 2 then Living Room. +3. If you enjoyed, you might want to ~~take a break~~ :sparkles: spur your nostalgia further :sparkles: by checking some of the (successors of text-based) classic point-and-click adventure PC games I grew up with: + - [Zak McKracken and the Alien Mindbenders](https://en.wikipedia.org/wiki/Zak_McKracken_and_the_Alien_Mindbenders) 1988 + - [KGB](https://en.wikipedia.org/wiki/KGB_(video_game)) 1992 + - [Gabriel Knight: Sins of the Fathers](https://en.wikipedia.org/wiki/Gabriel_Knight) 1993 + - [Simon the Sorcerer](https://en.wikipedia.org/wiki/Simon_the_Sorcerer) 1993 + - [Prisoner of Ice](https://en.wikipedia.org/wiki/Prisoner_of_Ice) 1995 -1. Test the whole game. Try to make all kinds of inputs to make sure your game is rock solid and will not break. diff --git a/surreal-escapy-plan.jpg b/surreal-escapy-plan.jpg new file mode 100644 index 00000000..89ae7f2c Binary files /dev/null and b/surreal-escapy-plan.jpg differ diff --git a/surreal-escapy.pptx b/surreal-escapy.pptx new file mode 100644 index 00000000..978e2dd8 Binary files /dev/null and b/surreal-escapy.pptx differ diff --git a/your-code/main.ipynb b/your-code/main.ipynb new file mode 100644 index 00000000..b633a055 --- /dev/null +++ b/your-code/main.ipynb @@ -0,0 +1,485 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 20, + "id": "0e7470bd", + "metadata": {}, + "outputs": [], + "source": [ + "# import modules\n", + "\n", + "import time\n", + "import random\n", + "\n", + "\n", + "# define rooms and items\n", + "\n", + "nails = {\n", + " \"name\": \"bed of nails\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "desk = {\n", + " \"name\": \"escritoire desk\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "veil = {\n", + " \"name\": \"veil of darkness\",\n", + " \"type\": \"door\",\n", + "}\n", + "\n", + "candle = {\n", + " \"name\": \"candle-light\",\n", + " \"type\": \"key\",\n", + " \"target\": veil,\n", + "}\n", + "\n", + "insomnia_room = {\n", + " \"name\": \"the room of insomnia\",\n", + " \"type\": \"room\",\n", + "}\n", + "\n", + "chest = {\n", + " \"name\": \"steel chest\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "hole = {\n", + " \"name\": \"black hole\",\n", + " \"type\": \"door\",\n", + "}\n", + "\n", + "mouth = {\n", + " \"name\": \"open mouth\",\n", + " \"type\": \"door\",\n", + "}\n", + "\n", + "diamond = {\n", + " \"name\": \"diamond\",\n", + " \"type\": \"key\",\n", + " \"target\": hole,\n", + "}\n", + "\n", + "diamond_room = {\n", + " \"name\": \"diamond room\",\n", + " \"type\": \"room\",\n", + "}\n", + "\n", + "rqbed = {\n", + " \"name\": \"Red Queen bed\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "wkdresser = {\n", + " \"name\": \"White Knight dresser\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "s_pill = {\n", + " \"name\": \"small pill\",\n", + " \"type\": \"key\",\n", + " \"target\": mouth,\n", + "}\n", + "\n", + "alice_room = {\n", + " \"name\": \"the room of Alice\",\n", + " \"type\": \"room\",\n", + "}\n", + "\n", + "bag = {\n", + " \"name\": \"bag of problems\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "arch = {\n", + " \"name\": \"arch of life\",\n", + " \"type\": \"door\",\n", + "}\n", + "\n", + "l_pill = {\n", + " \"name\": \"large pill\",\n", + " \"type\": \"key\",\n", + " \"target\": arch,\n", + "}\n", + "\n", + "reasoning_room = {\n", + " \"name\": \"the room of reasoning\",\n", + " \"type\": \"room\",\n", + "}\n", + "\n", + "outside = {\n", + " \"name\": \"outside\"\n", + "}\n", + "\n", + "all_rooms = [insomnia_room, diamond_room, alice_room, reasoning_room, outside]\n", + "\n", + "all_doors = [veil, hole, mouth, arch]\n", + "\n", + "\n", + "# define which items/rooms are related\n", + "\n", + "object_relations = {\n", + " \"the room of insomnia\": [nails, desk, veil],\n", + " \"bed of nails\": [],\n", + " \"escritoire desk\": [],\n", + " \"outside\": [arch],\n", + " \"veil of darkness\": [insomnia_room, diamond_room],\n", + " \"diamond room\": [chest, veil, hole, mouth],\n", + " \"steel chest\": [diamond],\n", + " \"black hole\": [diamond_room, alice_room],\n", + " \"the room of Alice\": [rqbed, wkdresser, hole],\n", + " \"Red Queen bed\": [],\n", + " \"White Knight dresser\": [],\n", + " \"open mouth\": [diamond_room, reasoning_room],\n", + " \"the room of reasoning\": [bag, arch],\n", + " \"arch of life\": [reasoning_room, outside],\n", + "}\n", + "\n", + "\n", + "# randomly assign the first key to either of the furniture of the room\n", + "# randomly assign the third to either of the furniture of the room\n", + "# assign the fourth key to the empty furniture of the room\n", + "\n", + "candle_location = random.choice([\"bed of nails\", \"escritoire desk\"])\n", + "object_relations[candle_location].append(candle)\n", + "\n", + "s_pill_location = random.choice([\"Red Queen bed\", \"White Knight dresser\"])\n", + "object_relations[s_pill_location].append(s_pill)\n", + "\n", + "if s_pill_location == \"Red Queen bed\":\n", + " l_pill_location = \"White Knight dresser\"\n", + "else:\n", + " l_pill_location = \"White Knight dresser\"\n", + "object_relations[l_pill_location].append(l_pill)\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\": insomnia_room,\n", + " \"keys_collected\": [],\n", + " \"target_room\": outside\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "89104b4f", + "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", + " Set a timer for start and end in order to give a message to the player of the time they wandered\n", + " \"\"\"\n", + " print(\"You needed to sleep but you couldn't take any sleep. Waking up on a bed of nails, you understand why. You decide to get up and struggle with the dark forces that lurk in the clear moonlight (there's no electricity and you can barely see, but somehow your senses feel...enhanced!). Deep inside you, you sense some unknown dangerous mental movement approaching and you feel an urge to run as far as possible NOW!\")\n", + " \n", + " start_time = time.time()\n", + " play_room(game_state[\"current_room\"])\n", + " end_time = time.time()\n", + "\n", + " print(player_name,\"you took\",end_time-start_time,\"to get out!!!\")\n", + " \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 (but you cannot escape yourself)!\")\n", + " else:\n", + " print(\"You are now in \" + room[\"name\"])\n", + " intended_action = input(\"What would you like to do? Type 'explore', 'check' or 'examine': \").strip()\n", + " if intended_action == \"explore\":\n", + " explore_room(room)\n", + " play_room(room)\n", + " elif intended_action == \"check\":\n", + " explore_self(game_state)\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. Perhaps drink a glass of water and then re-type 'explore', 'check' or 'examine'.\")\n", + " play_room(room)\n", + " linebreak()\n", + "\n", + "def explore_self(game_state):\n", + " \"\"\"\n", + " Check which keys the player has collected so far.\n", + " \"\"\"\n", + " keys_collected = game_state[\"keys_collected\"]\n", + " if not keys_collected:\n", + " print(\"You haven't collected anything yet. Empty pockets. You wonder why.\")\n", + " else:\n", + " print(\"You have collected the following bunch of weird stuff:\")\n", + " for key_obj in keys_collected:\n", + " print(key_obj[\"name\"])\n", + " return keys_collected \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 go through it using one of the bizarre objects you carry.\"\n", + " next_room = get_next_room_of_door(item, current_room)\n", + " else:\n", + " output += \"You can't go though no matter how hard you try. It would help if you had something to use as a 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 += \"Despite your continuous starring, there is nothing interesting about it. Move along!\"\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", + " play_room(next_room)\n", + " else:\n", + " play_room(current_room)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "fceac4f7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Please insert your name: aris\n", + "You needed to sleep but you couldn't take any sleep. Waking up on a bed of nails you understand why. You decide to get up and struggle with the dark forces that lurk in the clear moonlight (there's no electricity and you can barely see, but somehow your senses feel...enhanced!). Deep inside you, you sense some unknown dangerous mental movement approaching and you feel an urge to run as far as possible NOW!\n", + "You are now in the room of insomnia\n", + "What would you like to do? Type 'explore', 'check' or 'examine'?explore\n", + "You explore the room. This is the room of insomnia. You find bed of nails, escritoire desk, veil of darkness\n", + "You are now in the room of insomnia\n", + "What would you like to do? Type 'explore', 'check' or 'examine'?examine\n", + "What would you like to examine?bed of nails\n", + "You examine bed of nails. Despite your continuous starring, there is nothing interesting about it. Move along!\n", + "You are now in the room of insomnia\n", + "What would you like to do? Type 'explore', 'check' or 'examine'?examine\n", + "What would you like to examine?veil of darkness\n", + "You examine veil of darkness. You can't go though no matter how hard you try. It would help if you had something to use as a key...\n", + "You are now in the room of insomnia\n", + "What would you like to do? Type 'explore', 'check' or 'examine'?examine\n", + "What would you like to examine?escritoire desk\n", + "You examine escritoire desk. You find candle-light.\n", + "You are now in the room of insomnia\n", + "What would you like to do? Type 'explore', 'check' or 'examine'?examine \n", + "What would you like to examine?veil of darkness\n", + "You examine veil of darkness. You go through it using one of the bizarre objects you carry.\n", + "Do you want to go to the next room? Enter 'yes' or 'no'yes\n", + "You are now in diamond room\n", + "What would you like to do? Type 'explore', 'check' or 'examine'?explore\n", + "You explore the room. This is diamond room. You find steel chest, veil of darkness, black hole, open mouth\n", + "You are now in diamond room\n", + "What would you like to do? Type 'explore', 'check' or 'examine'?explore\n", + "You explore the room. This is diamond room. You find steel chest, veil of darkness, black hole, open mouth\n", + "You are now in diamond room\n", + "What would you like to do? Type 'explore', 'check' or 'examine'?examine\n", + "What would you like to examine?steel chest\n", + "You examine steel chest. You find diamond.\n", + "You are now in diamond room\n", + "What would you like to do? Type 'explore', 'check' or 'examine'?examine black hole\n", + "Not sure what you mean. Perhaps drink a glass of water and then re-type 'explore', 'check' or 'examine'.\n", + "You are now in diamond room\n", + "What would you like to do? Type 'explore', 'check' or 'examine'?examine\n", + "What would you like to examine?black hole\n", + "You examine black hole. You go through it using one of the bizarre objects you carry.\n", + "Do you want to go to the next room? Enter 'yes' or 'no'yes\n", + "You are now in the room of Alice\n", + "What would you like to do? Type 'explore', 'check' or 'examine'?explore\n", + "You explore the room. This is the room of Alice. You find Red Queen bed, White Knight dresser, black hole\n", + "You are now in the room of Alice\n", + "What would you like to do? Type 'explore', 'check' or 'examine'?examine\n", + "What would you like to examine?Red Queen bed\n", + "You examine Red Queen bed. You find small pill.\n", + "You are now in the room of Alice\n", + "What would you like to do? Type 'explore', 'check' or 'examine'?examine\n", + "What would you like to examine?White Knight dresser\n", + "You examine White Knight dresser. You find large pill.\n", + "You are now in the room of Alice\n", + "What would you like to do? Type 'explore', 'check' or 'examine'?examine\n", + "What would you like to examine?black hole\n", + "You examine black hole. You go through it using one of the bizarre objects you carry.\n", + "Do you want to go to the next room? Enter 'yes' or 'no'yes\n", + "You are now in diamond room\n", + "What would you like to do? Type 'explore', 'check' or 'examine'?explore\n", + "You explore the room. This is diamond room. You find steel chest, veil of darkness, black hole, open mouth\n", + "You are now in diamond room\n", + "What would you like to do? Type 'explore', 'check' or 'examine'?examine\n", + "What would you like to examine?open mouth\n", + "You examine open mouth. You go through it using one of the bizarre objects you carry.\n", + "Do you want to go to the next room? Enter 'yes' or 'no'yes\n", + "You are now in the room of reasoning\n", + "What would you like to do? Type 'explore', 'check' or 'examine'?explore\n", + "You explore the room. This is the room of reasoning. You find bag of problems, arch of life\n", + "You are now in the room of reasoning\n", + "What would you like to do? Type 'explore', 'check' or 'examine'?examine\n", + "What would you like to examine?bag of problems\n", + "You examine bag of problems. Despite your continuous starring, there is nothing interesting about it. Move along!\n", + "You are now in the room of reasoning\n", + "What would you like to do? Type 'explore', 'check' or 'examine'?examine\n", + "What would you like to examine?arch of life\n", + "You examine arch of life. You go through it using one of the bizarre objects you carry.\n", + "Do you want to go to the next room? Enter 'yes' or 'no'yes\n", + "Congrats! You escaped the room (but you cannot escape yourself)!\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "aris you took 246.5780577659607 to get out!!!\n", + "Congrats! You escaped the room (but you cannot escape yourself)!\n" + ] + } + ], + "source": [ + "game_state = INIT_GAME_STATE.copy()\n", + "player_name = input(\"Please insert your name: \")\n", + "start_game()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6ef11ea1", + "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.10.10" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/your-code/surreal_escapy.py b/your-code/surreal_escapy.py new file mode 100644 index 00000000..187b2ba7 --- /dev/null +++ b/your-code/surreal_escapy.py @@ -0,0 +1,301 @@ +#!/usr/bin/env python +# coding: utf-8 + +# In[20]: + + +# import modules + +import time +import random + +# define rooms and items + +nails = { + "name": "bed of nails", + "type": "furniture", +} + +desk = { + "name": "escritoire desk", + "type": "furniture", +} + +veil = { + "name": "veil of darkness", + "type": "door", +} + +candle = { + "name": "candle-light", + "type": "key", + "target": veil, +} + +insomnia_room = { + "name": "the room of insomnia", + "type": "room", +} + +chest = { + "name": "steel chest", + "type": "furniture", +} + +hole = { + "name": "black hole", + "type": "door", +} + +mouth = { + "name": "open mouth", + "type": "door", +} + +diamond = { + "name": "diamond", + "type": "key", + "target": hole, +} + +diamond_room = { + "name": "diamond room", + "type": "room", +} + +rqbed = { + "name": "Red Queen bed", + "type": "furniture", +} + +wkdresser = { + "name": "White Knight dresser", + "type": "furniture", +} + +s_pill = { + "name": "small pill", + "type": "key", + "target": mouth, +} + +alice_room = { + "name": "the room of Alice", + "type": "room", +} + +bag = { + "name": "bag of problems", + "type": "furniture", +} + +arch = { + "name": "arch of life", + "type": "door", +} + +l_pill = { + "name": "large pill", + "type": "key", + "target": arch, +} + +reasoning_room = { + "name": "the room of reasoning", + "type": "room", +} + +outside = { + "name": "outside" +} + +all_rooms = [insomnia_room, diamond_room, alice_room, reasoning_room, outside] + +all_doors = [veil, hole, mouth, arch] + +# define which items/rooms are related + +object_relations = { + "the room of insomnia": [nails, desk, veil], + "bed of nails": [], + "escritoire desk": [], + "outside": [arch], + "veil of darkness": [insomnia_room, diamond_room], + "diamond room": [chest, veil, hole, mouth], + "steel chest": [diamond], + "black hole": [diamond_room, alice_room], + "the room of Alice": [rqbed, wkdresser, hole], + "Red Queen bed": [], + "White Knight dresser": [], + "open mouth": [diamond_room, reasoning_room], + "the room of reasoning": [bag, arch], + "arch of life": [reasoning_room, outside], +} + +# randomly assign thr first key to either of the furniture of the room +# randomly assign the third to either of the furniture of the room +# assign the fourth key to the empty furniture of the room + +candle_location = random.choice(["bed of nails", "escritoire desk"]) +object_relations[candle_location].append(candle) + +s_pill_location = random.choice(["Red Queen bed", "White Knight dresser"]) +object_relations[s_pill_location].append(s_pill) + +if s_pill_location == "Red Queen bed": + l_pill_location = "White Knight dresser" +else: + l_pill_location = "White Knight dresser" +object_relations[l_pill_location].append(l_pill) + +# 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": insomnia_room, + "keys_collected": [], + "target_room": outside +} + + +# In[21]: + + +def linebreak(): + """ + Print a line break + """ + print("\n\n") + +def start_game(): + """ + Start the game + Set a timer for start and end in order to give a message to the player of the time they wandered + """ + print("You needed to sleep but you couldn't take any sleep. Waking up on a bed of nails, you understand why. You decide to get up and struggle with the dark forces that lurk in the clear moonlight (there's no electricity and you can barely see, but somehow your senses feel...enhanced!). Deep inside you, you sense some unknown dangerous mental movement approaching and you feel an urge to run as far as possible NOW!") + + start_time = time.time() + play_room(game_state["current_room"]) + end_time = time.time() + + print(player_name,"you took",end_time-start_time,"to get out!!!") + + 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 (but you cannot escape yourself)!") + else: + print("You are now in " + room["name"]) + intended_action = input("What would you like to do? Type 'explore', 'check' or 'examine': ").strip() + if intended_action == "explore": + explore_room(room) + play_room(room) + elif intended_action == "check": + explore_self(game_state) + play_room(room) + elif intended_action == "examine": + examine_item(input("What would you like to examine?").strip()) + else: + print("Not sure what you mean. Perhaps drink a glass of water and then re-type 'explore', 'check' or 'examine'.") + play_room(room) + linebreak() + +def explore_self(game_state): + """ + Check which keys the player has collected so far. + """ + keys_collected = game_state["keys_collected"] + if not keys_collected: + print("You haven't collected anything yet. Empty pockets. You wonder why.") + else: + print("You have collected the following bunch of weird stuff:") + for key_obj in keys_collected: + print(key_obj["name"]) + return keys_collected + +def explore_room(room): + """ + Explore a room. List all items belonging to this room. + """ + 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. + """ + 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 + + 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 go through it using one of the bizarre objects you carry." + next_room = get_next_room_of_door(item, current_room) + else: + output += "You can't go though no matter how hard you try. It would help if you had something to use as a 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 += "Despite your continuous starring, there is nothing interesting about it. Move along!" + 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? Enter 'yes' or 'no'").strip() == 'yes'): + play_room(next_room) + else: + play_room(current_room) + + +# In[22]: + + +game_state = INIT_GAME_STATE.copy() +player_name = input("Please insert your name: ") +start_game() + + +# In[ ]: + + + +