The PacMan The original PacMan game was developed in 1980 in Japan and is still one of the most favorited computer and arcade game. Our example only shows a simple variation of the original. Some PacMan variations are played against four ghosts (Pinky, Blinky, Inky and Clyde) and move through different worlds.
|
![]() |
Explaining the program code:
The implementation consists of four classes: the application class PacMan.java, the actor classes PacActor.java and Ghost.java and the class PacManGrid.java, which is needed the layout the background.
The class PacManGrid builds a labyrinth in the backgorund of the game grid. Its grid has 30 horizontal and 33 vertical cells which are either walls, paths or paths with pills. Layouting the background is hard work. The less symmetric the labyrinth, the more difficult the layout prozess.
The class PacActor implements a GGKeyListener which registers the players key events. The method canMove() makes sure that the PacMan only moves on the gray cells. The method eatPill() hides the eaten pills and the method act() lets the PacMan's mouth open and close (changes the Sprites).
Both ghosts are instances of the class Ghost. They only differ in their pursuit strategies, which are defined in the method moveStrategy() and depend on the ghost type.