wood burning stoves 2.0
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help With Snake Game" Watch "Help With Snake Game" New topic

Help With Snake Game

Amil Mehmedagic

Joined: Feb 27, 2004
Posts: 22

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

Amil Mehmedagic

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
It's not a secret anymore!