Skip to content
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
386 changes: 386 additions & 0 deletions .ipynb_checkpoints/MVP - Elora final features-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,386 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"# Defining rooms\n",
"door_a = {\n",
" \"name\": \"door_a\",\n",
" \"type\": \"door\",\n",
"}\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",
"# Defining keys\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",
"# Defining items\n",
"couch = {\n",
" \"name\": \"couch\",\n",
" \"type\": \"furniture\",\n",
"}\n",
"\n",
"piano = {\n",
" \"name\": \"piano\",\n",
" \"type\": \"furniture\",\n",
"}\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",
"#rooms declaration: \n",
"game_room = {\n",
" \"name\": \"game_room\",\n",
" \"type\": \"room\",\n",
"}\n",
"\n",
"bedroom_1 = {\n",
" \"name\": \"bedroom_1\",\n",
" \"type\": \"room\",\n",
"}\n",
"bedroom_2 = {\n",
" \"name\": \"bedroom_2\",\n",
" \"type\": \"room\",\n",
"}\n",
"\n",
"livingroom = {\n",
" \"name\": \"livingroom\",\n",
" \"type\": \"room\",\n",
"}\n",
"outside = {\n",
" \"name\": \"outside\",\n",
" \"type\": \"room\",\n",
"}\n",
"\n",
"\n",
"# define which items/rooms are related\n",
"\n",
"object_relations = {\n",
" \"game_room\": [couch, piano, door_a],\n",
" \"bedroom_1\": [queen_bed, door_b, door_a, door_c],\n",
" \"bedroom_2\": [double_bed, dresser, door_b],\n",
" \"livingroom\": [dining_table, door_c, door_d],\n",
" \"outside\": [door_d],\n",
" \"door_a\": [game_room, bedroom_1],\n",
" \"door_b\": [bedroom_1, bedroom_2],\n",
" \"door_c\": [bedroom_1, livingroom],\n",
" \"door_d\": [livingroom, outside],\n",
" \"key_a\": [door_a],\n",
" \"key_b\": [door_b],\n",
" \"key_c\": [door_c],\n",
" \"key_d\": [door_d],\n",
" \"piano\": [key_a],\n",
" \"queen_bed\": [key_b],\n",
" \"double_bed\": [key_c],\n",
" \"dresser\": [key_d],\n",
" \"couch\": [],\n",
" \"dining_table\": [],\n",
"}\n",
"\n",
"# define game state. Do not directly change this dict. \n",
"# Instead, when a new game starts, make a copy of this\n",
"# dict and use the copy to store gameplay state. This \n",
"# way you can replay the game multiple times.\n",
"\n",
"INIT_GAME_STATE = {\n",
" \"current_room\": game_room,\n",
" \"keys_collected\": [],\n",
" \"target_room\": outside\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"def linebreak():\n",
" \"\"\"\n",
" Print a line break\n",
" \"\"\"\n",
" print(\"\\n\\n\")\n",
"\n",
"import time\n",
"import sys\n",
"\n",
"def start_countdown():\n",
" \"\"\"\n",
" Countdown before starting the game\n",
" \"\"\"\n",
" for x in range(3, 0, -1):\n",
" print(x)\n",
" time.sleep(1)\n",
" print(\"LET'S PLAY!\")\n",
" \n",
" # Play a beep sound\n",
" if sys.platform.startswith('win'):\n",
" import winsound\n",
" frequency = 1500\n",
" duration = 1500\n",
" winsound.Beep(frequency, duration)\n",
" \n",
"\n",
"def start_game():\n",
" \"\"\"\n",
" Start the game\n",
" \"\"\"\n",
" print(\"Welcome to your Escape Room!\"+\"\\U0001F525\") \n",
" player_name = input(\"Before we get started, what's your name? \")\n",
" print(f'Hello {player_name} !')\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",
" \n",
" # Start the timer\n",
" start_time = time.time()\n",
" \n",
" play_room(game_state[\"current_room\"], start_time)\n",
"\n",
"def play_room(room, start_time): \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",
" \n",
" # Calculate elapsed time\n",
" elapsed_time = int(time.time() - start_time)\n",
" print(f\"\\nElapsed Time: {elapsed_time} seconds\\n\")\n",
" \n",
" if(game_state[\"current_room\"] == game_state[\"target_room\"]):\n",
" print(\"Congrats! You escaped the room!\"+\"\\U0001F389\")\n",
" print(f\"Total Time: {elapsed_time} seconds\")\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",
" \n",
" if intended_action == \"explore\":\n",
" explore_room(room)\n",
" play_room(room, start_time) # Include start_time argument here\n",
" elif intended_action == \"examine\":\n",
" examine_item(input(\"What would you like to examine?\"+\"\\U0001F914\").strip(), start_time) # Pass start_time here\n",
" else:\n",
" print(\"Not sure what you mean. Type 'explore' or 'examine'.\")\n",
" play_room(room, start_time) # Include start_time argument here\n",
" \n",
" linebreak()\n",
"\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, start_time): # Pass start_time here\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\"+\"\\U0001F44F\"\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\"+\"\\U0001F622\"\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\"+\"\\U0001F644\"\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, start_time) # Include start_time argument here\n",
" else:\n",
" play_room(current_room, start_time) # Include start_time argument here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3\n",
"2\n",
"1\n",
"LET'S PLAY!\n",
"Welcome to your Escape Room!🔥\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"Before we get started, what's your name? Elora\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello Elora !\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",
"\n",
"Elapsed Time: 0 seconds\n",
"\n",
"You are now in game_room\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"What would you like to do? Type 'explore' or 'examine'? examine\n"
]
}
],
"source": [
"start_countdown()\n",
"\n",
"game_state = INIT_GAME_STATE.copy()\n",
"\n",
"start_game()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading