[Solved] SOLVED: implementing the game hangman Solution

$25

File Name: SOLVED:_implementing_the_game_hangman_Solution.zip
File Size: 433.32 KB

SKU: [Solved] SOLVED: implementing the game hangman Solution Category: Tag:
5/5 - (1 vote)

1. (35 mins.) For this problem you will be implementing the game hangman. In hangman one person chooses a secret word and and displays _ representing the position of each character. The other person guesses letters in the word in an attempt to figure out what it is. If the character is in the secret word the then all positions that contain that character are revealed. If the character is not in the secret word then a body part of the hang man is drawn. The second personcontinues guessing letters until either they reveal the entire secret word or until the hangman figure is complete. If the word is completely revealed the second player wins. If the hangman is completed the second player loses. Write a program called hangman.py that implements the hangman game. Here is Wikipedias article on hangman if you need more information on howthe game is played.1. The second player has 7 guesses as there are 7 pieces to the hangman figure. The pieces are added to the figure in the following order: rope, head, torso, left arm, right arm, left leg, right leg.2. At the beginning of the game the first player should be asked to enter the secret word. All characters are legal excluding ? and white space characters (tab, space, newline). After the user enters a word you should display 30 newlines so as to hide the secret word.3. At the beginning of each round you should display in this order: The hanged man, the partially guessed secret word, the characters guessed so far.4. For the secret word, the characters that have not been guessed should be displayed as ?5. Guesses for the characters in the secret word should be case insensitive. Store the entered secret word in lowercase and convert all guessed characters to lower case.6. Leading and trailing white space should be removed from the users guess before checking it7. The user must enter a guess. If they do not they should be told that they must enter a guess and receive the prompt to enter the next character again. This should continue until the user enters a new character.8. If the user guesses a character that they have already guessed then they should be told that they already guessed that character and be given the opportunity to guess again. This shouldcontinue until the user enters a new character. These guesses should not be counted against the user.9. The user can only guess 1 character at a time. If the user enters more than 1 character they should be told that they can only enter 1 character and be given the opportunity to guess again. This should continue until the user enters a new character.10. The letters that have been guessed so far should be displayed in sorted order.11. If the user guesses the secret word they should be told that they guessed the secret word.12. If the user does not guess the secret word they should be told that they failed to guess the word and the word should be revealed.13. You MUST USE FUNCTIONS for this program as it will make things much easier.The are two examples of playing the hangman game below.Example(The extra newlines after the secret word are not shown for space reasons):Please enter a word to be guessedthat does not contain ? or white space: hello?????So far you have guessed:Please enter your next guess: hh????So far you have guessed: hPlease enter your next guess: t|h????So far you have guessed: h, tPlease enter your next guess: y|0h????So far you have guessed: h, t, yPlease enter your next guess: tYou already guessed the character: tPlease enter your next guess: yYou already guessed the character: yPlease enter your next guess: hiYou can only guess a single character.Please enter your next guess: jokeYou can only guess a single character.Please enter your next guess: l|0h?ll?So far you have guessed: h, l, t, yPlease enter your next guess: u|0|h?ll?So far you have guessed: h, l, t, u, yPlease enter your next guess: (|0/|h?ll?So far you have guessed: (, h, l, t, u, yPlease enter your next guess: e|0/|hell?So far you have guessed: (, e, h, l, t, u, yPlease enter your next guess: oYou correctly guessed the secret word: helloExample (The extra newlines after the secret word are not shown for space reasons):Please enter a word to be guessedthat does not contain ? or white space: dont ? mePlease enter a word to be guessedthat does not contain ? or white space: me and youPlease enter a word to be guessedthat does not contain ? or white space: ?the-systemPlease enter a word to be guessedthat does not contain ? or white space: backdash??????????So far you have guessed:Please enter your next guess: jokeYou can only guess a single character.Please enter your next guess:You must enter a guess.Please enter your next guess: bb?????????So far you have guessed: bPlease enter your next guess: bYou already guessed the character: bPlease enter your next guess: aba?????a??So far you have guessed: a, bPlease enter your next guess: aYou already guessed the character: aPlease enter your next guess: bYou already guessed the character: bPlease enter your next guess: bathroomYou can only guess a single character.Please enter your next guess: 1|ba?????a??So far you have guessed: 1, a, bPlease enter your next guess: /|0ba?????a??So far you have guessed: /, 1, a, bPlease enter your next guess: |0ba???a??So far you have guessed: -, /, 1, a, bPlease enter your next guess: r|0|ba???a??So far you have guessed: -, /, 1, a, b, rPlease enter your next guess: aYou already guessed the character: aPlease enter your next guess: q|0/|ba???a??So far you have guessed: -, /, 1, a, b, q, rPlease enter your next guess: 9|0/|ba???a??So far you have guessed: -, /, 1, 9, a, b, q, rPlease enter your next guess: ^|0/|/ba???a??So far you have guessed: -, /, 1, 9, ^, a, b, q, rPlease enter your next guess: z|0/|/ You failed to guess the secret word: backdash1. (26 mins) For this problem you will be implementing the turn based battle system found in Pokemon and many other games. In a battle the monsters take turns attacking each other untilone of them runs out of hit points (hp). If you have never seen a battle before you can watch one here (dont bother watching beyond 3:35). Write a program called pokemon.py that implements a basic 1 v 1 Pokemon battle that meets the following specifications1. Modules Allowed1. random1. You will find the following functions from random vital to complete yourassignment: random.seed, random.random, and random.randint.2. Since we are working with random here, it is absolutely VITAL that you follow the instructions in how to call the random functions because if you dont, even if your logic is correct, your answers wont match mine.2. You should ask the user to enter the names for both monsters followed by the seed.1. The names for the monsters can be anything2. The seed must be an integer1. Use the integer value of the seed input to initialize the random number generator via a call to random.seed. This should be done exactly once in your program and before any other calls to the functions in the random module are made.2. In a normal program we wouldnt ask the user for a seed but here we are so that we can test your programs3. After seeding the random number generator, use random.randint to randomly choose who will be first to attack. If a 0 is chosen the first monster goes first and if a 1 is chosen the second monster will go first4. Both monsters will start the battle with 100 hp and the fight will continue until the hp of one of the monsters is 0. The last monster left standing is the winner.5. Both monsters have access to the following moves Name Number Accuracy Min Max Crit Chance EffectTackle 1 90.00% 10 20 5.00% Damage Opponent from min maxHigh Jump Kick 2 75.00% 25 30 5.00% Damage Opponent from min maxDesperate Blow 3 10.00% 50 60 5.00% Damage Opponent from min maxSlack Off 4 95.00% 15 20 5.00% Heal Self from min max6. During each turn the player will choose a move1. After a valid move is selected we will check to see if that move hit the opponent based on that moves accuracy1. Use random.random to check for a hit2. If the move hits1. We will randomly pick an integer between min and max for the strength of thisattack1. Use random.randint to determine the strength2. After determining strength we will then check if a crit occurred.1. If a crit does occur the strength of the attack is doubled1. For example if we used tackle and its strength was 19 this time and a critoccurred its strength would then be 38.2. Use random.random to determine if a critical hit occurred3. If the attack was between 1 3 then the strength of the move is dealt to the other monster as damage4. If the attack was 4 then the strength of the move heals the current monster thatmuch.3. If the move misses1. If the attack was 1 3 then the other monster dodged the attack2. If the attack was 4 then the monster failed to heal itself2. No attack may deal more than the defenders current hp and no heal may heal the current monster over 100 hp1. To implement this we will still do the normal damage calculations in 6.1 but after the strength of the move is determined we will reduce it if it would violate the rules in6.21. For example lets say the defender has 10 hp left but the attack would deal 20after completing 6.1., we would reduce the strength down to 10.2. As another example lets say we are at 95 hp and we decide to heal. Aftercompleting 6.1 we find that we would heal for 40. If we did this would put usover 100 hp so we instead heal for 5.2. If we are at full health and decide to heal, we still carry out all the steps in 6.1 but the heal is counted as a failure because it would heal 0 hp.7. After a monster makes it move the other monster is allowed to take its turn. Turns switchuntil the hp of one monster reaches 0.8. NO INPUT is guaranteed to be valid. If the user enters invalid input your program shouldcontinue to ask them for input until valid input is entered.2. Some Example Games on the following pagesEnter the name for your monster: AshEnter the name for your monster: GaryEnter a seed value: 5Ash has 100 hit points remaining.Gary has 100 hit points remaining.Choose a move for Gary.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: 4Gary failed to heal itself.Ash has 100 hit points remaining.Gary has 100 hit points remaining.Choose a move for Ash.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: 4Ash failed to heal itself.Ash has 100 hit points remaining.Gary has 100 hit points remaining.Choose a move for Gary.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: 1Gary hit Ash with a Tackle dealing 13 points of damage.Ash has 87 hit points remaining.Gary has 100 hit points remaining.Choose a move for Ash.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: 1Gary dodged the attack.Ash has 87 hit points remaining.Gary has 100 hit points remaining.Choose a move for Gary.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: 4Gary failed to heal itself.Ash has 87 hit points remaining.Gary has 100 hit points remaining.Choose a move for Ash.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: 4Ash Slacked Off, healing 13 points of damage.Ash has 100 hit points remaining.Gary has 100 hit points remaining.Choose a move for Gary.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: 1Gary hit Ash with a Tackle dealing 13 points of damage.Ash has 87 hit points remaining.Gary has 100 hit points remaining.Choose a move for Ash.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: 2Ash hit Gary with a High Jump Kick dealing 28 points of damage.Ash has 87 hit points remaining.Gary has 72 hit points remaining.Choose a move for Gary.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: 2Gary hit Ash with a High Jump Kick dealing 26 points of damage.Ash has 61 hit points remaining.Gary has 72 hit points remaining.Choose a move for Ash.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: 3Gary dodged the attack.Ash has 61 hit points remaining.Gary has 72 hit points remaining.Choose a move for Gary.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: 3Ash dodged the attack.Ash has 61 hit points remaining.Gary has 72 hit points remaining.Choose a move for Ash.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: 2Ash hit Gary with a High Jump Kick dealing 25 points of damage.Ash has 61 hit points remaining.Gary has 47 hit points remaining.Choose a move for Gary.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: 2Gary hit Ash with a High Jump Kick dealing 26 points of damage.Ash has 35 hit points remaining.Gary has 47 hit points remaining.Choose a move for Ash.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: 2Ash hit Gary with a High Jump Kick dealing 26 points of damage.Ash has 35 hit points remaining.Gary has 21 hit points remaining.Choose a move for Gary.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: 2Gary hit Ash with a High Jump Kick dealing 26 points of damage.Ash has 9 hit points remaining.Gary has 21 hit points remaining.Choose a move for Ash.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: 1Gary dodged the attack.Ash has 9 hit points remaining.Gary has 21 hit points remaining.Choose a move for Gary.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: 1Gary hit Ash with a Tackle dealing 9 points of damage.Gary won the fight.Enter the name for your monster: MagikarpEnter the name for your monster: MewtwoEnter a seed value: badEnter a seed value: 69hiEnter a seed value: -3Magikarp has 100 hit points remaining.Mewtwo has 100 hit points remaining.Choose a move for Magikarp.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: somethingChoose a move for Magikarp.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: 5Choose a move for Magikarp.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: -2Choose a move for Magikarp.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: 2Magikarp hit Mewtwo with a High Jump Kick dealing 26 points ofdamage.Magikarp has 100 hit points remaining.Mewtwo has 74 hit points remaining.Choose a move for Mewtwo.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: 2Mewtwo hit Magikarp with a High Jump Kick dealing 30 points ofdamage.Magikarp has 70 hit points remaining.Mewtwo has 74 hit points remaining.Choose a move for Magikarp.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: 2Magikarp hit Mewtwo with a High Jump Kick dealing 28 points ofdamage.Magikarp has 70 hit points remaining.Mewtwo has 46 hit points remaining.Choose a move for Mewtwo.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: 2Mewtwo hit Magikarp with a High Jump Kick dealing 30 points ofdamage.Magikarp has 40 hit points remaining.Mewtwo has 46 hit points remaining.Choose a move for Magikarp.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: 2Magikarp hit Mewtwo with a High Jump Kick dealing 28 points ofdamage.Magikarp has 40 hit points remaining.Mewtwo has 18 hit points remaining.Choose a move for Mewtwo.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: 2Mewtwo hit Magikarp with a High Jump Kick dealing 26 points ofdamage.Magikarp has 14 hit points remaining.Mewtwo has 18 hit points remaining.Choose a move for Magikarp.1. Tackle2. High Jump Kick3. Desperate Blow4. Slack OffEnter your move: 2Magikarp hit Mewtwo with a High Jump Kick dealing 18 points ofdamage.Magikarp won the fight.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] SOLVED: implementing the game hangman Solution
$25