C. Algorithmic Code Representation

  1. Include the different libraries necessary
  2. Create a struct which contains information about the player
  3. Create a character class that contains current and prior positions, and direction for the different characters on the screen.
  4. Assign a number value to a direction
  • 0 – North
  • 1 – East
  • 2 – South
  • 3 – West
  1. Create a struct for memory which stores all of the changing information in the game.
  2. The map describes the position of walls, free space, ghosts, oranges, and pac-man
  • 0 – Free Space
  • 1 – Wall
  • 2 – Ghost
  • 3 – Orange
  • 4 – Pac-man
  1. Create a struct to hold a list of players with the their scores
  2. Create a class for the game which holds the different player names, leaderboard, memory, and functions for directions of characters.
  3. Write the function prototypes for displaying the menu, the game, the results, and the board. Also write prototypes for the map rendering, moving the ghosts and moving the pacman.
  4. Start the main function
  5. Set the orientation as north to give the desired orientation
  6. Seed the random number generator
  7. Initialize the game object
  8. Open the menu automatically
  9. End main function
  10. Start openRoute function
  11. Clear the screen and reset colors to default
  12. Run certain functions based on the route
  • Route Types:
    • 0 – Menu
    • 1 – Play Game
    • 2 – Game Session Results
    • 3 – Leaderboard
    • 4 – Instructions/Rules
    • 5 – Credits
  1. Display the different options based on what is chosen
  2. End openRoute function
  3. Start the displayMenu function which renders the menu and responds to touches
  4. Set the number of options and text to show
  5. Draw vertical bounding lines for the menu
  6. Draw horizontal bounding lines for the menu
  7. Write out the options to the screen
  8. Wait for the user to touch something
  9. Record a touch and proceed after the finger has been removed
  10. Determine which option the user touched
  11. End the displayMenu function
  12. Start the displayPlay function which renders the game, responds to user interaction, and time-based changes
  13. Set up the map using the specification listed in the Memory struct
  14. Copy the default map into memory
  15. Each free space has a 40% chance of containing an orange
  16. Initialize all of the characters
  17. Store the characters to memory
  18. Initialize game state variables
  19. Initialize the time and touch variables
  20. Stop if the game has ended
  21. Change the UI to reflect the map in memory
  22. Wait for a user touch or a game tick
  23. If the event was a user touch, set the initial touch position
  24. Then set the final touch position
  25. Detect swipes via displacement of initial & final touch
  • Conditions:
    • Initial touch on map
    • Swipe must be at least 15 px
  1. Check if east, west, north, or south swipe
  2. Detect 6 buttons at the bottom of the screen
  • Buttons:
    • Toggle pause
    • Left
    • Up
    • Down
    • Stop
    • Right
  1. Reset the start time
  2. Move the ghosts randomly
  3. Move pacman in the specified direction
  4. Check if oranges remain on the board
  5. If there are no oranges, then the player wins and the game ends
  6. End the displayPlay function
  7. Start renderMap function
  8. Change each map square based on its type
  • All map squares are 20px by 20px
  1. Draw a black box for free space
  2. Draw a white box for a wall
  3. Draw ghosts
  4. Draw pacman
  5. Draw the buttons at the bottom of the screen
  6. Start the modCoord function to modify the coordinates based on the direction
  7. End function
  8. Start the checkDirection function to check if the direction is off the board or a wall
  9. End function
  10. Start the onlyDirection function to check if the backwards direction is the only direction
  11. Loop through each direction to check
  12. Start the moveGhosts function to randomly move the ghosts to new positions
  13. Loop through each ghost
  14. Generate a random direction 0 to 3
  15. Reset the x and y coordinates to the current position
  16. Modify the x and y to the new coordinates
  17. If the direction is off screen or to a wall, regenerate a direction
  18. If the direction is backwards and it is not the only direction, regenerate
  19. Set current position to prior
  20. Update the memory variables
  21. Remove the ghost from the prior position
  22. Add the ghost to the new position
  23. End function
  24. Start movePacman function
  25. Set the x and y positions as the current ones
  26. If the new position is valid, change the coordinates
  27. Store the new positions to memory
  28. Remove pacman from the prior position
  29. Add the ghost to the new position
  30. End function
  31. Start displayResults function which renders the results of the game
  32. Display text based on game outcome
  33. Display the number of points earned
  34. Prompt the user to pick a name
  35. Write all of the professors & TAs to the screen
  36. Record a touch and proceed after the finger has been removed
  37. Detect pressing the professors and TAs, then proceed to the leaderboard
  38. End function
  39. Start displayBoard renders the leaderboard
  40. Display title and instructions
  41. Display the name and points of each professor and TA
  42. Record a touch and proceed after the finger has been removed
  43. Open the menu screen
  44. End function
  45. Start displayRules which explains how to play
  46. Write instructions to screen and continue if screen is tapped.
  47. End function
  48. Start displayCredits to attribute to the developers and rescources
  49. Write the instructions to the screen and continue when the screen is tapped
  50. End function