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