Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * removes circles in left right top and bottom with the circle in the
- * middle
- *
- * @param row
- * - the row location of the middle circle
- * @param col
- * - the column location of the middle circle
- * @param circle
- * - what instance is the circle of
- */
- public void removeCircles(int row, int col, Circle circle) {
- System.out.println("removing circles");
- int counter;
- if (circle instanceof GreenCircle) {
- playfield[row][col] = new NoCircle(row, col);
- counter = 0;
- // up direction
- int rowUp = row;
- int colUp = col;
- while (true) {
- // if its not greenCircle then break the process
- if (!(playfield[--rowUp][colUp] instanceof GreenCircle)
- && !(playfield[rowUp][colUp] instanceof NoCircle))
- break;
- // if it is a GreenCircle then remove it, increment the counter
- // and break the while process
- else if (playfield[rowUp][colUp] instanceof GreenCircle) {
- playfield[rowUp][colUp] = new NoCircle(rowUp, colUp);
- counter++;
- break;
- }
- }
- // right direction
- int rowRight = row;
- int colRight = col;
- while (true) {
- // if its not greencircle then break the process
- if (!(playfield[rowRight][++colRight] instanceof GreenCircle)
- && !(playfield[rowRight][colRight] instanceof NoCircle))
- break;
- // if it is a greencircle then remove it, increment the counter
- // break the while process
- else if (playfield[rowRight][colRight] instanceof GreenCircle) {
- playfield[rowRight][colRight] = new NoCircle(rowRight,
- colRight);
- counter++;
- break;
- }
- }
- // donw direction;
- int rowDown = row;
- int colDown = col;
- while (true) {
- // if its not greencircle then break the process
- if (!(playfield[++rowDown][colDown] instanceof GreenCircle)
- && !(playfield[rowDown][colDown] instanceof NoCircle))
- break;
- // if it is a greencircle then remove it, increment the counter
- // and break the while process
- else if (playfield[rowDown][colDown] instanceof GreenCircle) {
- playfield[rowDown][colDown] = new NoCircle(rowDown, colDown);
- counter++;
- break;
- }
- }
- // left direction
- int rowLeft = row;
- int colLeft = col;
- while (true) {
- // if its not Greencircle then break the process
- if (!(playfield[rowLeft][--colLeft] instanceof GreenCircle)
- && !(playfield[rowLeft][colLeft] instanceof NoCircle))
- break;
- // if it is a greencircle then remove it increment the counter
- // and break the while process
- else if (playfield[rowLeft][colLeft] instanceof GreenCircle) {
- playfield[rowLeft][colLeft] = new NoCircle(rowLeft, colLeft);
- counter++;
- break;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment