C. Program Description for Developers

Over/under program description

-The program begins by initializing the scene using the simpleGameEngine.m, now scenes can be drawn using the variable my_scene

-Next, variables for the sprites are determined. The sprites are taken from the file retro_cards.png, and given a number based on their placement in the array starting with 1 being a blank space, 2 being a blank card, and the 54 cards being in spots 21 through 74

-The card sprites (the 21:74 ones) are then given card values. The number cards 2-10 are given face value, jacks 11, queens 12, kings 13, aces 14, and jokers 15

– Finally, the players win values are set to zero.

-Now that all the game visuals and player values are set up, a welcome message is displayed.

-The actual game is comprised of multiple if/else statements inside a while loop, nested inside of a larger while loop

-The outermost while loop is only in place to check for win conditions and shuffle the deck every turn

-The win check is accomplished using logical operators as the while loops condition and the shuffling is accomplished by creating a random permutation of the numbers 1 through 54

-Next, a nested while loop is created. This is so the game only continues if the player inputs the correct value.

-To get the player to input the correct value, an if statement is used. If the player inputs the correct value the game continues and the player and computers hands are determined by taking the first number in the random sequence and assigning it to its corresponding card value. The same is done for the second number in the random sequence. The first card value determined is the players draw, and the second is the computers. The card values are then stored as player_hand and computer_hand.

-The two variables are concatenated into one variable called combined_hand. This is so both cards can be displayed side by side later on in the code.

-The next stage of the code is to find out who had the higher card. This is accomplished using two if statements. The if statements compare the value of the players hand, and then displays the appropriate message to the player. Inside these if statements is also where the score is increased. If the player’s card is higher 1 win is added to their total and stored in the variable playerWins. If the Computer’s card is higher though, 1 win is added to their total and stored in the variable computerWins. If the value of the two cards are equal no wins are added and the code continues on.

-Next, the code checks to see if the added win makes either the computer or the player have a total of 10 wins. If this is the case then the outer while loop is broken and an end message is displayed. Otherwise, the code continues until one of the parties reaches 10 wins.

-The next part of the code is displaying the card sprites. This is done using the simpleGameEnginer command of draw_scene. The combined_hand variable from before is layered on top of two blank card sprites, and then the scene is drawn and displayed for the player.

-After that, fprintf statements are used to print the value in words in the command window to the player (for example “Jack of hearts” is printed in the command window.) To accomplish this the function file correct.m is called, and the file uses multiple if statements to convert sprite values to character strings for the player to read. For example, if the sprite value is 1 the correct.m changes it into a string that says ‘Ace of hearts’.

-Finally, the player is prompted to either continue, quit, or restart. If the player enters 3 the player and computer’s win values are set back to zero and the game resets. If the player enters 2 the while loop is broken out of and an end message is displayed. If the player enters any other number, the game loops back to the beginning and play continues.

 

Hangman Description for Developers

The two fprintf statements at the beginning of the code show in the command script as the title of the game and tells the user to enter a word for the game. The word=lower input allows the user to enter the word in the command script and lower(word) sets the letters to be lowercase in the script. The next fprintf statement tells the player to guess a letter of the word chosen. A while loop is created so when the player enters a letter that is correct, the letter shows itself in the hidden word and the player guesses another letter. If the letter is guessed incorrectly, it follows the if and elseif statements in the script which plots a section of the hangman. At the end of the while loop, if the letters of the word were guessed incorrectly, the full hangman will be plotted and the word will display itself. If the word was guessed correctly, the fprintf statement will say that the word was guessed correctly.

 

List of Variables

The display(1:length(word)=’*’  keeps the word hidden from the player.

A=find(guess==word) The find function finds if the letter guessed is in the word vector.

Incorrect=incorrect+1 This allows the player to guess again after an incorrect letter is entered.

Linspace creates a vector that is spaced in even increments.

Viscircles creates a circle in the plotted graph.