I am having trouble implementing appleColor attribute in bowl class.
If a green apple is caught (appleColor attribute of Apple class is 1), you must increase the attribute greenApplesCounter by 1, remove the apple from Game. If a yellow apple is caught (appleColor attribute of Apple class is 2), you must increase the attribute yellowApplesCounter by 1, remove the apple from Game.
Apple class
*****************************************************************************************************
public class Apple extends SimulationActor {
public int appleColor = 0;
public Apple(int v_appleColor)
{
setRotation(Greenfoot.getRandomNumber(360));
if (v_appleColor == 1)
{
setImage("greenApple.png");
appleColor = 1;
} else
if (v_appleColor == 2)
{
setImage("yellowApple.png");
appleColor = 2;
}
}
public void act()
{
super.act();
if (getY() > 630)
{
position.setY(position.getY() + 300.0);
}
}
}
Bowl class
*****************************************************************************************************
public class Bowl extends SimulationActor
{
/* (World, Actor, GreenfootImage, Greenfoot and MouseInfo)*/
public int greenApplesCounter = 0;
public int yellowApplesCounter = 0;
/**
*
*/
public Bowl()
{
super();
alignWithVector( new Vector2D(0.0, 0.0));
acceleration = new Vector2D(0.0, 0.4);
}
/**
*
*/
public void act()
{
super.act();
MouseInfo mouse = Greenfoot.getMouseInfo();
if (mouse != null) {
Point2D mouseWindowPos = new Point2D(mouse.getX(), mouse.getY());
Point2D mouseWorldPos = windowToWorld(mouseWindowPos);
position.setX(mouseWorldPos.getX());
}
eatAppleOnCollision();
}
/**
*
*/
public void eatAppleOnCollision()
{
Actor Apple = getOneIntersectingObject(Apple.class);
SimulationWorld world = (SimulationWorld)getWorld();
List<Apple> apples = world.getObjects(Apple.class);
if (Apple != null) {
getWorld().removeObject(Apple);
Greenfoot.playSound(" pop1.wav");
}
}
}
