File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Help With Snake Game Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help With Snake Game" Watch "Help With Snake Game" New topic
Author

Help With Snake Game

Amil Mehmedagic
Greenhorn

Joined: Feb 27, 2004
Posts: 22
Hello!

I am trying to get the rat to stop when its centre falls within 5 pixels of the head of the snake. The head of the snake is the first element in an array of 25 snake objects. There's five classes to this application altogether and I am providing the Snake, Rat and SnakeRatPanel classes to help you on this.

I think the problem is in the moveRat method of the SnakeRatPanel class, as it is here where I am controlling the movement of the rat. The condition
to stop the rat when its centre is within 5 pixels of the snake's head
doesn't do anything.

I appreciate your help on this one!
Below are the three classes: Rat, Snake and SnakeRatPanel:
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

I modified it for my taste, and to get a better overview.


Your getX () getY () where without specified object, so 'this' was asumed.
There is no SnakeRatPanel.getX () but a JPanel.getX () and that was called.
I guess you wanted to call rat.getX ();

An additional feature is my real sophisticated debug-code


http://home.arcor.de/hirnstrom/bewerbung
Amil Mehmedagic
Greenhorn

Joined: Feb 27, 2004
Posts: 22
Thanks Stefan!

This is precisely what I wanted to accomplish! And thankx for the debug code too!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help With Snake Game
 
Similar Threads
Stopping Animation
Balls are not moving
Event Handlers:Mouse over "circles"
Help in Algorithm Construction
Non-static variable cannot be referenced from static context