import sofia.micro.*;
import java.util.List;
import java.util.ArrayList;
//-------------------------------------------------------------------------
/**
* This is the marble class
*
* @author Emily Ashburn (emily2
...
import sofia.micro.*;
import java.util.List;
import java.util.ArrayList;
//-------------------------------------------------------------------------
/**
* This is the marble class
*
* @author Emily Ashburn (emily2000)
* @version (2019.04.04)
*/
public class Marble extends Actor
{
//~ Fields ................................................................
private Marble melvin;
//~ Constructor ...........................................................
// ----------------------------------------------------------
/**
* Creates a new Marble object.
*/
public Marble()
{
// Do NOT try to calculate the list of friends here,
// the marble is not added to a world yet, so it has
// no neighbors.
}
//~ Methods ...............................................................
// ----------------------------------------------------------
/**
* Finds the marble at the specified height (which could be
* at any x-coordinate for that height).
* @param yPosition The y-coordinate where the marble is located.
* @return The marble with the specified y-coordinate.
*/
public Marble getMarbleAtHeight(int yPosition)
{
for (int i = 0; i < this.getWorld().getWidth(); i++)
{
melvin =
this.getWorld().getOneObjectAt(i, yPosition, Marble.class);
if (melvin != null)
{
return melvin;
}
}
return null;
}
// ----------------------------------------------------------
/**
* Get a list of the marbles within two rows on either side
* of this marble, not including this marble itself.
* @return A list of the marbles with y-coordinates 1 or 2
* cells above or below this marble, not including
* this marble.
*/
public List getFriends()
{
List marbleList = new ArrayList();
for (int j = this.getGridY() - 2; j <= this.getGridY() + 2; j++)
{
[Show More]