C. Program Description for Developers

Program Description for Developers

 

In programming of Hangman, there were many different commands used.  It begins with a ‘while’ loop to keep the game going as long as the player wants. Next, a list of 50 words is imported using the ‘importdata’ command.  Next, a word is randomly selected from the list of words using the command ‘randperm.’ That word is then converted into an array of letters that make up the word using ‘char’.

The game display is set up next, using ‘fprintf’ statements to print out the gallows for the hangman. A welcome statement with instructions is also printed out using ‘fprintf.’ Next the length of the random work is printed out in words and with using question marks to represent each letter of the word. This is done using the command ‘length’ and a ‘for’ loop.

After the display setup, another ‘while’ loop is used for displaying certain things based on what the user inputs for their guess. Within this while loop is an ‘if’ statement. As long as the user has guessed less than six times, the user will be asked to guess a letter, using the ‘input’ command. Inside the ‘if’ statement is a ‘for’ loop for when the user’s guess is correct. There is another ‘if’ statement inside that ‘for’ loop in order replace one of the displayed question marks with the correct guessed letter.

After the ‘for’ loop is ‘if’ and ‘elseif’ commands with six options. These are used to display anther body part on the hangman picture for each wrong guess. ‘fprintf’ statements are used to print the gallows and hangman, and 1 is added to the variable “tries” after each incorrect guess.

If the user runs out of guesses, a losing statement is displayed, but if the user correctly guessed the word, a winning statement is displayed. These are both done using ‘fprintf’ statements. Finally, using an input command, the user is asked if they want to play again, by pressing 1 for yes, or 0 for no.

The full list of variables used in this code are as follows: answer, flag1, flag2, flag3, flag4, flag5, flag6, guess, i, j, msize, stillplaying, strlength, tries, word, words.