I am creating a game where you need to avoid obstacles. When the obstacles reach the bottom of the screen, a point is added. But, I am not able to add change the score. I would appreciate some help. Thanks
- Ian
**Obstacle (block)**
public class Block extends Actor
{
public int addScore;
private int actCounter;
private int grn = 6;
public int getTransparency;
private int bttl = 300;
private int mrn = 10;
public Block()
{
setRotation(90);
getImage().setColor(Color.BLUE);
fillBlock();
}
public void act()
{
moveDown();
}
/**
* Change the colour of the Block.
*/
private void fillBlock()
{
getImage().fill();
}
/**
* Move a random amount of steps. Call "atBottom".
*/
private void moveDown()
{
atBottom();
move(Greenfoot.getRandomNumber(mrn));
}
/**
* Check if we have touvhed the bottom, if so become invisible.
*/
private void atBottom()
{
if (getY() == 499) {
getImage().setTransparency(0);
backTop();
addScore();
}
else
{
getImage().setTransparency(255);
if (isTouching(Dot.class))
{
if (getTransparency !=255)
{
World world = getWorld();
world.removeObjects(world.getObjects(null)); //removes all the objects in the world;
world.addObject(new GameOver(), world.getWidth()/2, world.getHeight()/2);
//adds the game over screen in the middle of the world;
Greenfoot.stop();
}
}
}
}
/**
* If at bottom, go back up and come down again.
*/
private void backTop()
{
setLocation(Greenfoot.getRandomNumber(300), 22);
moveDown();
}
}
**Counter**
public class Counter extends Actor
{
private int score;
public int done = 20;
public int addScore;
/**
* Act - do whatever the Counter wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public Counter()
{
score = 0;
setImage (new GreenfootImage(200, 30));
GreenfootImage image = getImage();
image.scale(image.getWidth() + 200, image.getHeight() + 30);
setImage(image);
update();
}
public void addScore()
{
score++;
update();
if (score == done)
{
Greenfoot.playSound("tada.wav");
Greenfoot.stop();
}
}
public void update()
{
GreenfootImage ing = getImage();
ing.clear();
ing.setColor(Color.BLACK);
ing.drawString("S c o r e : " + score, 4, 20);
}
}

