While trying to write a function to reset my game's environment I'm running into a problem I'm not sure how to tackle. redDragon and blueDragon can each shoot up to 3 fireballs on screen at a time. I've found a static way to reset the dragons position after one is hit by a Fireball but I need to search the world for any and all fireballs and remove them from the world during this reset. I imagine I would use a loop to search for them but I'm unsure how to select them. Maybe there is a lesson in the book I can refer to.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* DragonArena is a two player game of fire-breathing dragons.
*
* @author (Mitch Belmer)
* @version (.01)
*/
public class DragonArena extends World
{
private int redScore;
private int blueScore;
private Dragon redDragon, blueDragon;
/**
* Constructor for objects of class DragonArena.
*
*/
public DragonArena()
{
// Create a new world with 768x768 cells with a cell size of 1x1 pixels.
super(768, 768, 1);
prepare();
redScore = 0;
blueScore = 0;
showScore();
}//end DragonArena
/**
* Prepare the world for the start of the program.
* That is: create the initial objects and add them to the world.
*/
private void prepare()
{
Wall wall = new Wall();
addObject(wall,221,366);
Wall wall2 = new Wall();
addObject(wall2, 571, 366);
redDragon = new Dragon("RedDragon.png");
redDragon.turn(-90);
addObject(redDragon,404,596);
blueDragon = new Dragon("BlueDragon.png");
blueDragon.turn(90);
addObject(blueDragon, 404, 180);
}//end prepare
/**
* Show Red and Blue Player score
*/
public void showScore()
{
showText("Red Player: " + redScore, 80, 25);
showText("Blue Player: " + blueScore, 675,25);
}//end showScore
/**
* Accessor methods for each of the player objects
*/
public Dragon getRedDragon() { return redDragon; }
public Dragon getBlueDragon() { return blueDragon; }
/**
* roundOver method allows for the world to start a new round
*/
public void roundOver(Dragon dragon)
{
//adjust the score
if (dragon == redDragon) {
//redDragon was hit so increase blue dragon score
blueScore++;
}//end if
else {
redScore++;
}//end else
showScore();
locReset();
}//end roundOver
/**
* Reset Dragons to start
*/
public void locReset()
{
redDragon.setLocation(404,596);
blueDragon.setLocation(404,180);
}//end locReset
}//end DragonArena

