サブクラス:以下は、変数を親クラスに分類するサブクラスです。
public class Score extends Actor
{
static int sum = 0; //NOT this SUM
public void act()
{
}
public int getScore(int scoreDisplay)
{
int mX, mY;
Message mess = new Message();
mX = 720;
mY = 50;
World wld = getWorld();
wld.addObject(mess, mX, mY);
sum = sum + scoreDisplay; // I want this sum.
mess.displayMessage(sum);
return sum;
}
}
sum=sum+scoreDisplay;
親クラスで値を呼び出したい。
親クラス:
public class BalloonWorld extends World
{
private Score score;
Timer timerText = new Timer();
private int timer = 3600;
public Score getScore()
{
return score;
}
public BalloonWorld()
{
super(800, 600, 1);
addObject(timerText, 100, 15);
timerText.setText("Time left: " + (timer / 60));
prepare();
}
private void prepare()
{
Gun g1 = new Gun();
addObject(g1, 0, 300);
addObject(new Timer(), 780, 300);
score = new Score();
addObject(score, 533, 291);
if (score.sum > 100) // I want the sum to be called here, if its value is greater than 100 the 'if' statement should execute.
{
Gun2 g2 = new Gun2();
addObject(g1, 0, 300);
addObject(new Timer(), 780, 300);
}
if (timer > 0)
{
timer--;
if (timer % 60 == 0)
{
timerText.setText("Time left: " + (timer / 60));
}
}
if (timer == 0)
{
Greenfoot.stop();
}
}
}
サブクラスから親クラスに変数を呼び出すにはどうすればよいですか。