C. Program Description for Developers

Blackjack
The game is a full, interactive GUI. You start the game by pressing on the red “Play Game” button. The code generates an array of values from 1 to 52. A folder of images contain names that correspond from 1 – 52. Each number represents a specific card. Two numbers are randomly chosen using the randi() function. Once the card gets dealt, it is removed from the available cards array and placed into the dealt cards array to ensure the same card isn’t randomly chosen twice. The dealer gets two random cards as well. The cards are displayed to the GUI using the imshow() command. If the user hits the “Hit” button, another card will be dealt using the process described above. If the user hits the “stand” button, the dealer with continue to hit if the sum of the dealers cards is less than 17, at which point the dealer will stop hitting. The game will go through a multitude of if statements to determine the winner. If/else statements are used for multiple functions of the game. For example, these are used to determine what happens to a player based on their score, which means that they cause him/her to lose if their score goes over 21, and dictates whether he or she wins or loses against a computer by comparing the scores of the two players. Switch statements determine the player and dealer’s total. While loops are used for when the user wants to hit, and they prevent the same card from being drawn twice.

Variables:
cards – array of card image locations
availableCards – array of card ID numbers, 1-52
randomElement – random elment chosen from a random number in availableCards array
playerCards – array of player cards; contains card’s ID numbers
dealerCards – array of dealer cards; contains card’s ID numbers
dealtCards – array of dealt cards; contains card’s ID numbers
playerSum – total sum of player’s cards’ values
dealerSum – total sum of dealer’s cards’ values
imgFile – file location of the playing card
img – specific image object
ax – axes to display card in proper location
w/won – audio object; winner
l/lost – audio object; loser
soundOn – variable to determine if sounds should be played
wallet – wallet value
curWalletVal – current wallet value/handle
newWallet – diplays after bet is won/lost
totalWallet – handle to keep value consistent
currentBet – current bet value
aceHit – dealing with two aces displaying at the same time

Functions
str2double() – converts a string to double
strcmp() –  compares two strings
strcat() – joins two string
length() – length of a vector
randi() – random number
char() – converts to character
imshow() – displays an image
set() – sets handles in GUI
get() – gets handles in GUI
audioread() – loads in a audio file
audioplayer() – loads the audio file into the player object
find() – finds the handles in a GUI
axes()- changes axes for imshow()
subplot() – plots the cards in a grid
importdata() – imports cards into an array of file locations
msgbox() – displays messages about the current state of the game

 

Over Under

  1. The program loads a pre-made zipfile with the dice program
  2. The user is asked how much money that they would like to make available to bet using an input statement
  3. The program uses an if statement making sure that the user may only play if they have money to bet
  4. The program then asks if the user would like to to play using an input statement
  5. Using another if statement, the game only allows the user to play if they have money and wish to continue playing
  6. Using an input statement, the program asks how much of the money available the user would like to bet on that round.
  7. The next step is another input statement that asks what the user believes the dice are going to roll.
  8. The program then uses a randi function to randomly generate the roll of the dice every round
  9. The program will go into another if statement saying that if the user entered the correct bet, they will be paid 1:1, if they are wrong on their bet, they will lose the money bet that round.
  10. After each round the game will ask the user if they would like to play again as long as they have money available to bet.
  11. Once the user chooses to leave the game or has run out of money, the game will tell the user how much the users total winnings or losses were.

 

Variable list

money – Contains all of the money the user is able to bet

ogMoney- Contains the original amount of money that the user started with

answer- contains the response of the user to see if they would like to play/ play another round

totalmoney- all the money that the user has once that they are done with the game

h- used to store the image of the dice that were rolled

bet- The amount of money that the user would like to bet for that round

bet2- records what the user thinks the dice is going to roll, over, under, or seven

roll- where the generated roll of the dice are stored

totalroll- used to add the two die together to figure out the total of the roll

totaldiff- contains the original amount that the user started with and sees how much the user gained or lost

totalmoney- contains the total amount of money that the user has once they have the game





Hangman
The game uses an interactive GUI that launches when the program is run. The game will start when the start button is clicked. When the game starts, a random number is generated that will determine what word or phrase will be chosen ranging from 1 – 35. After the word/phrase is chosen it is stored in an array. To create the word that will be displayed as blanks, an if else statement is used with a for loop to replace each letter with a dash “-”, while keeping underscores to separate multiple words if they are present. The result is stored as the display word. The word is displayed on the array using handles to edit text boxes. Since the full hangman will have six parts, the user is limited to 6 outs. The code keeps track of the count using a while loop. In addition to this, if else statements are used to determine how many outs there are and what image should be displayed to correctly inform the user. An image is loaded as a graph and is modified to remove axis. This is updated every time the number of outs changes. While the player still has outs remaining the code will wait for user input. The gui has a keyboard that the user can click on to chose a letter. When a letter is chosen that letter is assigned to a variable and that button is temporarily disabled to avoid clicking it again. A for loop is used to evaluate the letter in the variable. It compares it to each letter in the word, and replaces the appropriate dash in the display if it it present in the word. After the letter is checked it will subtract an out if it was an incorrect guess. The program will then wait for another input to repeat the process. To determine if the player has won, the display word is compared to the actual word. If they are identical the program will use handles to display winning text onto the gui as well as buttons to play again or quit. If the player runs out of outs handles are used to display a losing screen with the same buttons as the winning screen. If the player clicks play again, the program will clear all the variables then proceed as if the start button was pressed.

Variables
WordDis – The displayed word that will change with user input
Word – The randomly selected word
Words – the list of word to be chosen from randomly
I – Used to ensure an out is not subtracted on a correct guess
k – Is assigned as the length of the word to be used in for loops
M – see above
num – randomly generated number to determine Word
Outs – the count of how many guesses the user has left
str – is directly changed by user input and stores the letter they guessed
Win – the sum of the logical array that results from comparing “Word” and “WordDis” and used to determine if the player won
Hangman – The hangman image that corresponds to the number of outs

Functions
randi() – generate random number
length() – calculates the length of a vector
set() – sets GUI handles
imread() – loads an image
sum() – Generates the sum of an array
char() -converts into character(s)
image() – displays stored image
axis() -changes axis
uiwait() – waits for user input