From cddbb2886ee26cb61e79c6b073c3f175d0fa4b44 Mon Sep 17 00:00:00 2001 From: Mattia Lobascio Date: Fri, 25 Oct 2019 11:57:25 +0100 Subject: [PATCH 1/3] dice item and master key working --- .../.ipynb_checkpoints/main-checkpoint.ipynb | 16 ++- your-code/main.ipynb | 132 +++--------------- 2 files changed, 34 insertions(+), 114 deletions(-) diff --git a/your-code/.ipynb_checkpoints/main-checkpoint.ipynb b/your-code/.ipynb_checkpoints/main-checkpoint.ipynb index a0050117..87e1322b 100644 --- a/your-code/.ipynb_checkpoints/main-checkpoint.ipynb +++ b/your-code/.ipynb_checkpoints/main-checkpoint.ipynb @@ -124,6 +124,17 @@ " \"target\": door_d,\n", "}\n", "\n", + "master_key = {\n", + " \"name\": \"master key\",\n", + " \"type\": \"key\",\n", + " \"target\": \"all\",\n", + "}\n", + "\n", + "dice = {\n", + " \"name\": \"dice\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", "all_rooms = [game_room, bedroom1, bedroom2, living, outside]\n", "\n", "all_doors = [door_a, door_b, door_c, door_d]\n", @@ -131,7 +142,7 @@ "# define which items/rooms are related\n", "\n", "object_relations = {\n", - " \"game room\": [couch, piano, door_a],\n", + " \"game room\": [couch, piano, door_a, dice],\n", " \"piano\": [key_a],\n", " \"outside\": [door_d],\n", " \"door a\": [game_room, bedroom1],\n", @@ -144,6 +155,7 @@ " \"double bed\": [key_c],\n", " \"bedroom 2\": [dresser,doublebed,door_b],\n", " \"living room\": [table,door_d,door_c],\n", + " \"dice\" : [master_key]\n", "}\n", "\n", "# define game state. Do not directly change this dict. \n", @@ -258,7 +270,7 @@ " if(item[\"type\"] == \"door\"):\n", " have_key = False\n", " for key in game_state[\"keys_collected\"]:\n", - " if(key[\"target\"] == item):\n", + " if(key[\"target\"] == item or key[\"target\"]==\"all\"):\n", " have_key = True\n", " if(have_key):\n", " output += color.YELLOW + \"You unlock it with a key you have.\" + color.END\n", diff --git a/your-code/main.ipynb b/your-code/main.ipynb index a0050117..64e85073 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -124,6 +124,17 @@ " \"target\": door_d,\n", "}\n", "\n", + "master_key = {\n", + " \"name\": \"master key\",\n", + " \"type\": \"key\",\n", + " \"target\": \"all\",\n", + "}\n", + "\n", + "dice = {\n", + " \"name\": \"dice\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", "all_rooms = [game_room, bedroom1, bedroom2, living, outside]\n", "\n", "all_doors = [door_a, door_b, door_c, door_d]\n", @@ -131,7 +142,7 @@ "# define which items/rooms are related\n", "\n", "object_relations = {\n", - " \"game room\": [couch, piano, door_a],\n", + " \"game room\": [couch, piano, door_a, dice],\n", " \"piano\": [key_a],\n", " \"outside\": [door_d],\n", " \"door a\": [game_room, bedroom1],\n", @@ -144,6 +155,7 @@ " \"double bed\": [key_c],\n", " \"bedroom 2\": [dresser,doublebed,door_b],\n", " \"living room\": [table,door_d,door_c],\n", + " \"dice\" : [master_key]\n", "}\n", "\n", "# define game state. Do not directly change this dict. \n", @@ -160,7 +172,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -258,7 +270,7 @@ " if(item[\"type\"] == \"door\"):\n", " have_key = False\n", " for key in game_state[\"keys_collected\"]:\n", - " if(key[\"target\"] == item):\n", + " if(key[\"target\"] == item or key[\"target\"]==\"all\"):\n", " have_key = True\n", " if(have_key):\n", " output += color.YELLOW + \"You unlock it with a key you have.\" + color.END\n", @@ -291,119 +303,15 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[91m\u001b[1mYou 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, but you suddenly hear a terrifying scream coming from the floor below your feet... You must get out of here, NOW!\u001b[0m\n", - "00:00\n", - "\u001b[36m\u001b[1m\n", - "Current Room: GAME ROOM\u001b[0m\n", - "\n", - "Type '1' to EXPLORE the room OR type '2' to EXAMINE an object! 1\n", - "\u001b[1m\n", - "You EXPLORE the room and you FIND: \u001b[94m\u001b[4mCOUCH, PIANO, DOOR A\u001b[0m\n", - "\u001b[36m\u001b[1m\n", - "Current Room: GAME ROOM\u001b[0m\n", - "\n", - "Type '1' to EXPLORE the room OR type '2' to EXAMINE an object! 2\n", - "\n", - "What would you like to EXAMINE? piano\n", - "\n", - "\u001b[1mYou examine PIANO. \u001b[0m\u001b[93m\u001b[1mYou FOUND KEY for Door A.\u001b[0m\n", - "\u001b[1m\n", - "You are still in the same room... AND THE CLOCK IS TICKING!\u001b[0m\n", - "\u001b[36m\u001b[1m\n", - "Current Room: GAME ROOM\u001b[0m\n", - "\n", - "Type '1' to EXPLORE the room OR type '2' to EXAMINE an object! 2\n", - "\n", - "What would you like to EXAMINE? door a\n", - "\n", - "\u001b[1mYou examine DOOR A. \u001b[0m\u001b[92mYou unlock it with a key you have.\u001b[0m\n", - "\n", - "Type 'YES' if you want to move to the next room, press ENTER otherwise: YES\n", - "\u001b[36m\u001b[1m\n", - "Current Room: BEDROOM 1\u001b[0m\n", - "\n", - "Type '1' to EXPLORE the room OR type '2' to EXAMINE an object! 1\n", - "\u001b[1m\n", - "You EXPLORE the room and you FIND: \u001b[94m\u001b[4mQUEEN BED, DOOR A, DOOR B, DOOR C\u001b[0m\n", - "\u001b[36m\u001b[1m\n", - "Current Room: BEDROOM 1\u001b[0m\n" - ] - } - ], - "source": [ - "game_state = INIT_GAME_STATE.copy()\n", - "\n", - "start_game()" - ] - }, - { - "cell_type": "code", - "execution_count": 15, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "00:00\n" - ] - }, - { - "data": { - "text/plain": [ - "'00:00'" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def countdown(t=10):\n", - " while t != 0:\n", - " mins, secs = divmod(t, 60)\n", - " timeformat = \"{:02d}:{:02d}\".format(mins, secs)\n", - " print(timeformat, end=\"\\r\")\n", - " time.sleep(1)\n", - " t -= 1\n", - " timeformat = \"{:02d}:{:02d}\".format(0,0)\n", - " print(timeformat)\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "00:00\n", - "00:00\n" - ] - } - ], + "outputs": [], "source": [ - "print(countdown())" + "game_state = INIT_GAME_STATE.copy()\n", + "\n", + "start_game()" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { From 59d944d772c92e105db2a68f307a3e4551f2d988 Mon Sep 17 00:00:00 2001 From: Mattia Lobascio Date: Fri, 25 Oct 2019 15:12:20 +0100 Subject: [PATCH 2/3] Final version including dice game --- .../Dice_game-checkpoint.ipynb | 109 +++++++++++ .../.ipynb_checkpoints/main-checkpoint.ipynb | 178 +++++------------- your-code/Dice_game.ipynb | 109 +++++++++++ your-code/main.ipynb | 62 ++++-- 4 files changed, 316 insertions(+), 142 deletions(-) create mode 100644 your-code/.ipynb_checkpoints/Dice_game-checkpoint.ipynb create mode 100644 your-code/Dice_game.ipynb diff --git a/your-code/.ipynb_checkpoints/Dice_game-checkpoint.ipynb b/your-code/.ipynb_checkpoints/Dice_game-checkpoint.ipynb new file mode 100644 index 00000000..83274c98 --- /dev/null +++ b/your-code/.ipynb_checkpoints/Dice_game-checkpoint.ipynb @@ -0,0 +1,109 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "import random\n", + "import time\n" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "You found a dice! If you roll the dice and get an even number you get the masterkey to escape from the scary house.\n", + "Are you ready?\n", + "00:00\n", + "You rolled number 5 you didn't escape by rolling the dice -_-'\n" + ] + }, + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#Describes setting and initiate g# your code\n", + "def countdown(t=10):\n", + " while t != 0:\n", + " mins, secs = divmod(t, 60)\n", + " timeformat = \"{:02d}:{:02d}\".format(mins, secs)\n", + " print(timeformat, end=\"\\r\")\n", + " time.sleep(1)\n", + " t -= 1\n", + " timeformat = \"{:02d}:{:02d}\".format(0,0)\n", + " print(timeformat)\n", + "\n", + "\n", + "### dice game!\n", + "def dice_game():\n", + " \"\"\"\n", + " Roll the dice\n", + " \"\"\"\n", + " print(\"You found a dice! If you roll the dice and get an even number you get the masterkey to escape from the scary house.\")\n", + " print(\"Are you ready?\")\n", + " time.sleep(1)\n", + " countdown(3)\n", + " rolled_num = random.randint(1,18)\n", + " if rolled_num % 2 == 0:\n", + " print(\"Congratulations, you rolled \", rolled_num, \" and thus you the master key!\")\n", + " return True \n", + " else:\n", + " print(\"You rolled number\", rolled_num,\"you didn't escape by rolling the dice -_-'\")\n", + " return False\n", + " \n", + " \n", + "dice_game()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "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.6.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/your-code/.ipynb_checkpoints/main-checkpoint.ipynb b/your-code/.ipynb_checkpoints/main-checkpoint.ipynb index 87e1322b..0016d28e 100644 --- a/your-code/.ipynb_checkpoints/main-checkpoint.ipynb +++ b/your-code/.ipynb_checkpoints/main-checkpoint.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -11,7 +11,7 @@ "import time\n", "\n", "#Define classes\n", - "\n", + "#Classes of colours for DARK background\n", "class color:\n", " PURP = '\\033[36m'\n", " BLUE = '\\033[94m'\n", @@ -172,7 +172,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -185,25 +185,45 @@ " \"\"\"\n", " print(\"\\n\\n\")\n", "\n", - "#Describes setting and initiate g# your code\n", - "def countdown(t=10):\n", + "#Prints a countdown timer for the beginnig of the game:\n", + "def countdown(t=3):\n", " while t != 0:\n", " mins, secs = divmod(t, 60)\n", " timeformat = \"{:02d}:{:02d}\".format(mins, secs)\n", - " print(timeformat, end=\"\\r\")\n", + " print(color.RED + color.BOLD + timeformat + color.END, end=\"\\r\")\n", " time.sleep(1)\n", " t -= 1\n", " timeformat = \"{:02d}:{:02d}\".format(0,0)\n", - " print(timeformat)\n", - "\n", - "\n", + " print(color.RED + color.BOLD + timeformat + color.END)\n", + " \n", "\n", + "#Defines the outcomes of rolling the dice, which can lead to obtain master key\n", + "def dice_game(faces = 18):\n", + " \"\"\"\n", + " Roll the dice\n", + " \"\"\"\n", + " usr_choice = input(color.RED + \"\\nIt does not look like a normal dice...\" + color.BOLD + \"Type 'YES' if you want to roll it, press ENTER otherwise: \").strip().lower()\n", + " if usr_choice == \"yes\":\n", + " #print(color.RED + color-BOLD + \"The mystery dice is rolling\" + color.END)\n", + " time.sleep(3)\n", + " rolled_num = random.randint(1,faces)\n", + " if rolled_num % 2 == 0:\n", + " print(color.YELLOW + \"\\nThe outcome is \", rolled_num, \" ...WOW a shiny golden key appeared out of nowere!\" + color.END)\n", + " return True \n", + " else:\n", + " print(color.BOLD + \"\\nThe outcome is \", rolled_num, \" ...Maybe you should roll it again...\"+color.END)\n", + " return False\n", + " else:\n", + " print(color.RED + \"\\nAren't you curious?\" + color.END)\n", + " return False\n", + " \n", + "#Describes setting and initiate g# your code\n", "def start_game():\n", " \"\"\"\n", " Start the game\n", " \"\"\"\n", " print(color.RED+color.BOLD+\"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, but you suddenly hear a terrifying scream coming from the floor below your feet... You must get out of here, NOW!\"+color.END)\n", - " countdown()\n", + " time=countdown()\n", " play_room(game_state[\"current_room\"])\n", " \n", "\n", @@ -215,7 +235,7 @@ " \"\"\"\n", " game_state[\"current_room\"] = room\n", " if(game_state[\"current_room\"] == game_state[\"target_room\"]):\n", - " time.sleep(4)\n", + " time.sleep(3)\n", " print(color.YELLOW + color.BOLD + \"\\nCONGRATS! YOU ESCAPED FROM AN ATROCIOUS DEATH!\" + color.END)\n", " else:\n", " print(color.PURP + color.BOLD + \"\\nCurrent Room: \" + room[\"name\"].upper() + color.END)\n", @@ -235,7 +255,7 @@ " Explore a room. List all items belonging to this room.\n", " \"\"\"\n", " items = [i[\"name\"] for i in object_relations[room[\"name\"]]]\n", - " time.sleep(2)\n", + " time.sleep(1)\n", " print(color.BOLD+\"\\nYou EXPLORE the room and you FIND: \"+color.BLUE+color.UNDER+\", \".join(items).upper() + color.END)\n", " #This is \" + room[\"name\"].upper()\n", " \n", @@ -266,10 +286,11 @@ " \n", " for item in object_relations[current_room[\"name\"]]:\n", " if(item[\"name\"] == item_name):\n", - " output = color.BOLD + \"You examine \" + item_name.upper() + \". \" + color.END\n", + " output = color.BOLD + \"You examined \" + item_name.upper() + \". \" + color.END\n", " if(item[\"type\"] == \"door\"):\n", " have_key = False\n", " for key in game_state[\"keys_collected\"]:\n", + " #Master key has target all doors\n", " if(key[\"target\"] == item or key[\"target\"]==\"all\"):\n", " have_key = True\n", " if(have_key):\n", @@ -279,12 +300,21 @@ " output += color.RED + \"It is locked but you don't have the key.\" + color.END\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 += color.YELLOW + color.BOLD + \"You FOUND \" + item_found[\"name\"] + \".\" + color.END\n", + " #Here inserted dice game outcomes\n", + " if item[\"name\"] == \"dice\":\n", + " if dice_game() == True:\n", + " item_found = object_relations[item[\"name\"]].pop()\n", + " game_state[\"keys_collected\"].append(item_found)\n", + " output += color.YELLOW + color.BOLD + \"You FOUND \" + item_found[\"name\"] + \".\" + color.END\n", + " else:\n", + " output += color.RED + \"Nothing happend, but there is something strange...\" + color.END\n", + " else:\n", + " item_found = object_relations[item[\"name\"]].pop()\n", + " game_state[\"keys_collected\"].append(item_found)\n", + " output += color.YELLOW + color.BOLD + \"You FOUND \" + item_found[\"name\"] + \".\" + color.END\n", " else:\n", " output += \"There isn't anything interesting about it. You hear an indistinct tapping right behind you... \"\n", - " time.sleep(2)\n", + " time.sleep(1)\n", " print(\"\\n\" + output)\n", " break\n", "\n", @@ -295,7 +325,7 @@ " time.sleep(2)\n", " play_room(next_room)\n", " else:\n", - " print(color.BOLD + \"\\nYou are still in the same room... AND THE CLOCK IS TICKING!\" + color.END)\n", + " print(color.BOLD + \"\\nYou are still in the same room...\" + color.END)\n", " play_room(current_room)\n", " " ] @@ -303,119 +333,15 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[91m\u001b[1mYou 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, but you suddenly hear a terrifying scream coming from the floor below your feet... You must get out of here, NOW!\u001b[0m\n", - "00:00\n", - "\u001b[36m\u001b[1m\n", - "Current Room: GAME ROOM\u001b[0m\n", - "\n", - "Type '1' to EXPLORE the room OR type '2' to EXAMINE an object! 1\n", - "\u001b[1m\n", - "You EXPLORE the room and you FIND: \u001b[94m\u001b[4mCOUCH, PIANO, DOOR A\u001b[0m\n", - "\u001b[36m\u001b[1m\n", - "Current Room: GAME ROOM\u001b[0m\n", - "\n", - "Type '1' to EXPLORE the room OR type '2' to EXAMINE an object! 2\n", - "\n", - "What would you like to EXAMINE? piano\n", - "\n", - "\u001b[1mYou examine PIANO. \u001b[0m\u001b[93m\u001b[1mYou FOUND KEY for Door A.\u001b[0m\n", - "\u001b[1m\n", - "You are still in the same room... AND THE CLOCK IS TICKING!\u001b[0m\n", - "\u001b[36m\u001b[1m\n", - "Current Room: GAME ROOM\u001b[0m\n", - "\n", - "Type '1' to EXPLORE the room OR type '2' to EXAMINE an object! 2\n", - "\n", - "What would you like to EXAMINE? door a\n", - "\n", - "\u001b[1mYou examine DOOR A. \u001b[0m\u001b[92mYou unlock it with a key you have.\u001b[0m\n", - "\n", - "Type 'YES' if you want to move to the next room, press ENTER otherwise: YES\n", - "\u001b[36m\u001b[1m\n", - "Current Room: BEDROOM 1\u001b[0m\n", - "\n", - "Type '1' to EXPLORE the room OR type '2' to EXAMINE an object! 1\n", - "\u001b[1m\n", - "You EXPLORE the room and you FIND: \u001b[94m\u001b[4mQUEEN BED, DOOR A, DOOR B, DOOR C\u001b[0m\n", - "\u001b[36m\u001b[1m\n", - "Current Room: BEDROOM 1\u001b[0m\n" - ] - } - ], - "source": [ - "game_state = INIT_GAME_STATE.copy()\n", - "\n", - "start_game()" - ] - }, - { - "cell_type": "code", - "execution_count": 15, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "00:00\n" - ] - }, - { - "data": { - "text/plain": [ - "'00:00'" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def countdown(t=10):\n", - " while t != 0:\n", - " mins, secs = divmod(t, 60)\n", - " timeformat = \"{:02d}:{:02d}\".format(mins, secs)\n", - " print(timeformat, end=\"\\r\")\n", - " time.sleep(1)\n", - " t -= 1\n", - " timeformat = \"{:02d}:{:02d}\".format(0,0)\n", - " print(timeformat)\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "00:00\n", - "00:00\n" - ] - } - ], + "outputs": [], "source": [ - "print(countdown())" + "game_state = INIT_GAME_STATE.copy()\n", + "\n", + "start_game()" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/your-code/Dice_game.ipynb b/your-code/Dice_game.ipynb new file mode 100644 index 00000000..83274c98 --- /dev/null +++ b/your-code/Dice_game.ipynb @@ -0,0 +1,109 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "import random\n", + "import time\n" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "You found a dice! If you roll the dice and get an even number you get the masterkey to escape from the scary house.\n", + "Are you ready?\n", + "00:00\n", + "You rolled number 5 you didn't escape by rolling the dice -_-'\n" + ] + }, + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#Describes setting and initiate g# your code\n", + "def countdown(t=10):\n", + " while t != 0:\n", + " mins, secs = divmod(t, 60)\n", + " timeformat = \"{:02d}:{:02d}\".format(mins, secs)\n", + " print(timeformat, end=\"\\r\")\n", + " time.sleep(1)\n", + " t -= 1\n", + " timeformat = \"{:02d}:{:02d}\".format(0,0)\n", + " print(timeformat)\n", + "\n", + "\n", + "### dice game!\n", + "def dice_game():\n", + " \"\"\"\n", + " Roll the dice\n", + " \"\"\"\n", + " print(\"You found a dice! If you roll the dice and get an even number you get the masterkey to escape from the scary house.\")\n", + " print(\"Are you ready?\")\n", + " time.sleep(1)\n", + " countdown(3)\n", + " rolled_num = random.randint(1,18)\n", + " if rolled_num % 2 == 0:\n", + " print(\"Congratulations, you rolled \", rolled_num, \" and thus you the master key!\")\n", + " return True \n", + " else:\n", + " print(\"You rolled number\", rolled_num,\"you didn't escape by rolling the dice -_-'\")\n", + " return False\n", + " \n", + " \n", + "dice_game()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "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.6.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 64e85073..0016d28e 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -11,7 +11,7 @@ "import time\n", "\n", "#Define classes\n", - "\n", + "#Classes of colours for DARK background\n", "class color:\n", " PURP = '\\033[36m'\n", " BLUE = '\\033[94m'\n", @@ -185,25 +185,45 @@ " \"\"\"\n", " print(\"\\n\\n\")\n", "\n", - "#Describes setting and initiate g# your code\n", - "def countdown(t=10):\n", + "#Prints a countdown timer for the beginnig of the game:\n", + "def countdown(t=3):\n", " while t != 0:\n", " mins, secs = divmod(t, 60)\n", " timeformat = \"{:02d}:{:02d}\".format(mins, secs)\n", - " print(timeformat, end=\"\\r\")\n", + " print(color.RED + color.BOLD + timeformat + color.END, end=\"\\r\")\n", " time.sleep(1)\n", " t -= 1\n", " timeformat = \"{:02d}:{:02d}\".format(0,0)\n", - " print(timeformat)\n", - "\n", - "\n", + " print(color.RED + color.BOLD + timeformat + color.END)\n", + " \n", "\n", + "#Defines the outcomes of rolling the dice, which can lead to obtain master key\n", + "def dice_game(faces = 18):\n", + " \"\"\"\n", + " Roll the dice\n", + " \"\"\"\n", + " usr_choice = input(color.RED + \"\\nIt does not look like a normal dice...\" + color.BOLD + \"Type 'YES' if you want to roll it, press ENTER otherwise: \").strip().lower()\n", + " if usr_choice == \"yes\":\n", + " #print(color.RED + color-BOLD + \"The mystery dice is rolling\" + color.END)\n", + " time.sleep(3)\n", + " rolled_num = random.randint(1,faces)\n", + " if rolled_num % 2 == 0:\n", + " print(color.YELLOW + \"\\nThe outcome is \", rolled_num, \" ...WOW a shiny golden key appeared out of nowere!\" + color.END)\n", + " return True \n", + " else:\n", + " print(color.BOLD + \"\\nThe outcome is \", rolled_num, \" ...Maybe you should roll it again...\"+color.END)\n", + " return False\n", + " else:\n", + " print(color.RED + \"\\nAren't you curious?\" + color.END)\n", + " return False\n", + " \n", + "#Describes setting and initiate g# your code\n", "def start_game():\n", " \"\"\"\n", " Start the game\n", " \"\"\"\n", " print(color.RED+color.BOLD+\"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, but you suddenly hear a terrifying scream coming from the floor below your feet... You must get out of here, NOW!\"+color.END)\n", - " countdown()\n", + " time=countdown()\n", " play_room(game_state[\"current_room\"])\n", " \n", "\n", @@ -215,7 +235,7 @@ " \"\"\"\n", " game_state[\"current_room\"] = room\n", " if(game_state[\"current_room\"] == game_state[\"target_room\"]):\n", - " time.sleep(4)\n", + " time.sleep(3)\n", " print(color.YELLOW + color.BOLD + \"\\nCONGRATS! YOU ESCAPED FROM AN ATROCIOUS DEATH!\" + color.END)\n", " else:\n", " print(color.PURP + color.BOLD + \"\\nCurrent Room: \" + room[\"name\"].upper() + color.END)\n", @@ -235,7 +255,7 @@ " Explore a room. List all items belonging to this room.\n", " \"\"\"\n", " items = [i[\"name\"] for i in object_relations[room[\"name\"]]]\n", - " time.sleep(2)\n", + " time.sleep(1)\n", " print(color.BOLD+\"\\nYou EXPLORE the room and you FIND: \"+color.BLUE+color.UNDER+\", \".join(items).upper() + color.END)\n", " #This is \" + room[\"name\"].upper()\n", " \n", @@ -266,10 +286,11 @@ " \n", " for item in object_relations[current_room[\"name\"]]:\n", " if(item[\"name\"] == item_name):\n", - " output = color.BOLD + \"You examine \" + item_name.upper() + \". \" + color.END\n", + " output = color.BOLD + \"You examined \" + item_name.upper() + \". \" + color.END\n", " if(item[\"type\"] == \"door\"):\n", " have_key = False\n", " for key in game_state[\"keys_collected\"]:\n", + " #Master key has target all doors\n", " if(key[\"target\"] == item or key[\"target\"]==\"all\"):\n", " have_key = True\n", " if(have_key):\n", @@ -279,12 +300,21 @@ " output += color.RED + \"It is locked but you don't have the key.\" + color.END\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 += color.YELLOW + color.BOLD + \"You FOUND \" + item_found[\"name\"] + \".\" + color.END\n", + " #Here inserted dice game outcomes\n", + " if item[\"name\"] == \"dice\":\n", + " if dice_game() == True:\n", + " item_found = object_relations[item[\"name\"]].pop()\n", + " game_state[\"keys_collected\"].append(item_found)\n", + " output += color.YELLOW + color.BOLD + \"You FOUND \" + item_found[\"name\"] + \".\" + color.END\n", + " else:\n", + " output += color.RED + \"Nothing happend, but there is something strange...\" + color.END\n", + " else:\n", + " item_found = object_relations[item[\"name\"]].pop()\n", + " game_state[\"keys_collected\"].append(item_found)\n", + " output += color.YELLOW + color.BOLD + \"You FOUND \" + item_found[\"name\"] + \".\" + color.END\n", " else:\n", " output += \"There isn't anything interesting about it. You hear an indistinct tapping right behind you... \"\n", - " time.sleep(2)\n", + " time.sleep(1)\n", " print(\"\\n\" + output)\n", " break\n", "\n", @@ -295,7 +325,7 @@ " time.sleep(2)\n", " play_room(next_room)\n", " else:\n", - " print(color.BOLD + \"\\nYou are still in the same room... AND THE CLOCK IS TICKING!\" + color.END)\n", + " print(color.BOLD + \"\\nYou are still in the same room...\" + color.END)\n", " play_room(current_room)\n", " " ] From d3995944fd63aace54f660bafc2125eaebea488d Mon Sep 17 00:00:00 2001 From: Mattia Lobascio Date: Fri, 25 Oct 2019 15:15:39 +0100 Subject: [PATCH 3/3] final version including dice game --- your-code/Dice_game.ipynb | 109 -------------------------------------- 1 file changed, 109 deletions(-) delete mode 100644 your-code/Dice_game.ipynb diff --git a/your-code/Dice_game.ipynb b/your-code/Dice_game.ipynb deleted file mode 100644 index 83274c98..00000000 --- a/your-code/Dice_game.ipynb +++ /dev/null @@ -1,109 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "import random\n", - "import time\n" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "You found a dice! If you roll the dice and get an even number you get the masterkey to escape from the scary house.\n", - "Are you ready?\n", - "00:00\n", - "You rolled number 5 you didn't escape by rolling the dice -_-'\n" - ] - }, - { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "#Describes setting and initiate g# your code\n", - "def countdown(t=10):\n", - " while t != 0:\n", - " mins, secs = divmod(t, 60)\n", - " timeformat = \"{:02d}:{:02d}\".format(mins, secs)\n", - " print(timeformat, end=\"\\r\")\n", - " time.sleep(1)\n", - " t -= 1\n", - " timeformat = \"{:02d}:{:02d}\".format(0,0)\n", - " print(timeformat)\n", - "\n", - "\n", - "### dice game!\n", - "def dice_game():\n", - " \"\"\"\n", - " Roll the dice\n", - " \"\"\"\n", - " print(\"You found a dice! If you roll the dice and get an even number you get the masterkey to escape from the scary house.\")\n", - " print(\"Are you ready?\")\n", - " time.sleep(1)\n", - " countdown(3)\n", - " rolled_num = random.randint(1,18)\n", - " if rolled_num % 2 == 0:\n", - " print(\"Congratulations, you rolled \", rolled_num, \" and thus you the master key!\")\n", - " return True \n", - " else:\n", - " print(\"You rolled number\", rolled_num,\"you didn't escape by rolling the dice -_-'\")\n", - " return False\n", - " \n", - " \n", - "dice_game()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "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.6.8" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -}