D. Final Algorithm, Flowchart, or Pseudocode

Connect 4

  1. Ask if the user wants to play connect 4. The user input must be either 0 to quit or 1 to play. If the user enters anything else, display a message saying invalid input and keep asking until a valid input is given using a while loop.
  2. If the input is 1, display a welcome message and continue to the next step. If the input is 0, display a goodbye message and end the game.
  3. Ask for player 1 and player 2 name and store them in player_1 and player_2.
  4. Create the board for the game using the simple game engine
  5. Create three different variables to hold the two different chips and one to keep track of empty spots.
  6. Display the board created (empty) which is 6 x 7.
  7. Create two more variables; color and winner to keep track of each player’s color and keep track if a winning situation is found or the board is full.
  8. Using get mouse input function have player 1 choose the location.
  9. If the first choice is not in row 6, show an error message and tell the user to click in row 6 for their choice. 
  10. Once the player 1 makes select a spot, display a red chip in that spot and display the board with the added chip. 
  11. Set up a while loop with the condition of winner == 0 which is simply no winner has been determined.
  12. Check if color is 1 which is color for red chip and player 1. If it is true, go the next step. If not go to step 16.
  13.  Allow player 1 to choose a position on the grid.
  14. Check if the position is empty using the empty_sprite. If it is, show an error message saying “choose an empty sprite”. If not go to the next step.
  15. Using switch statements, determine the lowest possible location for the chip and drop the chip in that location and draw the board/scene.
  16. Then assign a color to 0 to make sure next time is player 2 (black chip) turn. The following if statement will assign color back to 1 to get back to player 1 (red chip) turn as well. 
  17. Set up four for loop to check whether the horizontal, vertical, and two diagonal directions have four consecutive patterns. 
  18. Once the chips of a certain color meet the conditions, set winner == 1 and jump out of while loop and display a message to show the winner is born. 
  19. The last if statement represents a special condition, where the board is full of chips but no winner appears. The game ends with a draw.

 

      MEMORY

  1. Display a welcome message and ask if the user wants to play the memory game. 
  2. Store the input in playedBefore variable.
  3. Using a while loop to check if the input is anything other than 0 (user doesn’t know how to play) or 1 (user knows how to play the game). If it is, keep asking until a valid input is given. If not continue to the next step.
  4. If the input is 0, display the rules and add pause so that the user has a chance to read and understand the rules. Then continue to the next step. If the input is 1, go to the next step.
  5. Create a scene using a simple game engine.
  6. Create variable empty_sprite to be used for vector creation.
  7. card_spritesFace holds a vector for cards.
  8. Create a counter to be used while creating cards.
  9. Using a while loop, create 52 cards (backFace).
  10. Create 4 rows with 13 cards.
  11. Create a variable cardDuplicate to flip the wrong guess back to face down
  12. Create numGuesses to keep track of the number of guesses. 
  13. Create a vector with 52 cards.
  14. Create two different vectors and randomize it with the first 26 cards. 
  15. Join both vectors and display the board.
  16. Using a while loop with conditions endLoop ~= 52 allow user to start clicking on cards.
  17. The user selects one card. Then the user selects another card.
  18. If user clicks on a card that is already face-up show an error message and tell them to choose another card. 
  19. When user selects two cards, check if the value of each card is the same. If they are the same, go to the next step. If not, display a message “not a match try again” and turn the cards back face down and increment numGuess and go back to step 17.
  20.  Show a message saying you found a match and increment numGuess by 1 and keep those two cards face up. Then go to step 17 and the process is repeated until all cards are face up.
  21. When all cards are face-up, display a message saying “you won the game, congrats”. 
  22. Then display the numGuesses. 

 

     Hi-Low Seven

  1. Display a message asking the user if they have played over/under seven before.
  2. If the user inputs an invalid response, display a message saying “Invalid input, you must enter 0 or 1!”, If not, go on to Step 3. 
  3. If the player inputs yes they have played before, go to Step 5, If they input no they have not played before, go to Step 4.
  4. Display a message explaining the rules of Over/Under Seven.
  5. Display a message with the amount of money the player has to bet.
  6. Display a message asking if the user wants to play
  7. If the user wants to play, go to Step 8, If the user does not want to play, display a message saying, “Maybe next time. Goodbye!”.
  8. Display a message asking the user to input an amount to bet.
  9. If the user inputs a valid bet, go to Step 10, if the user inputs an invalid bet, display a message saying, “Your bet must be between 0 and 100 dollars” and go back to Step 8.
  10. Ask the user if they want to place their bet on High, Low, or sevens.
  11. Generate a sum for two randomly rolled die.
  12. Display a message saying what the sum of the two dies is. 
  13. If the player’s bet High (>7), Low (<7), or Sevens (=7) matches the sum of the die, display a message saying “You won (bet amount) dollars”, if the players bet does not match the sum of the die, display a message saying “You lost (bet amount) dollars”. Go to Step 16.
  14. If the user bets Sevens and the sum of the dice is 7, then the user’s earnings are the bet amount multiplied by 4.
  15. If the player earns money to add it to their total and if the user loses money subtract the amount from their total.
  16. Ask the user if they want to play again.
  17. If the user inputs yes, go to Step 8, if the user inputs no, display a message saying “Thank you for playing. Goodbye!”.
  18. If a player runs out of money, display a message saying “You ran out of money! Better luck next time!”.
  19. End