![]() |
Create a function called game_over() and make sure it is called whenever either Pacman moves or when a ghost moves. This function will detect whether the game has finished and, if so, will react accordingly. The function can be empty for the time being - we will fill it later! |
How do we know when the game is over? Well, for a start, if there are no pills left in any squares, then Pacman must have eaten them all and the game is won!
![]() |
Create a function called all_pills_gone() which counts how many pills there are left on the board and returns the numbers. When this number drops to 0, all the pills have gone! |
Now we start filling the function game_over().
![]() |
Insert a call to the function that you have just created. If the number of pills is 0, display a message stating that the player has won the game (an alert() instruction is the best way of doing it).
Create a loop that examines the position of each ghost in turn. If Pacman and any ghost occupy the same square, then display a message stating that the player has lost! |
When the game is over, the easiest course of action is to reset the game to its original state and then start it again. This is made easier as, in the first section of this assignment, you created the routines that set up the variables and display the screen in a modular fashion. However, we need to display some sort of message first, so that the player will know what is going on.
![]() |
Add a sentence to the messages displayed previously to the effect that the game is about to start again, and that the player should simply close the browser window in order to stop the game. As soon as the OK button on the alert() box is pressed, the game should restart. |
There, that's it! A rather simple, but perfectly functional, version of Pacman.
Pacman menu