Ok, so the problem is, like i said, the KeyListener. I did some research and seams like KeyListener dose not work on JFrame, its something about the components and foucs(only the component with the...
Type: Posts; User: RigaCrypto
Ok, so the problem is, like i said, the KeyListener. I did some research and seams like KeyListener dose not work on JFrame, its something about the components and foucs(only the component with the...
Yeah, i dont know man, you are of no help to me. Im new to this, like watching tutorials on youtube new, and i try to do what you tell me, but then i get more erors. It seams to me that you dont try...
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import...
Done, apple spawn only once. Checked every method with println, they work. No erors. Still the snake does not move when i press keys, i'm pretty sure it has something to do with the KeyListener, but...
It's suposed to be a snake game. I said at first that the snake (green squares) does not move, and apples (red circles) are spawned everywhere. Do you realy not know what a snake game is? The green...
2876
2877
Any luck?
If you mean a runnable jar, here it is:SnakeGame.jar
the program runs, the snake is there but it dose not move when i pres key, and apples are spawning everywhere
Here is move method:
public void move()
{
if (direction ==...
Yeah, i called the method before the initialization of global graphics so that gave me massiv eror. Now all is good. No erors, but still apples spawn every where and snake dose not move...
I have a globalGraphics variable.
Declaration:
private Graphics globalGraphics;
Initialization(see in paint()):
globalGraphics = g.create();
draw(globalGraphics);
public void run() {
while (true) {
GenerateDefaultSnake();
move();
draw(globalGraphics);
repaint();
try
{
Thread.currentThread();
Ok so now the problem is with the draw method:
public void draw(Graphics g)
{
g.clearRect(0, 0, BOX_WIDTH * GRID_WIDTH + 10, BOX_HEIGHT * GRID_HEIGHT + 20);
BufferedImage buffer = new...
public void paint(Graphics g)
{
this.setPreferredSize(new Dimension(640, 480));
GenerateDefaultSnake();
PlaceFruit();
globalGraphics = g.create();
this.addKeyListener(this);
if...
It's the same error message as above.
Same thing hapens
So line 85 is:
Point head = snake.peekFirst();
The declaration of the variable:
private LinkedList<Point> snake;
The initialization of the snake variable in paint method + snake generator: ...
Hi, im new to this and i tried to make a runnable snake game. When i try to run my code i get this:
Exception in thread "main" java.lang.NullPointerException
at Game.Move(Game.java:85)
at...