Algorithm

SDP Algorithm:

  1. Define class highscores to store top 5 high scores.
    1. Array that stores high scores
    2. Constructor that initializes array to 0 using a for loop
    3. Function minreplace that looks for the lowest value in the array using for loops and replaces it with the latest game score if game score is higher
    4. Function highscoresort that sorts high score array from highest to lowest using a bubble sort algorithm
  2. Declare functions
    1. MainMenu: displays main menu
    2. PlayGame: controls actual gameplay
    3. touch: checks for touch on main menu
    4. instructions: displays instructions
    5. highscore: displays high scores
    6. quit: displays quit screen
    7. credits: displays credits
  3. Create global object highobject for class highscores
  4. In main function, call main menu function
  5. In void MainMenu()
    1. set background color and font color
    2. display different options
      1. Credits
      2. Instructions
      3. Gameplay
      4. High scores
      5. Quit
    3. Draw horizontal lines separating options
    4. Call touch function
  6. In void touch()
    1. Declare variables for x and y positions and have while loop that checks for touch while int i=0
    2. Use an if else statement inside the while loop that calls the corresponding function depending on where the user touches. Set i=1 if a function is called.
  7. In void instructions()
    1. Write instructions to screen in scarlet colored font
    2. Go back to main menu by calling MainMenu() if screen is touched
  8. In void PlayGame()
    1. Declare variables int w=60, h=40, color, x_pos, y_pos
    2. Initialize gamescore, createrectangle, and count to 0. Initialize float speed to 1
    3. Display epilepsy warning
    4. while loop while createrectangle==0
      1. do while speed<3
        1.  if count mod 5 is 0, add 0.1 to speed
        2. randomize x coordinate from 0 to 259 and set y coordinate to 0
        3. while touch is 0 and y coordinate is less than 240
          1. Fill rectangle in color white to cover up previous instance
          2. Randomize color using Switch Case
          3. Add speed to y coordinate
          4. Fill rectangle using random color
          5. Check for touch inside rectangle
            1. If true, add 100 to gamescore, add 1 to count, and set touch to 1
            2. Display gamescore on top right
          6. If y coordinate becomes 209, change createrectangle to 1 to exit while loop
          7. Clear screen and display gamescore
          8. Call class functions minreplace and highscoresort using object highobject.
            1. Send gamescore to minreplace and highobject.top5scores to highscoresort
          9. Call main menu if user touches the screen
  9. In void highscore(int hs)
    1. Display high scores using highobject and variable top5scores
    2. Take back to main menu if user touches screen
  10. In void quit()
    1. Display message to turn off Proteus
  11. In void credits()
    1. Display credits
    2. Call main menu if user touches the screen