This site requires JavaScript, please enable it in your browser!
Greenfoot back
BigGrosse
BigGrosse wrote ...

2016/12/26

BreakOut Counter Crashing

BigGrosse BigGrosse

2016/12/26

#
Hello guys, im having a try at programming Break Out. I tried to implement a score counter into my Game but the system keeps crashing. I tried several times to understand what was going wrong but i couldnt see the problem. Here is the relevant code and the error message. I hope that you can help me fix this.
 public class Spielfeld extends World
{
private Counter counter;

public Spielfeld()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(640, 480, 1); 

    }
public void Punkte()
    {
      counter.PunkteHinzufuegen();
    } 

public class Ball extends Actor {

private int dx;
private int dy;

private void pruefeKontaktBlock()
   {    
       Actor block = getOneIntersectingObject (Block.class);
       if (block != null)
       {dy = -dy;
           getWorld().removeObject(block);
           Spielfeld mySpielfeld = (Spielfeld)getWorld();
           mySpielfeld.Punkte();
       }
   }
public class Counter extends Actor
{
    private int punkte;
    
    public Counter()
    {
        punkte = 0;
        setImage (new GreenfootImage(200, 30));
        update();
    }
    
    public void PunkteHinzufuegen()
    {
        punkte++;
        update();
    }
    
    private void update()
    {
        GreenfootImage img = getImage();
        img.clear();
        img.setColor(Color.GREEN);
        img.drawString("Punkte: " + punkte, 4, 20);
    }
  }
danpost danpost

2016/12/26

#
A lot of code is missing; the classes run into each other as shown; the error message is missing.
You need to login to post a reply.