Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Pacman

807597Jan 6 2005 — edited Jan 8 2005
Okay, for my CS project I have decided to write Pacman.
As of now I have several classes:
GameWorld //most work is done here
PacManGUI //GUI portion- utilizes JFrame, JPanel, JLabel[][]
Driver //nothing special
PacMan //just for my ease, not necessary
Location // has an int row and int col, with getRow(), and setRow(), etc.
Locatable //interface with getLoc() and setLoc() which set and get Locations

The way I have it setup is:
I read in the level from a text file.
I create a char[][] with text from the file, which I pass on to my GUI class.
In the GUI class, I cycle through the char[][], creating a JLabel[][], containers for pictures. I load each picture depending on the character:
thus 'p' will load "pacman.gif" and w will load "wall.gif"

This is where I am right now: PacMan can move around and "eat" the dot things. (Motion via keys and KeyListener) Now I am ready to add in Ghosts to the game(the enemies). What I need to create is some sort of way for the Ghosts to chase after PacMan. Is a recursive sort of solution the right idea? The Ghosts must follow the same constraints of PacMan- cant go through walls, only can move up,down,left, and right

I can make a Ghost class that implements Locatable and I can figure out where PacMan is at any given time. Any ideas on how to write this sort of method would be greatly appreciated. Also any suggestions about design issues would be appreciated. I highly doubt using a matrix of JLabels is the best way, but I only know limited GUI. Thank you sincerely.
-----------------
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 5 2005
Added on Jan 6 2005
6 comments
404 views