Search:

Type: Posts; User: RigaCrypto

Search: Search took 0.09 seconds.

  1. Replies
    35
    Views
    2,058

    Re: Java SnakeGame

    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...
  2. Replies
    35
    Views
    2,058

    Re: Java SnakeGame

    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...
  3. Replies
    35
    Views
    2,058

    Re: Java SnakeGame

    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...
  4. Replies
    35
    Views
    2,058

    Re: Java SnakeGame

    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...
  5. Replies
    35
    Views
    2,058

    Re: Java SnakeGame

    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...
  6. Replies
    35
    Views
    2,058

    Re: Java SnakeGame

    2876
    2877
  7. Replies
    35
    Views
    2,058

    Re: Java SnakeGame

    Any luck?
  8. Replies
    35
    Views
    2,058

    Re: Java SnakeGame

    If you mean a runnable jar, here it is:SnakeGame.jar
  9. Replies
    35
    Views
    2,058

    Re: Java SnakeGame

    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 ==...
  10. Replies
    35
    Views
    2,058

    Re: Java SnakeGame

    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...
  11. Replies
    35
    Views
    2,058

    Re: Java SnakeGame

    I have a globalGraphics variable.

    Declaration:
    private Graphics globalGraphics;
    Initialization(see in paint()):
    globalGraphics = g.create();

    draw(globalGraphics);
  12. Replies
    35
    Views
    2,058

    Re: Java SnakeGame

    public void run() {
    while (true) {
    GenerateDefaultSnake();
    move();
    draw(globalGraphics);
    repaint();

    try
    {
    Thread.currentThread();
  13. Replies
    35
    Views
    2,058

    Re: Java SnakeGame

    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...
  14. Replies
    35
    Views
    2,058

    Re: Java SnakeGame

    public void paint(Graphics g)
    {
    this.setPreferredSize(new Dimension(640, 480));
    GenerateDefaultSnake();
    PlaceFruit();
    globalGraphics = g.create();
    this.addKeyListener(this);
    if...
  15. Replies
    35
    Views
    2,058

    Re: Java SnakeGame

    It's the same error message as above.
  16. Replies
    35
    Views
    2,058

    Re: Java SnakeGame

    Same thing hapens
  17. Replies
    35
    Views
    2,058

    Re: Java SnakeGame

    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: ...
  18. Replies
    35
    Views
    2,058

    Java SnakeGame

    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...
Results 1 to 18 of 18