so bin jetzt ein kleines Stückchen weiter mit dem Spiel

jedoch habe ich jetzt ein neues Problem und zwar habe ich jetzt den Code hier
Code: Alles auswählen
import ch.aplu.jgamegrid.*;
import java.awt.Color;
import java.util.ArrayList;
import java.awt.event.KeyEvent;
public class Snake_0 extends GameGrid
{
public Snake_0()
{
super(20 , 20 ,20, Color.darkGray, false);
Snake snake = new Snake();
addActor(snake, new Location(10, 10));
snake.setDirection(Location.NORTH);
addActor(new Mouse(), getRandomEmptyLocation());
addKeyListener(snake);
show();
doRun();
}
public static void main(String[] args)
{
new Snake_0();
}
}
// ______________ Snake ______________
class Snake extends Actor implements GGKeyListener
{
private ArrayList<TailSegment> tail = new ArrayList<TailSegment>();
public Snake()
{
super(true, "sprites/snakeHead.gif");
}
public boolean keyPressed(KeyEvent evt)
{
switch (evt.getKeyCode())
{
case KeyEvent.VK_UP:
setDirection(270);
break;
case KeyEvent.VK_RIGHT:
setDirection(0);
break;
case KeyEvent.VK_LEFT:
setDirection(180);
break;
case KeyEvent.VK_DOWN:
setDirection(90);
break;
}
move();
tryToEat();
return true;
}
public boolean keyReleased(KeyEvent evt)
{
return true;
}
public void initTail()
{
for (int i = 0; i < 3; i++)
{
TailSegment segment = new TailSegment();
gameGrid.addActor(segment, new Location(getX(), getY() + i + 1));
tail.add(segment);
}
}
public void act()
{
if (nbCycles == 0)
initTail();
int lastIndex = tail.size() - 1;
for (int i = lastIndex; i > 0; i--)
tail.get(i).setLocation(tail.get(i-1).getLocation());
tail.get(0).setLocation(getLocation());
move();
}
public void tryToEat()
{
Actor mouse = gameGrid.getOneActorAt(getLocation(), Mouse.class);
if (mouse != null)
mouse.hide(); // seitdem ich die drei Schritte hier eingefügt hab kommt der Fehler :(
mouse.setLocation(gameGrid.getRandomEmptyLocation());
mouse.show();
}
}
class Mouse extends Actor
{
public Mouse()
{
super("sprites/sMouse.gif");
}
}
// ____________ Snake Schwanz ________
class TailSegment extends Actor
{
public TailSegment()
{
super("sprites/snakeTail.gif");
}
}
Das Problem tritt aber erst auf seitdem ich bei "public void tryToEat()" & im "public Snake_0()" was geändert habe
als noch alles ging war das "tryToEat()" noch so:
Code: Alles auswählen
public void tryToEat()
{
Actor actor = gameGrid.getOneActorAt(getLocation(), Mouse.class);
if (actor != null)
actor.hide();
}
Code: Alles auswählen
public Snake_0()
{
super(20 , 20 ,20, Color.darkGray, false);
Snake snake = new Snake();
addActor(snake, new Location(10, 10));
snake.setDirection(Location.NORTH);
for (int i = 0; i < 10; i++) // die for Schleife ist jetzt weg
addActor(new Mouse(), getRandomEmptyLocation());
addKeyListener(snake);
show();
doRun();
}
also ich wollte eigentlich, dass immer nur eine Maus da ist, wenn man diese gegessen hat, spawnt die woanders wieder, das die ganze Zeit bis irgendwann GameOver ist (so weit bin ich aber noch nicht^^)
falls ihr das was hilft hier noch mal der DropBox Link wo der Code und die Sprites drin sind https://www.dropbox.com/sh/1nxl69a63yi3 ... JEPga?dl=0