diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..040e508 Binary files /dev/null and b/.DS_Store differ diff --git a/Kick-Off.md b/Kick-Off.md deleted file mode 100644 index f784834..0000000 --- a/Kick-Off.md +++ /dev/null @@ -1,94 +0,0 @@ -Ironhack Logo - -# Build your own game! - -## Content -- [Project Description](#project-description) -- [Games](#games) -- [Project Goals](#project-goals) -- [Requirements & Deliverables](#requirements-&-deliverables) -- [Mentoring](#mentoring) -- [Schedule](#schedule) -- [Presentation](#presentation) - -## Project Description -In this project, you will create your first software! -You are tasked with creating a **game** that interacts with the user, using functions and other basic python resources you have learned during the week. Your game will be able to take an input from the user and provide an output. - -You will also present your game to the class. - -## Games -You will be assigned one of the following games: - -* [Strong Random Password Generator](https://strongpasswordgenerator.com/) -* [Guess The Number](https://www.funbrain.com/games/guess-the-number) -* [Hangman](https://www.coolmathgames.com/0-hangman) -* [Message Encryption & Decryption](https://www.base64decode.org/) -* [Mastermind](https://www.webgamesonline.com/mastermind/) -* [Tic Tac Toe](https://www.google.com/search?q=tic+tac+toe&oq=tic+tac+toe&aqs=chrome..69i57j0l5.1876j0j4&sourceid=chrome&ie=UTF-8) -* [Blackjack](https://bicyclecards.com/how-to-play/blackjack/) -* [Soldier & Dice (Risk)](https://en.wikipedia.org/wiki/Risk_(game)#Attack_and_defense) - -## Project Goals -During this project you will: -* Fork and manage your own git repository. -* Build your own code from scratch. -* Put into practice the basic python concepts learned during the week. -* Get used to public presentations. - -## Requirements & Deliverables -The **mandatory** requirements that this project needs to satisfy are: -* The project must be planned. That is why creating a Kanban board is important. You can either do it manually (e.g. with post-its) or use an online tool like Trello. You can find a template for Trello [here](https://trello.com/b/pc2CNZTo/project-1-build-your-own-game). Remember that you **CAN'T CODE** until your project is planned. -* Your repository must be clean and organized; this means that it must include a *.gitignore* file and a README file and also have a functional file structure. You can easily create a *.gitignore* template [here](https://www.toptal.com/developers/gitignore). -* Your code must include at least one function. -* The project needs to be presented to your colleagues on the day of the presentation. - -The **mandatory** deliverables that you must turn in are: -* Link to the repository you used while working on your project. The repository must include all the files you used to build your game. Remember to commit often to avoid trouble in case you mess up: this means more than 1 commit! -* Link to Trello or picture of your Kanban Board. Include the link or the picture in the README file. - -The **deadline** to turn in the deliverables is right before the project presentations. - -## Mentoring -One of the TAs will be your mentor! - -Your mentor will: -* Keep track of your project in general terms. Your mentor will be the second person that knows more about the project, after you. -* Check if you are following your plan: are you keeping up with your tasks and deadlines? Do you have any obstacles blocking you? -* Help/support you with specific questions. - -Your mentor is **not** meant to: -* Know everything. -* Be your manager. You have to be responsible of your own tasks! - -## Schedule - -**Please note** that the following schedule is simply a guideline. Feel free to organize your work as you see fit. - -**Wednesday** -* Choose the game that you are going to code. -* Plan your project. Remember that we are providing you with a Trello [template](https://trello.com/b/pc2CNZTo/project-1-build-your-own-game). Remember that you **CAN'T CODE** until your project is planned. -* Fork the repository and edit the README overview. You can find a [template](https://github.com/ta-data-bcn/Project-Week-1-Build-Your-Own-Game/blob/master/your-project/README.md) for your README file in this repository. Remember to keep the README up-to-date. -* Once you finish, start coding! Remember to use functions. - -**Thursday** -* Finish the coding and possibly check for bugs in the program (e.g. check what happens if the player gives unexpected inputs to the program). -* In the evening, start preparing the slides for Friday's presentation. - -**Friday** -* Presentation time at **3PM**! There will be a 15-minute break during the presentations. - -## Presentation -You will have **3 minutes** to present your project to the class and then **2 minutes** for Q&A. - -The slides of your presentation must include the content listed below and a demo of your game: - -* Title of the project + Student name -* Description and rules of your game -* Workflow -* Challenges you encountered during the process -* Learnings -* Possible future improvements -* Demo of the game (remember to save time for it) - -Tip: you have only 3 minutes for this presentation so keep it simple! diff --git a/README.md b/README.md new file mode 100644 index 0000000..1ca95e7 --- /dev/null +++ b/README.md @@ -0,0 +1,60 @@ +Ironhack Logo + +# The hangfolk game vlau.0 +*Laura* + +*Data Analysis Bootcamp, May 2021, Remote* + +## Content +- [Project Description](#project-description) +- [Rules](#rules) +- [Workflow](#workflow) +- [Organization](#organization) +- [Links](#links) + +## Project Description + +In this project I will create a version of the hangman game called "The hangfolk vlau.0". It is a really funny game that I used to play at school when I was a child on the board. My own version will make it even more fun (specially after all the work behind)! + +## Rules + +This game consists in guessing an unknown word picked randomly from a list of words. I will provide three topics to choose. +In each turn the player will pick a letter that, hopefully, the unknown word will contain. If this is the case, it will be shown on screen in which position is located together with a list of letters that have been already used.  +The player has 11 lives. That mean that you can just be wrong with your letter this amount of time, or you will be hanged! + +## Workflow + +The general workflow is the following: +- The player is welcome. +- The player inputs a letter. +- This word is added to the a list of already used letters. +- A display is generated showing the encrypted word and the list of letters that the player have already used. +- If the letter chosen by the player was in the word it will be placed in its correct position on the word display. +- The game will ask the player to input more letters until all letters are guessed or the player failes 11(the number of lives you will start with) times in guessing a letter. +- The game is finshed and a message is shown to see if the player has won. + + +## Organization + +**Phases of the project** + +I have used a Trello board to organize my tasks. They where organized is three phases: + +- The first phase was for creating the kanban board with all tasks required and set flexible deadlines. It was as well the moment to start with the design of the game an the pseudocode. + +- The second one for finished the pseudocode and started coding. + +- The third phase to review the code, test the game, debug and prepare the presentation. + +If I have extra time, I will implement extra fun on my game. + +**The repository** + +The repository includes this Readme file and a gitignote. Inside of the folder your code, it includes a python file with the script of the game, a jupyter notebook where the code is commented, and 3 text files whith the lists f word for the 3 topics provided. + +## Links +Links to the repository, slides and kanban board of this project. + +[Repository](https://github.com/lauratll/Project-Week-1-Build-Your-Own-Game) +[Slides](https://drive.google.com/file/d/1A2sbVdCMirgQOVL3RaTMTmUf_eGgOOpf/view?usp=sharing) +[Trello](https://trello.com/b/wEj7kAZd/project-1-built-your-own-game) diff --git a/your-project/.DS_Store b/your-project/.DS_Store new file mode 100644 index 0000000..d200fef Binary files /dev/null and b/your-project/.DS_Store differ diff --git a/your-project/.ipynb_checkpoints/The_hangfolk_game_vlau-checkpoint.ipynb b/your-project/.ipynb_checkpoints/The_hangfolk_game_vlau-checkpoint.ipynb new file mode 100644 index 0000000..733ee59 --- /dev/null +++ b/your-project/.ipynb_checkpoints/The_hangfolk_game_vlau-checkpoint.ipynb @@ -0,0 +1,323 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "1515067d", + "metadata": {}, + "source": [ + "# The hangfolk game version lau.0" + ] + }, + { + "cell_type": "markdown", + "id": "8bbca474", + "metadata": {}, + "source": [ + "## Welcome" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "id": "a1a712bd", + "metadata": {}, + "outputs": [], + "source": [ + "def welcome():\n", + " '''\n", + " This function welcomes the player asking for her/his name.\n", + " It has no return, it just prints\n", + " '''\n", + "\n", + " player_name = input(\"Please, enter your name: \")\n", + " print(\"Hello,\",player_name)\n", + " print(\"You probably know the game... In can you don't, I will quickly explain how it works...\")\n", + " print(\"You will have to guess the choosen word, picking in each turn a letter from the alphabet.If you fail, you will loose one of the 11 lives you have\")\n", + " print(\"If you fail too much, you will be hanged\")" + ] + }, + { + "cell_type": "markdown", + "id": "fb48a160", + "metadata": {}, + "source": [ + "## Choosing a topic" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "id": "ad7f46ba", + "metadata": {}, + "outputs": [], + "source": [ + "def choose_a_topic():\n", + " '''\n", + " This function is for choosing a topic from the provided ones.\n", + " The player inputs the topic. The functions makes sures the topic is one of the given ones.\n", + " It returns the topic chosen by the player\n", + " '''\n", + "\n", + " print(\"Now I will display a list of topics and you will hace to pick one:\")\n", + " list_topics = [\"sports\", \"medicine\", \"nature\"]\n", + "\n", + " for topics in list_topics:\n", + " print(topics)\n", + "\n", + " player_topic = input(\"Please, enter the topic you have choosen:\")\n", + "\n", + " check_topic = True\n", + "\n", + " while check_topic:\n", + " if player_topic in list_topics:\n", + " print(\"Great! You have choosen: \", player_topic)\n", + " check_topic = False\n", + " else:\n", + " player_topic = input(\"Please, enter the topic you have choosen correctly/from the list before:\")\n", + "\n", + " return player_topic" + ] + }, + { + "cell_type": "markdown", + "id": "25b0fe0e", + "metadata": {}, + "source": [ + "## Providing a word" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8242c231", + "metadata": {}, + "outputs": [], + "source": [ + "def clean_list(list1, drop=\"\\n\"):\n", + " '''\n", + " This function cleans a list from escape sequences and transforms the elements/strings\n", + " in lower case.\n", + " The input is a list and drop can be modified with more special characters.\n", + " A new clean list is returned.\n", + " '''\n", + "\n", + " clean_list = []\n", + " for element in list1:\n", + " element = element.lower()\n", + " element = element.replace(drop, \"\")\n", + " clean_list.append(element)\n", + " return clean_list" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "id": "526880f8", + "metadata": {}, + "outputs": [], + "source": [ + "def choose_word(list1):\n", + " '''\n", + " This function selects randomly an element.\n", + " The input must be a list and the output is the selected element\n", + " '''\n", + " chosen_word = random.choice(list1)\n", + " return chosen_word" + ] + }, + { + "cell_type": "markdown", + "id": "6169bccf", + "metadata": {}, + "source": [ + "## Player inputs letter" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d6ca27fe", + "metadata": {}, + "outputs": [], + "source": [ + "def player_input_letter(letters) :\n", + " '''\n", + " This function ask the player for the letter to play. It also\n", + " makes sures that is not a repeated letter and is not a digit. It will ask untill\n", + " it get the right input.\n", + " The input must be a list and the output is the output a single character.\n", + " In this case the list of used letters.\n", + " '''\n", + "\n", + " while True:\n", + " input_letter = input(\"Please,enter a letter: \")\n", + " if input_letter not in letters and input_letter.isdigit() == False:\n", + " break\n", + " elif input_letter in letters:\n", + " print(\"Please,enter another letter. This one you have already used\")\n", + " elif input_letter.isdigit():\n", + " print(\"Please, enter a letter, not a digit\")\n", + "\n", + " return input_letter" + ] + }, + { + "cell_type": "markdown", + "id": "523369e2", + "metadata": {}, + "source": [ + "## Display of the game" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "id": "cec0f518", + "metadata": {}, + "outputs": [], + "source": [ + "def generate_word_display(hidden_word, list_letters):\n", + " '''\n", + " This function generates a display of the encrypted word. It creates\n", + " an empty string where the letters present on the list are concatenated with *,\n", + " for the letters that are not present in the list but in the word.\n", + " In this way, we just show the played letters.\n", + " the inputs are a string (the word) and a list (the used_letters)\n", + " '''\n", + " result = str()\n", + " for character in hidden_word:\n", + " if character in list_letters:\n", + " result = result + character\n", + " else:\n", + " result = result + \"*\"\n", + " return result" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "id": "cd2516f7", + "metadata": {}, + "outputs": [], + "source": [ + "def print_current_game(list_letters,hidden_word,fails_left):\n", + " '''\n", + " This function prints the list of used letters and the encrypted word.\n", + " It will be print every turn, so it will show the advances on the game.\n", + " The inputs are a list of letter(the used letters), string (encrypted word) and\n", + " an integer(number of lives left)\n", + " '''\n", + " print(\"Those are the letters you have used:\", list_letters)\n", + " print(\"This is the word:\", hidden_word)\n", + " print(f\"You have {fails_left} lives left\")" + ] + }, + { + "cell_type": "markdown", + "id": "2f42a1b8", + "metadata": {}, + "source": [ + "## Main function - Game" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "id": "5f02be38", + "metadata": {}, + "outputs": [], + "source": [ + "def main():\n", + " '''\n", + " This function is the one who is gonna make run the game as many times as the player wants\n", + " '''\n", + " print(\"Welcome to the hangfolk game version lau.0\")\n", + " while True:\n", + " welcome()\n", + "\n", + " player_topic = choose_a_topic()\n", + "\n", + " sports_file = open(\"/Users/lauratll/Documents/Data_Analysis/IronHack/Week_1/Project_week1/Project-Week-1-Build-Your-Own-Game/your-project/sports_list.txt\")\n", + " medicine_file = open(\"/Users/lauratll/Documents/Data_Analysis/IronHack/Week_1/Project_week1/Project-Week-1-Build-Your-Own-Game/your-project/medicine_list.txt\")\n", + " nature_file = open(\"/Users/lauratll/Documents/Data_Analysis/IronHack/Week_1/Project_week1/Project-Week-1-Build-Your-Own-Game/your-project/nature_list.txt\")\n", + " sports_list = clean_list(sports_file)\n", + " medicine_list = clean_list(medicine_file)\n", + " nature_list = clean_list(nature_file)\n", + "\n", + " dic_words = {}\n", + " dic_words[\"sports\"] = sports_list\n", + " dic_words[\"medicine\"] = medicine_list\n", + " dic_words[\"nature\"] = nature_list\n", + " word = choose_word(dic_words[player_topic])\n", + "\n", + " ongoing = True\n", + " used_letters = []\n", + " lives = 11\n", + " player_wins = False\n", + "\n", + " while ongoing:\n", + " player_letter = player_input_letter(used_letters)\n", + " used_letters.append(player_letter)\n", + " word_display = generate_word_display(word, used_letters)\n", + " if player_letter not in word:\n", + " lives -= 1\n", + " if lives == 0:\n", + " ongoing = False\n", + "\n", + " if \"*\" not in word_display:\n", + " ongoing= False\n", + " player_wins= True\n", + "\n", + " print_current_game(used_letters, word_display,lives)\n", + "\n", + " if player_wins:\n", + " print(f\"Cool! You have won! The word was: {word}\")\n", + " else:\n", + " print(f\"Sorry! You are hanged! The word was: {word}\")\n", + "\n", + " play_again = input(\"Would you like to play again?(Yes/No)\")\n", + " if play_again == \"No\":\n", + " break" + ] + }, + { + "cell_type": "markdown", + "id": "c4995949", + "metadata": {}, + "source": [ + "## Starts the game!" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ba6e077e", + "metadata": {}, + "outputs": [], + "source": [ + "main()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Laura1Env", + "language": "python", + "name": "laura1env" + }, + "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.2" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/your-project/README.md b/your-project/README.md deleted file mode 100644 index 2a8493d..0000000 --- a/your-project/README.md +++ /dev/null @@ -1,34 +0,0 @@ -Ironhack Logo - -# Title of Your Project -*[Your Name]* - -*[Your Cohort, Campus & Date]* - -## Content -- [Project Description](#project-description) -- [Rules](#rules) -- [Workflow](#workflow) -- [Organization](#organization) -- [Links](#links) - -## Project Description -Write a short description of your project. Write 1-2 sentences about the game you chose to build and why. - -## Rules -Briefly describe the rules of the game. - -## Workflow -Outline the workflow you used in your project. What are the steps you went through? - -## Organization -How did you organize your work? Did you use any tools like a kanban board? - -What does your repository look like? Explain your folder and file structure. - -## Links -Include links to your repository, slides and kanban board. Feel free to include any other links associated with your project. - -[Repository](https://github.com/) -[Slides](https://slides.com/) -[Trello](https://trello.com/en) diff --git a/your-project/The_hangfolk_game_vlau.ipynb b/your-project/The_hangfolk_game_vlau.ipynb new file mode 100644 index 0000000..733ee59 --- /dev/null +++ b/your-project/The_hangfolk_game_vlau.ipynb @@ -0,0 +1,323 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "1515067d", + "metadata": {}, + "source": [ + "# The hangfolk game version lau.0" + ] + }, + { + "cell_type": "markdown", + "id": "8bbca474", + "metadata": {}, + "source": [ + "## Welcome" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "id": "a1a712bd", + "metadata": {}, + "outputs": [], + "source": [ + "def welcome():\n", + " '''\n", + " This function welcomes the player asking for her/his name.\n", + " It has no return, it just prints\n", + " '''\n", + "\n", + " player_name = input(\"Please, enter your name: \")\n", + " print(\"Hello,\",player_name)\n", + " print(\"You probably know the game... In can you don't, I will quickly explain how it works...\")\n", + " print(\"You will have to guess the choosen word, picking in each turn a letter from the alphabet.If you fail, you will loose one of the 11 lives you have\")\n", + " print(\"If you fail too much, you will be hanged\")" + ] + }, + { + "cell_type": "markdown", + "id": "fb48a160", + "metadata": {}, + "source": [ + "## Choosing a topic" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "id": "ad7f46ba", + "metadata": {}, + "outputs": [], + "source": [ + "def choose_a_topic():\n", + " '''\n", + " This function is for choosing a topic from the provided ones.\n", + " The player inputs the topic. The functions makes sures the topic is one of the given ones.\n", + " It returns the topic chosen by the player\n", + " '''\n", + "\n", + " print(\"Now I will display a list of topics and you will hace to pick one:\")\n", + " list_topics = [\"sports\", \"medicine\", \"nature\"]\n", + "\n", + " for topics in list_topics:\n", + " print(topics)\n", + "\n", + " player_topic = input(\"Please, enter the topic you have choosen:\")\n", + "\n", + " check_topic = True\n", + "\n", + " while check_topic:\n", + " if player_topic in list_topics:\n", + " print(\"Great! You have choosen: \", player_topic)\n", + " check_topic = False\n", + " else:\n", + " player_topic = input(\"Please, enter the topic you have choosen correctly/from the list before:\")\n", + "\n", + " return player_topic" + ] + }, + { + "cell_type": "markdown", + "id": "25b0fe0e", + "metadata": {}, + "source": [ + "## Providing a word" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8242c231", + "metadata": {}, + "outputs": [], + "source": [ + "def clean_list(list1, drop=\"\\n\"):\n", + " '''\n", + " This function cleans a list from escape sequences and transforms the elements/strings\n", + " in lower case.\n", + " The input is a list and drop can be modified with more special characters.\n", + " A new clean list is returned.\n", + " '''\n", + "\n", + " clean_list = []\n", + " for element in list1:\n", + " element = element.lower()\n", + " element = element.replace(drop, \"\")\n", + " clean_list.append(element)\n", + " return clean_list" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "id": "526880f8", + "metadata": {}, + "outputs": [], + "source": [ + "def choose_word(list1):\n", + " '''\n", + " This function selects randomly an element.\n", + " The input must be a list and the output is the selected element\n", + " '''\n", + " chosen_word = random.choice(list1)\n", + " return chosen_word" + ] + }, + { + "cell_type": "markdown", + "id": "6169bccf", + "metadata": {}, + "source": [ + "## Player inputs letter" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d6ca27fe", + "metadata": {}, + "outputs": [], + "source": [ + "def player_input_letter(letters) :\n", + " '''\n", + " This function ask the player for the letter to play. It also\n", + " makes sures that is not a repeated letter and is not a digit. It will ask untill\n", + " it get the right input.\n", + " The input must be a list and the output is the output a single character.\n", + " In this case the list of used letters.\n", + " '''\n", + "\n", + " while True:\n", + " input_letter = input(\"Please,enter a letter: \")\n", + " if input_letter not in letters and input_letter.isdigit() == False:\n", + " break\n", + " elif input_letter in letters:\n", + " print(\"Please,enter another letter. This one you have already used\")\n", + " elif input_letter.isdigit():\n", + " print(\"Please, enter a letter, not a digit\")\n", + "\n", + " return input_letter" + ] + }, + { + "cell_type": "markdown", + "id": "523369e2", + "metadata": {}, + "source": [ + "## Display of the game" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "id": "cec0f518", + "metadata": {}, + "outputs": [], + "source": [ + "def generate_word_display(hidden_word, list_letters):\n", + " '''\n", + " This function generates a display of the encrypted word. It creates\n", + " an empty string where the letters present on the list are concatenated with *,\n", + " for the letters that are not present in the list but in the word.\n", + " In this way, we just show the played letters.\n", + " the inputs are a string (the word) and a list (the used_letters)\n", + " '''\n", + " result = str()\n", + " for character in hidden_word:\n", + " if character in list_letters:\n", + " result = result + character\n", + " else:\n", + " result = result + \"*\"\n", + " return result" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "id": "cd2516f7", + "metadata": {}, + "outputs": [], + "source": [ + "def print_current_game(list_letters,hidden_word,fails_left):\n", + " '''\n", + " This function prints the list of used letters and the encrypted word.\n", + " It will be print every turn, so it will show the advances on the game.\n", + " The inputs are a list of letter(the used letters), string (encrypted word) and\n", + " an integer(number of lives left)\n", + " '''\n", + " print(\"Those are the letters you have used:\", list_letters)\n", + " print(\"This is the word:\", hidden_word)\n", + " print(f\"You have {fails_left} lives left\")" + ] + }, + { + "cell_type": "markdown", + "id": "2f42a1b8", + "metadata": {}, + "source": [ + "## Main function - Game" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "id": "5f02be38", + "metadata": {}, + "outputs": [], + "source": [ + "def main():\n", + " '''\n", + " This function is the one who is gonna make run the game as many times as the player wants\n", + " '''\n", + " print(\"Welcome to the hangfolk game version lau.0\")\n", + " while True:\n", + " welcome()\n", + "\n", + " player_topic = choose_a_topic()\n", + "\n", + " sports_file = open(\"/Users/lauratll/Documents/Data_Analysis/IronHack/Week_1/Project_week1/Project-Week-1-Build-Your-Own-Game/your-project/sports_list.txt\")\n", + " medicine_file = open(\"/Users/lauratll/Documents/Data_Analysis/IronHack/Week_1/Project_week1/Project-Week-1-Build-Your-Own-Game/your-project/medicine_list.txt\")\n", + " nature_file = open(\"/Users/lauratll/Documents/Data_Analysis/IronHack/Week_1/Project_week1/Project-Week-1-Build-Your-Own-Game/your-project/nature_list.txt\")\n", + " sports_list = clean_list(sports_file)\n", + " medicine_list = clean_list(medicine_file)\n", + " nature_list = clean_list(nature_file)\n", + "\n", + " dic_words = {}\n", + " dic_words[\"sports\"] = sports_list\n", + " dic_words[\"medicine\"] = medicine_list\n", + " dic_words[\"nature\"] = nature_list\n", + " word = choose_word(dic_words[player_topic])\n", + "\n", + " ongoing = True\n", + " used_letters = []\n", + " lives = 11\n", + " player_wins = False\n", + "\n", + " while ongoing:\n", + " player_letter = player_input_letter(used_letters)\n", + " used_letters.append(player_letter)\n", + " word_display = generate_word_display(word, used_letters)\n", + " if player_letter not in word:\n", + " lives -= 1\n", + " if lives == 0:\n", + " ongoing = False\n", + "\n", + " if \"*\" not in word_display:\n", + " ongoing= False\n", + " player_wins= True\n", + "\n", + " print_current_game(used_letters, word_display,lives)\n", + "\n", + " if player_wins:\n", + " print(f\"Cool! You have won! The word was: {word}\")\n", + " else:\n", + " print(f\"Sorry! You are hanged! The word was: {word}\")\n", + "\n", + " play_again = input(\"Would you like to play again?(Yes/No)\")\n", + " if play_again == \"No\":\n", + " break" + ] + }, + { + "cell_type": "markdown", + "id": "c4995949", + "metadata": {}, + "source": [ + "## Starts the game!" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ba6e077e", + "metadata": {}, + "outputs": [], + "source": [ + "main()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Laura1Env", + "language": "python", + "name": "laura1env" + }, + "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.2" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/your-project/hangfolk.py b/your-project/hangfolk.py new file mode 100644 index 0000000..45ffca8 --- /dev/null +++ b/your-project/hangfolk.py @@ -0,0 +1,182 @@ +#######Welcome######### + +import random + + +def welcome(): + ''' + This function welcomes the player asking for her/his name and explain the basic rules. + It has no return, it just prints + ''' + + player_name = input("Please, enter your name: ") + print("Hello,",player_name) + print("You probably know the game... In can you don't, I will quickly explain how it works...") + print("You will have to guess the choosen word, picking in each turn a letter from the alphabet.If you fail, you will loose one of the 11 lives you have") + print("If you fail too much, you will be hanged") + + + +###############Chossing a topic############ +def choose_a_topic(): + ''' + This function is for choosing a topic from the provided ones. + The player inputs the topic. The functions makes sures the topic is one of the given ones. + It returns the topic chosen by the player + ''' + + print("Now I will display a list of topics and you will have to pick one:") + list_topics = ["sports", "medicine", "nature"] + + for topics in list_topics: + print(topics) + + player_topic = input("Please, enter the topic you have choosen:") + + check_topic = True + + while check_topic: + if player_topic in list_topics: + print("Great! You have choosen: ", player_topic) + check_topic = False + else: + player_topic = input("Please, enter the topic you have choosen correctly/from the list before:") + + return player_topic + + + +###################Providing a word############### + +def clean_list(list1, drop="\n"): + ''' + This function cleans a list from escape sequences and transforms the elements/strings + in lower case. + The input is a list and drop can be modified with more special characters. + A new clean list is returned. + ''' + + clean_list = [] + for element in list1: + element = element.lower() + element = element.replace(drop, "") + clean_list.append(element) + return clean_list + + + +def choose_word(list1): + ''' + This function selects randomly an element. + The input must be a list and the output is the selected element + ''' + chosen_word = random.choice(list1) + return chosen_word + + +#######Player inputs letters#################### + +def player_input_letter(letters) : + ''' + This function ask the player for the letter to play. It also + makes sures that is not a repeated letter and is not a digit. It will ask untill + it get the right input. + The input must be a list and the output is the output a single character. + In this case the list of used letters. + ''' + + while True: + input_letter = input("Please,enter a letter: ") + if input_letter not in letters and input_letter.isdigit() == False: + break + elif input_letter in letters: + print("Please,enter another letter. This one you have already used") + elif input_letter.isdigit(): + print("Please, enter a letter, not a digit") + + return input_letter + +######Displa + +def generate_word_display(hidden_word, list_letters): + ''' + This function generates a display of the encrypted word. It creates + an empty string where the letters present on the list are concatenated with *, + for the letters that are not present in the list but in the word. + In this way, we just show the played letters. + the inputs are a string (the word) and a list (the used_letters) + ''' + result = str() + for character in hidden_word: + if character in list_letters: + result = result + character + else: + result = result + "*" + return result + +def print_current_game(list_letters,hidden_word,fails_left): + ''' + This function prints the list of used letters and the encrypted word. + It will be print every turn, so it will show the advances on the game. + The inputs are a list of letter(the used letters), string (encrypted word) and + an integer(number of lives left) + ''' + print("Those are the letters you have used:", list_letters) + print("This is the word:", hidden_word) + print(f"You have {fails_left} lives left") + + + + +def main(): + ''' + This function is the one who is gonna make run the game as many times as the player wants + ''' + print("Welcome to the hangfolk game version lau.0") + while True: + welcome() + + player_topic = choose_a_topic() + + sports_file = open("/Users/lauratll/Documents/Data_Analysis/IronHack/Week_1/Project_week1/Project-Week-1-Build-Your-Own-Game/your-project/sports_list.txt") + medicine_file = open("/Users/lauratll/Documents/Data_Analysis/IronHack/Week_1/Project_week1/Project-Week-1-Build-Your-Own-Game/your-project/medicine_list.txt") + nature_file = open("/Users/lauratll/Documents/Data_Analysis/IronHack/Week_1/Project_week1/Project-Week-1-Build-Your-Own-Game/your-project/nature_list.txt") + sports_list = clean_list(sports_file) + medicine_list = clean_list(medicine_file) + nature_list = clean_list(nature_file) + + dic_words = {} + dic_words["sports"] = sports_list + dic_words["medicine"] = medicine_list + dic_words["nature"] = nature_list + word = choose_word(dic_words[player_topic]) + + ongoing = True + used_letters = [] + lives = 11 + player_wins = False + + while ongoing: + player_letter = player_input_letter(used_letters) + used_letters.append(player_letter) + word_display = generate_word_display(word, used_letters) + if player_letter not in word: + lives -= 1 + if lives == 0: + ongoing = False + + if "*" not in word_display: + ongoing= False + player_wins= True + + print_current_game(used_letters, word_display,lives) + + if player_wins: + print(f"Cool! You have won! The word was: {word}") + else: + print(f"Sorry! You are hanged! The word was: {word}") + + play_again = input("Would you like to play again?(Yes/No)") + if play_again == "No": + break +main() \ No newline at end of file diff --git a/your-project/medicine_list.txt b/your-project/medicine_list.txt new file mode 100644 index 0000000..10b3b1b --- /dev/null +++ b/your-project/medicine_list.txt @@ -0,0 +1,45 @@ +Surgeon +Anesthesiologist +Cardiologist +Traumatologist +Orthopedist +Gastroenterologist +Dermatologist +Gynaecologist +Urologist +Ophthalmologist +Therapist +Nurse +Paediatrician +Physician +Doctor +Family doctor +Chronic +Benign +Terminal +Treat +Cure +Sickness +Cold +Flu +Virus +Remedy +Wound +Burn +Fracture +Heal +Injury +Trauma +Disease +Exam +Diagnosis +Prescription +Urine sample +Blood sample +Hypertension +Cast +Vein +Syringe +Painkiller +Numb +Dosage diff --git a/your-project/nature_list.txt b/your-project/nature_list.txt new file mode 100644 index 0000000..12d19eb --- /dev/null +++ b/your-project/nature_list.txt @@ -0,0 +1,51 @@ +Canal +Bridge +Dam +Lighthouse +Island +Bay +Riverbank +Beach +Sea +Ocean +Coast +Ground +Dune +Desert +Cliff +Park +Meadow +Jungle +Forest +Glacier +Land +Hill +Field +Grass +Soil +Seashell +Mushroom +Pebble +Rock +Stone +Smoke +Pond +River +Wave +Sky +Water +Tree +Plant +Moss +Flower +Bush +Sand +Mud +Stars +Planet +Mine +Path +Road +Tunnel +Volcano +Cave \ No newline at end of file diff --git a/your-project/sports_list.txt b/your-project/sports_list.txt new file mode 100644 index 0000000..8c78c5f --- /dev/null +++ b/your-project/sports_list.txt @@ -0,0 +1,284 @@ +aerobics +archer +archery +arrow +athlete +athletics +badminton +ball +base +baseball +basketball +bat +baton +batter +batting +biathlon +bicycle +bicycling +bike +biking +billiards +bobsleigh +bocce +boomerang +boules +bow +bowler +bowling +boxer +boxing +bunt +canoe +canoeing +catch +catcher +champion +championship +cleats +club +coach +compete +competing +competition +competitor +crew +cricket +croquet +cue +curling +cycle +cycling +cyclist +dart +dartboard +deadlifting +decathlon +defense +diamond +discus +dive +diver +diving +dodgeball +doubleheader +dugout +epee +equestrian +equipment +exercise +fencing +field +fielder +hockey +fielding +fitness +football +forward +free throw +frisbee +game +gear +geocaching +go +goal +goalie +golf +golfer +golfing +guard +gym +gymnast +gymnastics +gymnasium +halftime +handball +hangliding +hardball +helmet +heptathlon +high jump +hitter +hockey +hoop +horseshoes +huddle +hurdle +icehockey +icerink +iceskates +iceskating +infield +infielder +inline skates +inning +javelin +jog +jogger +judo +jump +jumper +jumping +jumprope +karate +kayak +kayaker +kayaking +kickball +kneepads +kingfu +kite +lacrosse +bowling +league +lose +loser +luge +lutz +mallet +martialarts +mat +medal +mitt +mouthguard +move +movement +Nordicskiing +offense +ollie +Olympics +orienteering +out +outfield +outfielder +paddle +paddleball +paddling +paintball +parasailing +parkour +pentathlon +pickleball +pingpong +pitch +pitcher +play +player +playing +playoffs +pole +polo +pool +puck +quarter +quarterback +quiver +race +racer +racewalking +racing +racket +racquetball +rafting +referee +relay +ride +riding +rink +climbing +rollerskates +rollerskating +row +rower +rowing +rugby +run +runner +running +sailing +score +scoreboard +scuba +scull +sculling +shortstop +skate +ski +skier +skiing +slalom +sled +sledder +sledding +snorkling +snowboard +snowboarder +snowboarding +snowshoeing +soccer +softball +somersault +sport +sportsmanship +squash +stadium +stick +strike +stroke +Sumo +surfer +surfing +swim +swimmer +swimming +tabletennis +taekwondo +tag +target +team +teammate +tee +tennis +tetherball +throw +throwing +tie +toboggan +trampoline +triathlon +triathlete +triple jump +triple play +tug of war +ultramarathon +ultramarathoner +umpire +unicycle +unicyclist +uniform +vaulter +vaulting +visiting team +volley +volley ball +wakeboarding +walk +walker +walking +water polo +waterski +waterskier +waterskiing +weightlifter +weightlifting +weights +wetsuit +rafting +wicket +win +windsurfer +windsurfing +winner +winning +wrestler +wrestling \ No newline at end of file