D. Final Algorithm, Flowchart, or Pseudocode

BlackJack: Pseudocode

General setup: Player versus computer. Computer is dealer. There are a total of 52 cards (1 of each type):

  • Card Type:

 

  • Spades: Ace, King, Queen, Jack, Cards 1-10.
  • Hearts: Ace, King, Queen, Jack, Cards 1-10.
  • Diamonds: Ace, King, Queen, Jack, Cards 1-10.
  • Clubs: Ace, King, Queen, Jack, Cards 1-10.

 

  • Card Value:
  • Cards 1-10 worth their numerical values.
  • Kings, Queens, and Jacks are worth 10.
  • Ace cards are worth either 1 or 11 points.

 

  1. Title page and music.
  2. On the top right corner of each screen (title page and in game):
    1. If user presses sound symbol (speaker), music is turned off, symbol changes to an x over speaker.
    2. If user presses sound symbol with x, music turns on and reverts its symbol.
  3. User clicks ‘start’ button on title page.
  4. The program will do the following when initiating first turn:
    1. Two cards dealt to both player and computer.
    2. On the computer end, one card is face up and the other remains face down. For the card that is face up, its points are displayed (only first element from its array is used for the points).
    3. The player’s cards are shown face up on the player’s end along with their points.
  5. The program calculates the current amount of points based on the cards.
    1. Points are stored in two arrays: 1 for player, 1 for computer.
    2. The arrays begin with two elements; each for holding the initial card values.
    3. The values at each element are added and displayed on screen for both player and computer.
  6. If the computer begins with an ace and a 10 value card as dealer on the first turn, the computer will automatically win.
  7. As long as the prerequisites are not met for step 6, then the player has 1 of 2 options:

a.) Hit

b.) Stay

    8. If player chooses ‘Hit’, then they receive an additional card whose value is pushed back into the array (creates a 3rd                  element) and the card faces upwards.

    9. If the player score is greater than 21, they will automatically stay. A ‘break’ message will appear on the player end.

   10. If player chooses ‘Stay’, then the computer will do the following:

          a.) If computer card values are less than 17, the computer will keep ‘hitting’ until their values are greater than 16.

          b.) If computer card values are greater than 16, they will stay with their card values.

          c.) If computer score is greater than 21, a ‘break’ message will appear on computer end.

    11. Both the player and computer have boolean values that determine if they can still hit or stay:

         a.) If player pushes ‘stay’ then player value becomes false, making the addition of the array points static.

         b.) Similarly, once the computer stops drawing cards, their value becomes false and its addition of array values become static.

  12. So long as either player and computer have total points between 1 and 21, the following occur:

        a.)If player points are greater than computer points, then the screen displays, “PLAYER IS THE WINNER!”

        b.) If computer points are greater than player points, then the screen displays, “COMPUTER IS THE WINNER… :(“

  13. Another interactive button pops up underneath either message, “Click anywhere to continue.”

        a.) If user clicks the left mouse button, then they program reverts to the title screen (step 1).

 

Hangman: Pseudocode

General set up: Player one picks a word and player 2 tries to guess the letters

 

Assumptions:

  1. Players already know how to play hangman
  2. Player 1 and player 2 are already chosen

 

  1. Start
  2. Welcome page pops up
  3. Player 1 enters a word or sentence
  4. Player 2 enters a letter
  5. Check if letter/sentence is in player 1’s word

a.) If not

              i) If there are no strikes

                 (1) Decrease amount of guesses to 5

             ii) If one strike

                (1) Decrease amount of guesses to 4

            iii) If two strikes

                (1) Decrease amount of guesses to 3

            iv) If three strikes

               (1) Decrease amount of guesses to 2

             v) If 4 Strikes

               (1) Decrease amount of guesses to 1

           vi) If 5 strikes

              (1) Draw arm two

              (2) Display a sorry you lost message

              (3) Display the word

              (4) Go to step 9

b.) If it is

          i) Add letter to blank word

6. Check if word is completed

       a.) If it is, go to step 8

       b.) If not, go to step 6

7. Ask user if they would like guess the word

       a.) If yes, ask user for name

       b.) Go to step 5

       c.) If not, go to step 4

8. Display congratulations

9. Stop

 

Dice: Pseudocode

  1. Ask user how much money they will like to add
  2. Ask the user how much money they will bet.
  3. Ask user to guess if dice will roll below 7, exactly  seven, or above seven,
  4. Roll dice
  5. Check how much money they have

a.) If greater than zero

              i) Ask if they want to end the game

                (1) If yes, go to step 6

                (2) If no, go to step 2

         b.) If exactly zero

              i) Go to step 7

6.) Congratulate the player for winning amount they won

7.) Tell the player “Sorry, you lost”