Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help With Snake Game

 
Amil Mehmedagic
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stefan!

This is precisely what I wanted to accomplish! And thankx for the debug code too!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic