diff --git a/your-code/GHOST HOUSE.pdf b/your-code/GHOST HOUSE.pdf new file mode 100644 index 00000000..5e32faeb Binary files /dev/null and b/your-code/GHOST HOUSE.pdf differ diff --git a/your-code/Project_1.py b/your-code/Project_1.py new file mode 100644 index 00000000..cf60b953 --- /dev/null +++ b/your-code/Project_1.py @@ -0,0 +1,245 @@ +#!/usr/bin/env python +# coding: utf-8 + +# In[1]: + +from PIL import Image, ImageTk +import tkinter as tk +from time import sleep +import pygame as py + +#call sounds +def tocar_mp3(caminho): + + py.init() + py.mixer.init() + py.mixer.music.load(caminho) + py.mixer.music.play() + #sleep(10) + #py.mixer.music.stop() + +# tocar_mp3("music.mp3") + +#call images +bk = {"game room":"image1.png", + "bedroom 1":"image2.png", + "bedroom 2":"image3.png", + "living room":"image4.png", + "outside":"image5.png"} + +def house (background): + def fechar_janela(): + janela.after(3000, janela.destroy) + + imagem = Image.open(background) + + largura_desejada = 1200 + altura_desejada = 800 + imagem_redimensionada = imagem.resize((largura_desejada, altura_desejada)) + + janela = tk.Tk() + + imagem_tk = ImageTk.PhotoImage(imagem_redimensionada) + imagem_label = tk.Label(janela, image=imagem_tk) + imagem_label.pack() + + fechar_janela() + janela.mainloop() + + + + +# In[2]: + + +# define rooms and items +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"} + +couch = {"name": "couch", "type": "furniture"} +key_a = {"name": "key for door a", "type": "key", "target": door_a} +piano = {"name": "piano", "type": "furniture"} +game_room = {"name": "game room", "type": "room"} + +queen_bed = {"name":"queen bed", "type":"furniture"} +key_b = {"name": "key for door b", "type": "key", "target": door_b} +bedroom1 = {"name": "bedroom 1", "type": "room"} + +dining_table = {"name": "dining table", "type": "furniture"} +living_room = {"name": "living room", "type": "room"} + +double_bed = {"name":"double bed", "type":"furniture"} +dresser = {"name":"dresser", "type":"furniture"} +key_c = {"name": "key for door c", "type": "key", "target": door_c} +key_d = {"name": "key for door d", "type": "key", "target": door_d} +bedroom2 = {"name": "bedroom 2", "type": "room"} + +outside = {"name": "outside"} +all_rooms = [game_room, bedroom1, bedroom2, 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], + "piano": [key_a], + "outside": [door_d], + "door a": [game_room, bedroom1], + "door b": [bedroom1, bedroom2], + "door c": [bedroom1, living_room], + "door d": [living_room, outside], + "bedroom 1":[queen_bed, door_a, door_b, door_c], + "queen bed":[key_b], + "bedroom 2":[double_bed, dresser, door_b], + "double bed":[key_c], + "dresser":[key_d], + "living room":[dining_table, door_c, door_d] +} + +# 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[3]: + + +def linebreak(): + """ + Print a line break + """ + print("\n\n") + +def start_game(): + + """ + Start the game + """ + print("Prepare to enter a realm of darkness, where every step could be your last. As you find yourself surrounded by a haunting pile of bones, the eerie atmosphere engulfs you, sending shivers down your spine. Your mission? Escape this malevolent house of horrors before it consumes your very soul. You must get out IMMEDIATELY!") + 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("Congratulations! After a heart-pounding pursuit, you have successfully escaped the haunted house, leaving behind the bone-chilling terrors to be nothing more than a lingering memory. Well done!") + house(bk["outside"]) #image end game + tocar_mp3("end.mp3")#musica vitoria + sleep(10) + py.mixer.music.stop() #stop music + else: + print("You are now in " + room["name"]) + house(bk[room["name"]]) #images change room + intended_action = input("What would you like to do? Type 'explore' or 'examine'?").strip() + if intended_action == "explore": + explore_room(room) + play_room(room) + elif intended_action == "examine": + examine_item(input("What would you like to examine?").strip()) + else: + print("Not sure what you mean. Type 'explore' or 'examine'.") + play_room(room) + linebreak() + +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 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"] + "." + tocar_mp3("examine.mp3") #musica examinar + house("chave.png") #imagem chave + sleep(10) #tempo + tocar_mp3("music.mp3") #tocar musica + else: + output += "There isn't anything interesting about it." + tocar_mp3("examine.mp3") #musica examinar + house("fantasma.jpg") + sleep(10) + tocar_mp3("music.mp3") + 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'): + tocar_mp3("door.mp3") #musica abrir porta + house("porta.jpg") + sleep(10) + tocar_mp3("music.mp3") + play_room(next_room) + else: + play_room(current_room) + + +# In[4]: + + +game_state = INIT_GAME_STATE.copy() +tocar_mp3("music.mp3") +start_game() + + +# In[ ]: + + + + diff --git a/your-code/Project_1_Final.ipynb b/your-code/Project_1_Final.ipynb new file mode 100644 index 00000000..9c1fd481 --- /dev/null +++ b/your-code/Project_1_Final.ipynb @@ -0,0 +1,443 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "d7abf23e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "pygame 2.5.0 (SDL 2.28.0, Python 3.10.9)\n", + "Hello from the pygame community. https://www.pygame.org/contribute.html\n" + ] + } + ], + "source": [ + "from PIL import Image, ImageTk\n", + "import tkinter as tk\n", + "from time import sleep\n", + "import pygame as py\n", + "\n", + "#call sounds\n", + "def tocar_mp3(caminho):\n", + " \n", + " py.init()\n", + " py.mixer.init()\n", + " py.mixer.music.load(caminho)\n", + " py.mixer.music.play()\n", + " #sleep(10)\n", + " #py.mixer.music.stop()\n", + " \n", + "# tocar_mp3(\"music.mp3\")\n", + "\n", + "#call images\n", + "bk = {\"grand hall\":\"image1.png\",\n", + " \"trophy room\":\"image2.png\", \n", + " \"attic\":\"image3.png\", \n", + " \"dungeon\":\"image4.png\",\n", + " \"outside\":\"image5.png\"}\n", + "\n", + "def house (background):\n", + " def fechar_janela():\n", + " janela.after(3000, janela.destroy)\n", + "\n", + " imagem = Image.open(background)\n", + "\n", + " largura_desejada = 1200\n", + " altura_desejada = 800\n", + " imagem_redimensionada = imagem.resize((largura_desejada, altura_desejada))\n", + "\n", + " janela = tk.Tk()\n", + "\n", + " imagem_tk = ImageTk.PhotoImage(imagem_redimensionada)\n", + " imagem_label = tk.Label(janela, image=imagem_tk)\n", + " imagem_label.pack()\n", + "\n", + " fechar_janela()\n", + " janela.mainloop()\n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "88b9c46d", + "metadata": {}, + "outputs": [], + "source": [ + "# define rooms and items\n", + "door_a = {\"name\": \"door a\", \"type\": \"door\"}\n", + "door_b = {\"name\": \"door b\", \"type\": \"door\"}\n", + "door_c = {\"name\": \"door c\", \"type\": \"door\"}\n", + "door_d = {\"name\": \"door d\", \"type\": \"door\"}\n", + "\n", + "pile_of_bones = {\"name\": \"pile of bones\", \"type\": \"furniture\"}\n", + "key_a = {\"name\": \"key for door a\", \"type\": \"key\", \"target\": door_a}\n", + "piano = {\"name\": \"piano\", \"type\": \"furniture\"}\n", + "grand_hall = {\"name\": \"grand hall\", \"type\": \"room\"}\n", + "\n", + "deer_head = {\"name\":\"deer head\", \"type\":\"furniture\"}\n", + "key_b = {\"name\": \"key for door b\", \"type\": \"key\", \"target\": door_b}\n", + "trophy_room = {\"name\": \"trophy room\", \"type\": \"room\"}\n", + "\n", + "chainsaw = {\"name\": \"chainsaw\", \"type\": \"furniture\"}\n", + "dungeon = {\"name\": \"dungeon\", \"type\": \"room\"}\n", + "\n", + "dead_body = {\"name\":\"dead body\", \"type\":\"furniture\"}\n", + "coffin = {\"name\":\"coffin\", \"type\":\"furniture\"}\n", + "key_c = {\"name\": \"key for door c\", \"type\": \"key\", \"target\": door_c}\n", + "key_d = {\"name\": \"key for door d\", \"type\": \"key\", \"target\": door_d}\n", + "attic = {\"name\": \"attic\", \"type\": \"room\"}\n", + "\n", + "outside = {\"name\": \"outside\"}\n", + "all_rooms = [grand_hall, trophy_room, attic, dungeon, outside]\n", + "all_doors = [door_a, door_b, door_c, door_d]\n", + "\n", + "# define which items/rooms are related\n", + "\n", + "object_relations = {\n", + " \"grand hall\": [pile_of_bones, piano, door_a],\n", + " \"piano\": [key_a],\n", + " \"outside\": [door_d],\n", + " \"door a\": [grand_hall, trophy_room],\n", + " \"door b\": [trophy_room, attic],\n", + " \"door c\": [trophy_room, dungeon],\n", + " \"door d\": [dungeon, outside],\n", + " \"trophy room\":[deer_head, door_a, door_b, door_c],\n", + " \"deer head\":[key_b],\n", + " \"attic\":[dead_body, coffin, door_b],\n", + " \"dead body\":[key_c],\n", + " \"coffin\":[key_d],\n", + " \"dungeon\":[chainsaw, door_c, 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\": grand_hall,\n", + " \"keys_collected\": [],\n", + " \"target_room\": outside\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "bd1619da", + "metadata": {}, + "outputs": [], + "source": [ + "def linebreak():\n", + " \"\"\"\n", + " Print a line break\n", + " \"\"\"\n", + " print(\"\\n\\n\")\n", + "\n", + "def start_game():\n", + " \n", + " \"\"\"\n", + " Start the game\n", + " \"\"\"\n", + " print(\"Prepare to enter a realm of darkness, where every step could be your last. As you find yourself surrounded by a haunting pile of bones, the eerie atmosphere engulfs you, sending shivers down your spine. Your mission? Escape this malevolent house of horrors before it consumes your very soul. You must get out IMMEDIATELY!\")\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(\"Congratulations! After a heart-pounding pursuit, you have successfully escaped the haunted house, leaving behind the bone-chilling terrors to be nothing more than a lingering memory. Well done!\")\n", + " house(bk[\"outside\"]) #image end game\n", + " tocar_mp3(\"end.mp3\")#musica vitoria\n", + " sleep(5) \n", + " py.mixer.music.stop() #stop music\n", + " else:\n", + " print(\"You are now in \" + room[\"name\"])\n", + " house(bk[room[\"name\"]]) #images change room\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", + " tocar_mp3(\"examine.mp3\") #musica examinar\n", + " house(\"chave.png\") #imagem chave\n", + " sleep(5) #tempo\n", + " tocar_mp3(\"music.mp3\") #tocar musica\n", + " else:\n", + " output += \"There isn't anything interesting about it.\" \n", + " tocar_mp3(\"examine.mp3\") #musica examinar\n", + " house(\"fantasma.jpg\")\n", + " sleep(5)\n", + " tocar_mp3(\"music.mp3\") \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", + " tocar_mp3(\"door.mp3\") #musica abrir porta\n", + " house(\"porta.jpg\")\n", + " sleep(5)\n", + " tocar_mp3(\"music.mp3\")\n", + " play_room(next_room) \n", + " else:\n", + " play_room(current_room)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "1b249586", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Prepare to enter a realm of darkness, where every step could be your last. As you find yourself surrounded by a haunting pile of bones, the eerie atmosphere engulfs you, sending shivers down your spine. Your mission? Escape this malevolent house of horrors before it consumes your very soul. You must get out IMMEDIATELY!\n", + "You are now in grand hall\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 grand hall\n", + "What would you like to do? Type 'explore' or 'examine'?explore\n", + "You explore the room. This is grand hall. You find pile of bones, piano, door a\n", + "You are now in grand hall\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? Enter 'yes' or 'no'yes\n", + "You are now in trophy room\n", + "What would you like to do? Type 'explore' or 'examine'?explore\n", + "You explore the room. This is trophy room. You find deer head, door a, door b, door c\n", + "You are now in trophy room\n", + "What would you like to do? Type 'explore' or 'examine'?examine\n", + "What would you like to examine?deer head\n", + "You examine deer head. You find key for door b.\n", + "You are now in trophy room\n", + "What would you like to do? Type 'explore' or 'examine'?examine\n", + "What would you like to 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? Enter 'yes' or 'no'yes\n", + "You are now in attic\n", + "What would you like to do? Type 'explore' or 'examine'?explore\n", + "You explore the room. This is attic. You find dead body, coffin, door b\n", + "You are now in attic\n", + "What would you like to do? Type 'explore' or 'examine'?examine\n", + "What would you like to examine?dead body\n", + "You examine dead body. You find key for door c.\n", + "You are now in attic\n", + "What would you like to do? Type 'explore' or 'examine'?examine\n", + "What would you like to examine?coffin\n", + "You examine coffin. You find key for door d.\n", + "You are now in attic\n", + "What would you like to do? Type 'explore' or 'examine'?explore\n", + "You explore the room. This is attic. You find dead body, coffin, door b\n", + "You are now in attic\n", + "What would you like to do? Type 'explore' or 'examine'?explore\n", + "You explore the room. This is attic. You find dead body, coffin, door b\n", + "You are now in attic\n", + "What would you like to do? Type 'explore' or 'examine'?door b\n", + "Not sure what you mean. Type 'explore' or 'examine'.\n", + "You are now in attic\n", + "What would you like to do? Type 'explore' or 'examine'?explore\n", + "You explore the room. This is attic. You find dead body, coffin, door b\n", + "You are now in attic\n", + "What would you like to do? Type 'explore' or 'examine'?examine\n", + "What would you like to examine?dead body\n", + "You examine dead body. There isn't anything interesting about it.\n", + "You are now in attic\n", + "What would you like to do? Type 'explore' or 'examine'?examine\n", + "What would you like to examine?coffin\n", + "You examine coffin. There isn't anything interesting about it.\n", + "You are now in attic\n", + "What would you like to do? Type 'explore' or 'examine'?explore\n", + "You explore the room. This is attic. You find dead body, coffin, door b\n", + "You are now in attic\n", + "What would you like to do? Type 'explore' or 'examine'?examine\n", + "What would you like to 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? Enter 'yes' or 'no'yes\n", + "You are now in trophy room\n", + "What would you like to do? Type 'explore' or 'examine'?examine\n", + "What would you like to examine?door c\n", + "You examine door c. You unlock it with a key you have.\n", + "Do you want to go to the next room? Enter 'yes' or 'no'yes\n", + "You are now in dungeon\n", + "What would you like to do? Type 'explore' or 'examine'?examine\n", + "What would you like to examine?door d\n", + "You examine door d. You unlock it with a key you have.\n", + "Do you want to go to the next room? Enter 'yes' or 'no'yes\n", + "Congratulations! After a heart-pounding pursuit, you have successfully escaped the haunted house, leaving behind the bone-chilling terrors to be nothing more than a lingering memory. Well done!\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" + ] + } + ], + "source": [ + "game_state = INIT_GAME_STATE.copy()\n", + "tocar_mp3(\"music.mp3\")\n", + "start_game()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9ea4351b", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8d82fbb4", + "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.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/your-code/Project_1_Final_Group3.py b/your-code/Project_1_Final_Group3.py new file mode 100644 index 00000000..276fca96 --- /dev/null +++ b/your-code/Project_1_Final_Group3.py @@ -0,0 +1,252 @@ +#!/usr/bin/env python +# coding: utf-8 + +# In[1]: + + +from PIL import Image, ImageTk +import tkinter as tk +from time import sleep +import pygame as py + +#call sounds +def tocar_mp3(caminho): + + py.init() + py.mixer.init() + py.mixer.music.load(caminho) + py.mixer.music.play() + #sleep(10) + #py.mixer.music.stop() + +# tocar_mp3("music.mp3") + +#call images +bk = {"grand hall":"image1.png", + "trophy room":"image2.png", + "attic":"image3.png", + "dungeon":"image4.png", + "outside":"image5.png"} + +def house (background): + def fechar_janela(): + janela.after(3000, janela.destroy) + + imagem = Image.open(background) + + largura_desejada = 1200 + altura_desejada = 800 + imagem_redimensionada = imagem.resize((largura_desejada, altura_desejada)) + + janela = tk.Tk() + + imagem_tk = ImageTk.PhotoImage(imagem_redimensionada) + imagem_label = tk.Label(janela, image=imagem_tk) + imagem_label.pack() + + fechar_janela() + janela.mainloop() + + + + +# In[2]: + + +# define rooms and items +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"} + +pile_of_bones = {"name": "pile of bones", "type": "furniture"} +key_a = {"name": "key for door a", "type": "key", "target": door_a} +piano = {"name": "piano", "type": "furniture"} +grand_hall = {"name": "grand hall", "type": "room"} + +deer_head = {"name":"deer head", "type":"furniture"} +key_b = {"name": "key for door b", "type": "key", "target": door_b} +trophy_room = {"name": "trophy room", "type": "room"} + +chainsaw = {"name": "chainsaw", "type": "furniture"} +dungeon = {"name": "dungeon", "type": "room"} + +dead_body = {"name":"dead body", "type":"furniture"} +coffin = {"name":"coffin", "type":"furniture"} +key_c = {"name": "key for door c", "type": "key", "target": door_c} +key_d = {"name": "key for door d", "type": "key", "target": door_d} +attic = {"name": "attic", "type": "room"} + +outside = {"name": "outside"} +all_rooms = [grand_hall, trophy_room, attic, dungeon, outside] +all_doors = [door_a, door_b, door_c, door_d] + +# define which items/rooms are related + +object_relations = { + "grand hall": [pile_of_bones, piano, door_a], + "piano": [key_a], + "outside": [door_d], + "door a": [grand_hall, trophy_room], + "door b": [trophy_room, attic], + "door c": [trophy_room, dungeon], + "door d": [dungeon, outside], + "trophy room":[deer_head, door_a, door_b, door_c], + "deer head":[key_b], + "attic":[dead_body, coffin, door_b], + "dead body":[key_c], + "coffin":[key_d], + "dungeon":[chainsaw, door_c, door_d] +} + +# 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": grand_hall, + "keys_collected": [], + "target_room": outside +} + + +# In[3]: + + +def linebreak(): + """ + Print a line break + """ + print("\n\n") + +def start_game(): + + """ + Start the game + """ + print("Prepare to enter a realm of darkness, where every step could be your last. As you find yourself surrounded by a haunting pile of bones, the eerie atmosphere engulfs you, sending shivers down your spine. Your mission? Escape this malevolent house of horrors before it consumes your very soul. You must get out IMMEDIATELY!") + 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("Congratulations! After a heart-pounding pursuit, you have successfully escaped the haunted house, leaving behind the bone-chilling terrors to be nothing more than a lingering memory. Well done!") + house(bk["outside"]) #image end game + tocar_mp3("end.mp3")#musica vitoria + sleep(5) + py.mixer.music.stop() #stop music + else: + print("You are now in " + room["name"]) + house(bk[room["name"]]) #images change room + intended_action = input("What would you like to do? Type 'explore' or 'examine'?").strip() + if intended_action == "explore": + explore_room(room) + play_room(room) + elif intended_action == "examine": + examine_item(input("What would you like to examine?").strip()) + else: + print("Not sure what you mean. Type 'explore' or 'examine'.") + play_room(room) + linebreak() + +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 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"] + "." + tocar_mp3("examine.mp3") #musica examinar + house("chave.png") #imagem chave + sleep(5) #tempo + tocar_mp3("music.mp3") #tocar musica + else: + output += "There isn't anything interesting about it." + tocar_mp3("examine.mp3") #musica examinar + house("fantasma.jpg") + sleep(5) + tocar_mp3("music.mp3") + 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'): + tocar_mp3("door.mp3") #musica abrir porta + house("porta.jpg") + sleep(5) + tocar_mp3("music.mp3") + play_room(next_room) + else: + play_room(current_room) + + +# In[4]: + + +game_state = INIT_GAME_STATE.copy() +tocar_mp3("music.mp3") +start_game() + + +# In[ ]: + + + + + +# In[ ]: + + + + diff --git a/your-code/Project_1b.py b/your-code/Project_1b.py new file mode 100644 index 00000000..349917b5 --- /dev/null +++ b/your-code/Project_1b.py @@ -0,0 +1,252 @@ +#!/usr/bin/env python +# coding: utf-8 + +# In[1]: + + +from PIL import Image, ImageTk +import tkinter as tk +from time import sleep +import pygame as py + +#call sounds +def tocar_mp3(caminho): + + py.init() + py.mixer.init() + py.mixer.music.load(caminho) + py.mixer.music.play() + #sleep(10) + #py.mixer.music.stop() + +# tocar_mp3("music.mp3") + +#call images +bk = {"grand hall":"image1.png", + "trophy room":"image2.png", + "attic":"image3.png", + "dungeon":"image4.png", + "outside":"image5.png"} + +def house (background): + def fechar_janela(): + janela.after(3000, janela.destroy) + + imagem = Image.open(background) + + largura_desejada = 1200 + altura_desejada = 800 + imagem_redimensionada = imagem.resize((largura_desejada, altura_desejada)) + + janela = tk.Tk() + + imagem_tk = ImageTk.PhotoImage(imagem_redimensionada) + imagem_label = tk.Label(janela, image=imagem_tk) + imagem_label.pack() + + fechar_janela() + janela.mainloop() + + + + +# In[2]: + + +# define rooms and items +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"} + +pile_of_bones = {"name": "pile of bones", "type": "furniture"} +key_a = {"name": "key for door a", "type": "key", "target": door_a} +piano = {"name": "piano", "type": "furniture"} +grand_hall = {"name": "grand hall", "type": "room"} + +deer_head = {"name":"deer head", "type":"furniture"} +key_b = {"name": "key for door b", "type": "key", "target": door_b} +trophy_room = {"name": "trophy room", "type": "room"} + +chainsaw = {"name": "chainsaw", "type": "furniture"} +dungeon = {"name": "dungeon", "type": "room"} + +dead_body = {"name":"dead body", "type":"furniture"} +coffin = {"name":"coffin", "type":"furniture"} +key_c = {"name": "key for door c", "type": "key", "target": door_c} +key_d = {"name": "key for door d", "type": "key", "target": door_d} +attic = {"name": "attic", "type": "room"} + +outside = {"name": "outside"} +all_rooms = [grand_hall, trophy_room, attic, dungeon, outside] +all_doors = [door_a, door_b, door_c, door_d] + +# define which items/rooms are related + +object_relations = { + "grand hall": [pile_of_bones, piano, door_a], + "piano": [key_a], + "outside": [door_d], + "door a": [grand_hall, trophy_room], + "door b": [trophy_room, attic], + "door c": [trophy_room, dungeon], + "door d": [dungeon, outside], + "trophy room":[deer_head, door_a, door_b, door_c], + "deer head":[key_b], + "attic":[dead_body, coffin, door_b], + "dead body":[key_c], + "coffin":[key_d], + "dungeon":[chainsaw, door_c, door_d] +} + +# 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": grand_hall, + "keys_collected": [], + "target_room": outside +} + + +# In[3]: + + +def linebreak(): + """ + Print a line break + """ + print("\n\n") + +def start_game(): + + """ + Start the game + """ + print("Prepare to enter a realm of darkness, where every step could be your last. As you find yourself surrounded by a haunting pile of bones, the eerie atmosphere engulfs you, sending shivers down your spine. Your mission? Escape this malevolent house of horrors before it consumes your very soul. You must get out IMMEDIATELY!") + 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("Congratulations! After a heart-pounding pursuit, you have successfully escaped the haunted house, leaving behind the bone-chilling terrors to be nothing more than a lingering memory. Well done!") + house(bk["outside"]) #image end game + tocar_mp3("end.mp3")#musica vitoria + sleep(10) + py.mixer.music.stop() #stop music + else: + print("You are now in " + room["name"]) + house(bk[room["name"]]) #images change room + intended_action = input("What would you like to do? Type 'explore' or 'examine'?").strip() + if intended_action == "explore": + explore_room(room) + play_room(room) + elif intended_action == "examine": + examine_item(input("What would you like to examine?").strip()) + else: + print("Not sure what you mean. Type 'explore' or 'examine'.") + play_room(room) + linebreak() + +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 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"] + "." + tocar_mp3("examine.mp3") #musica examinar + house("chave.png") #imagem chave + sleep(10) #tempo + tocar_mp3("music.mp3") #tocar musica + else: + output += "There isn't anything interesting about it." + tocar_mp3("examine.mp3") #musica examinar + house("fantasma.jpg") + sleep(10) + tocar_mp3("music.mp3") + 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'): + tocar_mp3("door.mp3") #musica abrir porta + house("porta.jpg") + sleep(10) + tocar_mp3("music.mp3") + play_room(next_room) + else: + play_room(current_room) + + +# In[4]: + + +game_state = INIT_GAME_STATE.copy() +tocar_mp3("music.mp3") +start_game() + + +# In[ ]: + + + + + +# In[ ]: + + + + diff --git a/your-code/Untitled.ipynb b/your-code/Untitled.ipynb new file mode 100644 index 00000000..dfe2447b --- /dev/null +++ b/your-code/Untitled.ipynb @@ -0,0 +1,122 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "id": "11c41d29", + "metadata": {}, + "outputs": [], + "source": [ + "from time import sleep\n", + "import pygame as py\n", + "\n", + "def tocar_mp3(caminho):\n", + " \n", + " py.init()\n", + " py.mixer.init()\n", + " py.mixer.music.load(caminho)\n", + " py.mixer.music.play()\n", + " \n", + " # Pausar o programa por 1 minuto\n", + " sleep(10)\n", + "\n", + " # Parar a reprodução da música\n", + " py.mixer.music.stop()\n", + " \n", + "tocar_mp3(\"music.mp3\")" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "d699879e", + "metadata": {}, + "outputs": [], + "source": [ + "from time import sleep\n", + "import pygame as py\n", + "\n", + "def tocar_mp3(caminho):\n", + " \n", + " py.init()\n", + " py.mixer.init()\n", + " py.mixer.music.load(caminho)\n", + " py.mixer.music.play()\n", + " \n", + "tocar_mp3(\"music.mp3\")" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "bd581221", + "metadata": {}, + "outputs": [], + "source": [ + "py.mixer.music.stop()" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "589c9792", + "metadata": {}, + "outputs": [], + "source": [ + "import tkinter as tk\n", + "from tkinter import messagebox\n", + "\n", + "def exibir_popup():\n", + " janela = tk.Tk()\n", + " \n", + " # Função para lidar com o botão \"OK\"\n", + " def obter_dados():\n", + " texto = campo.get()\n", + " messagebox.showinfo(\"Mensagem\", \"Texto digitado: \" + texto)\n", + " janela.destroy()\n", + " \n", + " # Criar o campo de entrada e o botão \"OK\"\n", + " campo = tk.Entry(janela)\n", + " campo.pack()\n", + " \n", + " botao = tk.Button(janela, text=\"OK\", command=obter_dados)\n", + " botao.pack()\n", + " \n", + " # Exibir o popup\n", + " janela.mainloop()\n", + "\n", + "# Chamar a função para exibir o popup\n", + "exibir_popup()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6ad2b691", + "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.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/your-code/chave.png b/your-code/chave.png new file mode 100644 index 00000000..a87281e5 Binary files /dev/null and b/your-code/chave.png differ diff --git a/your-code/chave1.jpg b/your-code/chave1.jpg new file mode 100644 index 00000000..5ae9978b Binary files /dev/null and b/your-code/chave1.jpg differ diff --git a/your-code/door.mp3 b/your-code/door.mp3 new file mode 100644 index 00000000..87d795b4 Binary files /dev/null and b/your-code/door.mp3 differ diff --git a/your-code/end.mp3 b/your-code/end.mp3 new file mode 100644 index 00000000..525677dc Binary files /dev/null and b/your-code/end.mp3 differ diff --git a/your-code/examine.mp3 b/your-code/examine.mp3 new file mode 100644 index 00000000..01fbe79e Binary files /dev/null and b/your-code/examine.mp3 differ diff --git a/your-code/fantasma.jpg b/your-code/fantasma.jpg new file mode 100644 index 00000000..f9ceab62 Binary files /dev/null and b/your-code/fantasma.jpg differ diff --git a/your-code/image1.png b/your-code/image1.png new file mode 100644 index 00000000..94a03a9d Binary files /dev/null and b/your-code/image1.png differ diff --git a/your-code/image2.png b/your-code/image2.png new file mode 100644 index 00000000..b48ade0a Binary files /dev/null and b/your-code/image2.png differ diff --git a/your-code/image3.png b/your-code/image3.png new file mode 100644 index 00000000..f42a4ea2 Binary files /dev/null and b/your-code/image3.png differ diff --git a/your-code/image4.png b/your-code/image4.png new file mode 100644 index 00000000..0a2c9e41 Binary files /dev/null and b/your-code/image4.png differ diff --git a/your-code/image5.png b/your-code/image5.png new file mode 100644 index 00000000..1dbdc61e Binary files /dev/null and b/your-code/image5.png differ diff --git a/your-code/music.mp3 b/your-code/music.mp3 new file mode 100644 index 00000000..8e4a5965 Binary files /dev/null and b/your-code/music.mp3 differ diff --git a/your-code/porta.jpg b/your-code/porta.jpg new file mode 100644 index 00000000..2d2c42e5 Binary files /dev/null and b/your-code/porta.jpg differ diff --git a/your-code/sample-code.ipynb b/your-code/sample-code.ipynb deleted file mode 100644 index a6f8a94d..00000000 --- a/your-code/sample-code.ipynb +++ /dev/null @@ -1,248 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "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", - "\n", - "key_a = {\n", - " \"name\": \"key for door a\",\n", - " \"type\": \"key\",\n", - " \"target\": door_a,\n", - "}\n", - "\n", - "piano = {\n", - " \"name\": \"piano\",\n", - " \"type\": \"furniture\",\n", - "}\n", - "\n", - "game_room = {\n", - " \"name\": \"game room\",\n", - " \"type\": \"room\",\n", - "}\n", - "\n", - "outside = {\n", - " \"name\": \"outside\"\n", - "}\n", - "\n", - "all_rooms = [game_room, outside]\n", - "\n", - "all_doors = [door_a]\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", - "}\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, - "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(\"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'?\").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": 3, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "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" - ] - } - ], - "source": [ - "game_state = INIT_GAME_STATE.copy()\n", - "\n", - "start_game()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "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.7.2" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -}