I have this code for my game. I have been trying to spawn a boss when the user hits 15 points, but in order to spawn I need to be in the World Class. And the problem i'm having is trying to GET the score variable in the world class, to check if it is 15. My world class is as follows. The error is at the bottom.
This is the method I am referencing here at the bottm
THANKS IF YOU CAN HELP!
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class MyWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Space extends World
{
public int guess;
Counter counter = new Counter();
/**
* Constructor for objects of class MyWorld.
*
*/
public Space()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(1100, 600, 1);
prepare();
//PlatformAlien();
}
/**
* Prepare the world for the start of the program.
* That is: create the initial objects and add them to the world.
*/
public void prepare()
{
Hero hero = new Hero();
addObject(hero,298,137);
hero.setLocation(560,287);
RegularPlatform regularplatform = new RegularPlatform();
addObject(regularplatform,539,398);
regularplatform.setLocation(553,366);
addObject(counter, 100, 40);
// int amount = Greenfoot.getRandomNumber (0);
int rand = Greenfoot.getRandomNumber (2);
if (rand == 1)
{
Missiles[] missiles = new Missiles [2];
for (int i = 0; i < missiles.length; i++)
{
missiles[i] = new Missiles();
int misslesX = 1;
int misslesY = Greenfoot.getRandomNumber (600);
addObject(missiles[i], misslesX, misslesY);
}
}
else {
Missiles[] missiles = new Missiles [1];
for (int i = 0; i < missiles.length; i++)
{
missiles[i] = new Missiles();
int misslesX = 1;
int misslesY = Greenfoot.getRandomNumber (600);
addObject(missiles[i], misslesX, misslesY);
}
}
PlatformAlien();
}
public void PlatformAlien()
{
RegularPlatform[] platforms = new RegularPlatform [ 4];
Alien[] aliens = new Alien [2];
int platformX1 = 0;
int platformY1 = 0;
int platformX2 = 0;
int platformY2 = 0;
for (int i = 0; i < platforms.length; i++)
{
platforms[i] = new RegularPlatform();
// guess = Greenfoot.getRandomNumber (2);
//int platformX = Greenfoot.getRandomNumber(1100);
/// if (guess == 1)
// {
// platformX = 1;
//}
// else {
// platformX = 1100;
// }
int platformX = Greenfoot.getRandomNumber(1100);
int platformY = Greenfoot.getRandomNumber (450) + 110;
if (i == 0)
{
platformX1 = platformX;
platformY1 = platformY;
}
else if (i ==1)
{
platformY2 = platformY;
platformX2 = platformX;
}
//int platformY = Greenfoot.getRandomNumber (450) + 110;
addObject(platforms [i] , platformX,platformY);
//Actor offset = (RegularPlatform) getOneObjectAtOffset (0, 40, RegularPlatform.class);
// Actor RegularPlatform;
//RegularPlatform = getOneObjectAtOffset (platformX, platformY, RegularPlatform.class);
// if ( RegularPlatform !=null)
//
// platforms[i].setLocation(platformX+40, platformY + 40);
//tryna get it so that some spawn form left or just when it hits left go back
}
for (int i = 0; i < aliens.length; i++)
{
aliens[i] = new Alien();
if (i == 0)
{
addObject (aliens[i], platformX1, platformY1 - 70);
}
else if (i == 1)
{
addObject (aliens[i], platformX2, platformY2 - 70);
}
//aliens[i].setLocation (RegularPlatform.getXplatform(), 100);
}
}
public int getGuess()
{
return guess;
}
public Counter getCounter()
{
return counter;
}
public void boss()
{
int theScore = Counter.getScore();
if (theScore == 15)
{
BigAlien bigalien = new BigAlien();
addObject(bigalien, 0, 0);
}
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
* Write a description of class Score here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Counter extends Actor
{
/**
* Act - do whatever the Score wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public int score = 0;
public int getScore()
{
return score;
}
public void reset()
{
score = 0;
}
public void addScore()
{
score += 5;
}
public void act()
{
setImage(new GreenfootImage("Score: " + score, 25, Color.BLACK, Color.lightGray));
}
}
