Hi, so I am working on a game for school and I need to make a scoreboard. When I first made it, it wasn't actually counting whenever I picked something up like it was meant to. I asked my friends for help but for some reason their code didn't work for me. What can I do? I need the answer ASAP since I am going on holiday tomorrow and can't work on it there. Lines 45 - 60 below are related to my scoreboard.
That's my code ^^^^^
import greenfoot.*;
/**
* This class defines a crab. Crabs live on the beach.
*/
public class Crab extends Actor
{
private String[] down;
private String[] up;
public String[] left;
public String[] right;
public int frameCounterLeft;
public int frameCounterRight;
public int frameCounterDown;
public int frameCounterUp;
public int wormsEaten;
public Crab()
{
down = new String[4];
for(int n = 0; n<down.length;n++)
{
down[n]="SansDown"+n+".gif";
}
up = new String[4];
for(int n = 0; n<up.length;n++)
{
up[n]="SansUp"+n+".gif";
}
left = new String[4];
for(int n = 0; n<left.length;n++)
{
left[n]="SansLeft"+n+".gif";
}
right = new String[4];
for(int n = 0; n<right.length;n++)
{
right[n]="SansRight"+n+".gif";
}
frameCounterLeft=0;
frameCounterRight=0;
frameCounterDown=0;
frameCounterUp=0;
}
public void act()
{
wormsEaten = 0;
movement ();
getWorld().showText("Score: "+wormsEaten, 100, 50);
if ( isTouching(Worm.class) )
{
wormsEaten = wormsEaten +1;
removeTouching(Worm.class);
Greenfoot.playSound("slurp.wav");
}
if (wormsEaten == 6)
{
WinWorld win = new WinWorld();
Greenfoot.setWorld(win);
}
}
public void movement ()
{
if (Greenfoot .isKeyDown("a"))
{
move(-5);
if (frameCounterLeft<4)
{
setImage (left[frameCounterLeft]);
frameCounterLeft++;
}
else
{
frameCounterLeft=0;
}
}
if (Greenfoot .isKeyDown("d"))
{
move(5);
if (frameCounterRight<4)
{
setImage (right[frameCounterRight]);
frameCounterRight++;
}
else
{
frameCounterRight=0;
}
}
if (Greenfoot .isKeyDown("s"))
{
setLocation(getX(),getY()+5);
if (frameCounterDown<4)
{
setImage (down[frameCounterDown]);
frameCounterDown++;
}
else
{
frameCounterDown=0;
}
}
if (Greenfoot .isKeyDown("w"))
{
setLocation(getX(),getY()-5);
if (frameCounterUp<4)
{
setImage (up[frameCounterUp]);
frameCounterUp++;
}
else
{
frameCounterUp=0;
}
}
}
}
