Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python-project]MiqueleLucee #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
240 changes: 240 additions & 0 deletions your-code/.ipynb_checkpoints/Escape room-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"id": "fff55d05",
"metadata": {},
"outputs": [],
"source": [
"# define rooms and items\n",
"\n",
"couch = {\n",
" \"name\": \"couch\",\n",
" \"type\": \"furniture\",\n",
"}\n",
"\n",
"door_a = {\n",
" \"name\": \"door a\",\n",
" \"type\": \"door\",\n",
"}\n",
"book_1 = {\n",
" 'name': 'book1',\n",
" 'type': 'item',\n",
"}\n",
"\n",
"book_2 = {\n",
" 'name': 'book2',\n",
" 'type': 'item'\n",
"}\n",
"book_3 = {\n",
" 'name': 'book3',\n",
" 'type': 'item'\n",
"}\n",
"\n",
"spell = {\n",
" \"name\": \"key for door a\",\n",
" \"type\": \"key\",\n",
" \"target\": door_a,\n",
"}\n",
"\n",
"painting = {\n",
" \"name\": \"painting\",\n",
" \"type\": \"furniture\",\n",
"}\n",
"\n",
"book_shelve = {\n",
" 'name': 'book shelve',\n",
" 'type': 'furniture'\n",
"}\n",
"\n",
"\n",
"game_room = {\n",
" \"name\": \"Library\",\n",
" \"type\": \"room\",\n",
"}\n",
"\n",
"outside = {\n",
" \"name\": \"outside\"\n",
"}\n",
"\n",
"all_rooms = [game_room, outside]\n",
"\n",
"all_doors = [door_a]\n",
"\n",
"# define which items/rooms are related\n",
"\n",
"object_relations = {\n",
" \"Library\": [couch, book_shelve, painting, book_1, book_2, door_a],\n",
" \"book_3\": [spell],\n",
" \"outside\": [door_a],\n",
" \"door a\": [game_room, outside]\n",
"}\n",
"\n",
"# define game state. Do not directly change this dict. \n",
"# Instead, when a new game starts, make a copy of this\n",
"# dict and use the copy to store gameplay state. This \n",
"# way you can replay the game multiple times.\n",
"\n",
"INIT_GAME_STATE = {\n",
" \"current_room\": game_room,\n",
" \"keys_collected\": [],\n",
" \"target_room\": outside\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "5ddb7f9e",
"metadata": {},
"outputs": [],
"source": [
"def linebreak():\n",
" \"\"\"\n",
" Print a line break\n",
" \"\"\"\n",
" print(\"\\n\\n\")\n",
"\n",
"def start_game():\n",
" \"\"\"\n",
" Start the game\n",
" \"\"\"\n",
" print(\"As a Hogwarts student you are curious about the castle and its histories. However, when you touched a not common object, not to say weird, you were drawn to this completly dark room, where you can't see a thing in front of you. You remember that is almost time for your Defense against dark art class and Professor Snape doesn't like late students. You need to find a way out NOW or you will make your house loose points.\")\n",
" play_room(game_state[\"current_room\"])\n",
"\n",
"\n",
" \n",
"def light_the_room(room):\n",
" Lummus = input('You remember a spell to light the room and now is the perfect time to try it').strip()\n",
" if Lummus == 'Lummus':\n",
" print('Lummus spell worked. Professor Snape didnt believe you when you said you were concetrating, not sleeping')\n",
" else:\n",
" print('Try again.')\n",
" play_room(game_state[\"current_room\"])\n",
" \n",
"def play_room(room):\n",
" \"\"\"\n",
" Play a room. First check if the room being played is the target room.\n",
" If it is, the game will end with success. Otherwise, let player either \n",
" explore (list all items in this room) or examine an item found here.\n",
" \"\"\"\n",
" game_state[\"current_room\"] = room\n",
" if(game_state[\"current_room\"] == game_state[\"target_room\"]):\n",
" print(\"Congrats! You escaped the room!\")\n",
" else:\n",
" print(\"You are now in \" + room[\"name\"])\n",
" intended_action = input(\"What would you like to do? Type 'explore' or 'examine'?\").strip()\n",
" if intended_action == \"explore\":\n",
" explore_room(room)\n",
" play_room(room)\n",
" elif intended_action == \"examine\":\n",
" examine_item(input(\"What would you like to examine?\").strip())\n",
" else:\n",
" print(\"Not sure what you mean. Type 'explore' or 'examine'.\")\n",
" play_room(room)\n",
" linebreak()\n",
"\n",
"def explore_room(room):\n",
" \"\"\"\n",
" Explore a room. List all items belonging to this room.\n",
" \"\"\"\n",
" items = [i[\"name\"] for i in object_relations[room[\"name\"]]]\n",
" print(\"You explore the room. This is \" + room[\"name\"] + \". You find \" + \", \".join(items))\n",
"\n",
"def get_next_room_of_door(door, current_room):\n",
" \"\"\"\n",
" From object_relations, find the two rooms connected to the given door.\n",
" Return the room that is not the current_room.\n",
" \"\"\"\n",
" connected_rooms = object_relations[door[\"name\"]]\n",
" for room in connected_rooms:\n",
" if(not current_room == room):\n",
" return room\n",
"\n",
"def examine_item(item_name):\n",
" \"\"\"\n",
" Examine an item which can be a door or furniture.\n",
" First make sure the intended item belongs to the current room.\n",
" Then check if the item is a door. Tell player if key hasn't been \n",
" collected yet. Otherwise ask player if they want to go to the next\n",
" room. If the item is not a door, then check if it contains keys.\n",
" Collect the key if found and update the game state. At the end,\n",
" play either the current or the next room depending on the game state\n",
" to keep playing.\n",
" \"\"\"\n",
" current_room = game_state[\"current_room\"]\n",
" next_room = \"\"\n",
" output = None\n",
" \n",
" for item in object_relations[current_room[\"name\"]]:\n",
" if(item[\"name\"] == item_name):\n",
" output = \"You examine \" + item_name + \". \"\n",
" if(item[\"type\"] == \"door\"):\n",
" have_key = False\n",
" for key in game_state[\"keys_collected\"]:\n",
" if(key[\"target\"] == item):\n",
" have_key = True\n",
" if(have_key):\n",
" output += \"You unlock it with a key you have.\"\n",
" next_room = get_next_room_of_door(item, current_room)\n",
" else:\n",
" output += \"It is locked but you don't have the key.\"\n",
" else:\n",
" if(item[\"name\"] in object_relations and len(object_relations[item[\"name\"]])>0):\n",
" item_found = object_relations[item[\"name\"]].pop()\n",
" game_state[\"keys_collected\"].append(item_found)\n",
" output += \"You find \" + item_found[\"name\"] + \".\"\n",
" else:\n",
" output += \"There isn't anything interesting about it.\"\n",
" print(output)\n",
" break\n",
"\n",
" if(output is None):\n",
" print(\"The item you requested is not found in the current room.\")\n",
" \n",
" if(next_room and input(\"Do you want to go to the next room? Ener 'yes' or 'no'\").strip() == 'yes'):\n",
" play_room(next_room)\n",
" else:\n",
" play_room(current_room)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a7ea7b4e",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "4649f086",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
6 changes: 6 additions & 0 deletions your-code/.ipynb_checkpoints/Untitled-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
6 changes: 6 additions & 0 deletions your-code/.ipynb_checkpoints/Untitled1-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
6 changes: 6 additions & 0 deletions your-code/.ipynb_checkpoints/Untitled2-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
Loading