Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using matlab: function draw_hangman( misses ) This function has no outputs and one input: the number of times a player has answered incorrectly. Unlike most

Using matlab:image text in transcribed

function draw_hangman( misses )

This function has no outputs and one input: the number of times a player has answered incorrectly. Unlike most functions, this function computes no values, but is simply a nice way to draw the hangman board so that we can see the status of the game. There should be 9 different "drawings". The first is of the empty hangman stage (0 incorrect answers). The last is when Game is Over, which is used for 8 incorrect answers. If any number not from 0-8 is given to the function, you should use the error function to stop the program.

Coding Hint 1: When you first write this function, you should eschew (avoid) any fancy ASCII art, and simply print out the number of mistakes (as a number), until you have the rest of the program running correctly.

Coding Hint 2:You should use the fprintf statement (many times) and the if and elseif statements. Your own artistic merit can be used to design the ASCII art to show the status of the game.

 % Here is an example of the "output" (not returned value, but printed to the % screen) of the draw_hangman function, given different inputs: >> draw_hangman(0) | | | | ----- ----- >> draw_hangman(1) |--- | | | ----- ----- >> draw_hangman(2) |--- | 0 | | ----- ----- >> draw_hangman(7) |--- | 0 | -|- | / \ ----- ----- >> draw_hangman(8) RIP Game Over ----- 

Copy the Function Design Pattern into the draw_hangman function. Create a drawing for 0 mistakes. Initially, for 1 through 8 mistakes, simply print the number of mistakes!

3. function valid word) The valid_word() function takes in one parameter (a string) and returns a boolean. It returns false if the word has any non-letter characters (punctuation, etc) in it, or if it is shorter than 5 letters, otherwise true. You should loop over all the characters in the word and check to see if they are greater than or equal to 'a, and less than or equal to z. You can use 'a' and 'z' as part of your if check. Remember that you should lowercase the word before making this check. Here are some examples of use: >> word = 'Hi'; % too short >> valid_ word( word) ans-0 % Remember that 0 means false to the computer. But as a programmer we always % use true / false, NOT 1 / 0 !! ! >> word-Amendment'; % good >>valid_word( word) ans = 1 >> word = 'office."; % has punctuation, therefore bad. >> valid_ word( word) ans 0 3. function valid word) The valid_word() function takes in one parameter (a string) and returns a boolean. It returns false if the word has any non-letter characters (punctuation, etc) in it, or if it is shorter than 5 letters, otherwise true. You should loop over all the characters in the word and check to see if they are greater than or equal to 'a, and less than or equal to z. You can use 'a' and 'z' as part of your if check. Remember that you should lowercase the word before making this check. Here are some examples of use: >> word = 'Hi'; % too short >> valid_ word( word) ans-0 % Remember that 0 means false to the computer. But as a programmer we always % use true / false, NOT 1 / 0 !! ! >> word-Amendment'; % good >>valid_word( word) ans = 1 >> word = 'office."; % has punctuation, therefore bad. >> valid_ word( word) ans 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Principles Of Database Systems With Internet And Java Applications

Authors: Greg Riccardi

1st Edition

020161247X, 978-0201612479

More Books

Students also viewed these Databases questions