Okey... It's so f*ckin' weird that none can't see my mistake! I will try to explain again.
I'm creating Snake's clone. My app have too classes:
Snake.java and
Board.java.
Right now I have three problems:
1) There are two constants -
BOARDS_WIDTH,
BOARDS_HEIGHT. They are meant to be dimensions for playground where snake moves and collects apples. It's dynamic (thanks to
kieve) and I can set them as I want. For example 640 x 480, 160 x 160 or whatever. Only thing I need to keep in my mind is that both numbers must divide with 16. Why? Because constant
UNIT is set to 16 x 16 and, for example, when board's dimensions are set to 160 x 160, it means that there would be 10 x 10 units large playground (160 / 16 = 10). Problem: playground is always two pixels (not units) larger than it meant to be. Like if I have set dimensions to 160 x 160, actual dimensions will be 16
2 x 16
2! Here are screenshot...

If you measure this image... after pill (apple, if you like) there are two extra pixels.
2) Collisions. I think - it's because problem #1. You see, there are code lines...
1 2 3 4 5
| if( x[0] < 0 || x[0] > BOARDS_WIDTH || y[0] < 0 || y[0] > BOARDS_HEIGHT ) {
inGame = false;
} |
They should prevent snake from going into walls. Actual result is that snake goes few units in the wall - then only the game stops... i want it to stop exactly when snake collide with the wall!
3) How to make snake start to move only when users clicks any of arrows? Right now it's like snake starts to move her body, but her head is stopped. After
joints * DELAY snake's all joints are under her head! Ha, ha...
