C. Program Description for Developers

Hangman:

Description of program:

The program starts by clearing the memory and the command window. Then, the program defines 2 counting variables, one is used to keep track of incorrect guesses, the other is used to keep track of the hangman sprite. The program then sets up the initial scene. After this, the program runs a while loop that prompts the first user to enter a word until a valid response is entered. The first check uses a for loop to check if each letter of the response is a valid character. The next check uses an if statement to check the length of the response. After the program exits the while loop, the program creates an empty array that is used to store the correct guesses. This array is the same length as the first user’s guess. The program then runs a for loop that draws dashes into the scene. After this, the program runs a while loop that prompts the second user to enter a letter until a valid response is entered. The check uses a single if else statement to ensure the response is a letter and is a single character. Once the user enters a valid response the program exits the while loop. After this, the program starts another while loop that continues to run until the second user runs out of guesses. The while loop starts by defining a variable used to check if the guess was incorrect. After this, a for loop is used to check if the guess is correct. If the guess is correct, the program updates the scene, updates the empty array, and  updates the check variable. After this, an if statement updates the guess counter and hangman graphics if the guess was incorrect. Then, another if statement checks to see if the array matches the first user’s word. If the two are identical, the program breaks the while loop and displays a message saying the second user wins. The program then prompts the second user to input another guess using a while loop that is identical to the earlier one. Once the program exits the while loop, the program uses an if statement to check if the incorrect guess counter is equal to its maximum. If it is, the program updates the graphics and displays a message saying the first user wins.

Variable list:

  • b – This variable is used to tell the program whether or not each guess is correct.
  • c – This variable is a variable that stores the number of incorrect guesses.
  • gar1 – This variable stores the second user’s guess.
  • gar2 – This variable stores the lowercase version of the second user’s guess.
  • hangcount – This variable is used to keep track of the sprite position of the hangman’s components.
  • i – This is an arbitrary index variable used in the program’s for loops.
  • scene – This variable stores the sprite information.
  • var1 – This variable stores the first user’s word.
  • var2 – This variable stores the lowercase version of the first user’s word.
  • varL – This is an array that stores the second user’s correct guesses.
  • window – This array stores the sprite information for each position in the scene.
  • x – This is an arbitrary check variable used in a while loop.
  • y – This is an arbitrary check variable used in a while loop.

Over/Under 7:

This program starts by setting both of the dice values equal to 1. Then, the program sets up the scene and draws the initial graphics. After that, the program starts a while loop that continues to run until the user inputs a valid response.  It does this by changing the value of a check variable once the user inputs a valid response. The program then generates 2 random dice values and stores them as separate variables. After this, the program adds the 2 values together and stores the total as a separate variable. The program then enters a while loop that draws random dice values 20 times every 0.1 seconds. After this loop, the first dice sprite is drawn to match the real value. The program then starts another while loop that draws random dice values for the second dice 40 times every 0.1 seconds. After this loop, the second dice sprite is drawn to match the real value of the second dice. The program then defines 2 variables that store the win and lose messages. The program then uses an if elseif else statement to check which dice condition is true, then prints the appropriate message based on the user’s guess.

Variable list:

  • dice1 – This variable stores the value of the first dice.
  • dice2 – This variable stores the value of the second dice.
  • framecounter – This variable is used to keep track of how many times the dice animation draws a frame.
  • guess – This variable stores the user’s guess.
  • lose – this variable stores the loss message.
  • scene – This variable stores the sprite information.
  • spriteArray – This array stores the sprite information for each position in the scene.
  • total – This variable stores the sum of the two dice values.
  • valid – This is check variable that changes when the user inputs a correct response.
  • win – This variable stores the win message.

MATLAB game commands:

  • simpleGameEngine() – This command sets up the sprite information based on a sprite sheet, the height and width of the sprites, and a scale factor.
  • drawScene() – This command draws or updates the graphics based on the     scene variable and an array of sprite information.

References: 

Ohio State Fundamentals of Engineering Program, “simpleGameEngine.m.” [Course documentation]. Available: carmen.osu.edu for ENGR 1181. [Accessed Nov. 13, 2019].