public void checkrules(int row, int col, Direction d, Tile... tile) throws QwirkleException{
int n = 0; // Counter starts at 0, will be useful later one in the method to know if the array is being placed somewhere where there is no tiles surrounding it
int startrow = row; // Initial row where the first tile will be placed (will be updated everytime we check the next tile)
int startcol = col; // Initial column where the first tile will be placed (will be updated everytime we check the next tile)
for (int i = 0; i < tile.length; i++){ // Iterates through all the tiles in our array tile
if (this.tiles[startrow][startcol] != null){ // If the position where the tile from our array of tiles will be placed has another tile in it already throws a QwirkleException.
throw new QwirkleException();
}
for (Direction f : Direction.values()){ // Iterates through all directions for each tile to check how many nulls and if the tile touches another one, check if color AND shape are different
if (this.tiles[startrow + f.getDeltaRow()][startcol + f.getDeltaCol()] == null){
n++; // Adds 1 to the counter n everytime it encounters a null next to our tile in grids, will be used later to throw an exception
} else if (f!=d && this.tiles[startrow + f.getDeltaRow()][startcol + f.getDeltaCol()].color() != tile[i].color() && this.tiles[startrow + f.getDeltaRow()][startcol + f.getDeltaCol()].shape() != tile[i].shape()){
throw new QwirkleException(); // Throws an exception if one of the tiles next to our tile has different color AND shape (checks in all 4 directions, UP,DOWN,LEFT,RIGHT)
}
}
startrow = startrow + d.getDeltaRow(); // Updates the startrow for the next tile in the direction in which the user wants to place his array of tiles
startcol = startcol + d.getDeltaCol(); // Updates the startcol for the next tile in the direction in which the user wants to place his array of tiles
}
#Help fixing this method
5 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @frigid zinc! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.