import java.util.ArrayList; /** * This class represents a row in the game and keeps track of which * columns within the row contain obstacles * * @author Monique Shotande * @version November 2, 2017 * Lab 11 */ public class GameRow { /** The list of positions occupied by obstacles in this row * (excluding those occupied by the hero or villain) */ private ArrayList occupiedPositions; /** * Default Constructor for a row where all * columns are unoccupied by obstacles */ public GameRow() { this.occupiedPositions = new ArrayList(); } /** * Add a column index for a obstacle occupying * space within this row * * @param space int for the column index within the row * occupied by an obstacle */ public void addToOccupiedSpaces(int space) { occupiedPositions.add(space); } /** * Clear the list of obstacles occupying * space within this row */ public void clearOccupiedSpaces() { occupiedPositions.clear(); } /** * Are there any obstacles within this row? * * @return true if the row has no obstacles */ public boolean isEmptySpace() { return occupiedPositions.isEmpty(); } /** * Is there an obstacle within this row at the specified column index? * * @param space int for the column index within the row of interest * @return true if there is not an obstacle within the space for this row */ public boolean isEmptySpace(int space) { return !occupiedPositions.contains(space); } /** * Where are the positions occupied by obstacles within this row? * * @return list of integers, indicating positions occupied by obstacles * (not including spaces occupied the hero or villain) */ public ArrayList getOccupiedPositions() { return occupiedPositions; } }