I'm trying to increase the score every time I create a mine but it keeps giving me this error.
non static method addScore(int) cannot be referenced from static context
but what do i change to get this to work?
public class BubbleWorld extends World
{
private int loop = 0;
GreenfootSound backgroundMusic = new GreenfootSound("bubbletheme.mp3");
public void endGame()
{
GameOver go = new GameOver();
Greenfoot.setWorld(go);
}
/**
* Constructor for objects of class BubbleWorld.
*
*/
public BubbleWorld()
{
super(560, 560, 1);
if (loop == 0)
{
backgroundMusic.playLoop();
loop++;
}
prepare();
}
/**
* Prepare the world for the start of the program. That is: create the initial
* objects and add them to the world.
*/
private void prepare()
{
Bubble bubble = new Bubble();
addObject(bubble, 269, 498);
Cursor cursor = new Cursor();
addObject(cursor, 204, 100);
Shuriken shuriken = new Shuriken();
addObject(shuriken, 451, 59);
Deck deck = new Deck();
addObject(deck, 273, 557);
removeObject(bubble);
Bubble bubble2 = new Bubble();
addObject(bubble2, 291, 472);
removeObject(bubble2);
Bubble bubble3 = new Bubble();
addObject(bubble3, 278, 456);
ScoreBoard scoreboard = new ScoreBoard();
addObject(scoreboard, 56, 542);
}
public void act()
{
createMine();
createPowerUp();
}
public void createMine()
{
if (Greenfoot.getRandomNumber(1000) < 23)
{
Mine e = new Mine();
addObject(e, Greenfoot.getRandomNumber(getWidth()-20)+10, -30);
}
}
public void createPowerUp()
{
if (Greenfoot.getRandomNumber(1000) < 1)
{
PowerUp f = new PowerUp();
addObject(f, Greenfoot.getRandomNumber(getWidth()-20)+10, -30);
ScoreBoard.addScore(10);
}
}
}public class ScoreBoard extends Actor
{
private GreenfootImage board;
private GreenfootImage sb;
private int score = 0;
private String label = "Score : ";
public ScoreBoard()
{
super();
int boardWidth = 150; // I set the width
int boardHeight = 30; // i set the height to a variable
int boardTransparency = 125; // put in some transparency for effect
board = new GreenfootImage(boardWidth, boardHeight);
board.setColor(Color.gray);
board.setTransparency(boardTransparency);
board.fillRect(0, 0, boardWidth, boardHeight);
this.setImage(board);
update();
}
public void act()
{
// Add your action code here.
}
public int getScore()
{
return score;
}
public void addScore(int points)
{
score += points;
update();
}
private void update()
{
sb = new GreenfootImage(board);
sb.drawImage(new GreenfootImage(label + score, 18, Color.WHITE, new Color(0,0,0,0)),25,5);
this.setImage(sb);
}
}
