Guest User

Untitled

a guest
Oct 22nd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. /**
  2. * removes circles in left right top and bottom with the circle in the
  3. * middle
  4. *
  5. * @param row
  6. * - the row location of the middle circle
  7. * @param col
  8. * - the column location of the middle circle
  9. * @param circle
  10. * - what instance is the circle of
  11. */
  12. public void removeCircles(int row, int col, Circle circle) {
  13. System.out.println("removing circles");
  14. int counter;
  15.  
  16. if (circle instanceof GreenCircle) {
  17. playfield[row][col] = new NoCircle(row, col);
  18.  
  19. counter = 0;
  20.  
  21. // up direction
  22. int rowUp = row;
  23. int colUp = col;
  24. while (true) {
  25. // if its not greenCircle then break the process
  26. if (!(playfield[--rowUp][colUp] instanceof GreenCircle)
  27. && !(playfield[rowUp][colUp] instanceof NoCircle))
  28. break;
  29. // if it is a GreenCircle then remove it, increment the counter
  30. // and break the while process
  31. else if (playfield[rowUp][colUp] instanceof GreenCircle) {
  32. playfield[rowUp][colUp] = new NoCircle(rowUp, colUp);
  33. counter++;
  34. break;
  35. }
  36. }
  37. // right direction
  38. int rowRight = row;
  39. int colRight = col;
  40. while (true) {
  41. // if its not greencircle then break the process
  42. if (!(playfield[rowRight][++colRight] instanceof GreenCircle)
  43. && !(playfield[rowRight][colRight] instanceof NoCircle))
  44. break;
  45. // if it is a greencircle then remove it, increment the counter
  46. // break the while process
  47. else if (playfield[rowRight][colRight] instanceof GreenCircle) {
  48. playfield[rowRight][colRight] = new NoCircle(rowRight,
  49. colRight);
  50. counter++;
  51. break;
  52. }
  53. }
  54. // donw direction;
  55. int rowDown = row;
  56. int colDown = col;
  57. while (true) {
  58. // if its not greencircle then break the process
  59. if (!(playfield[++rowDown][colDown] instanceof GreenCircle)
  60. && !(playfield[rowDown][colDown] instanceof NoCircle))
  61. break;
  62. // if it is a greencircle then remove it, increment the counter
  63. // and break the while process
  64. else if (playfield[rowDown][colDown] instanceof GreenCircle) {
  65. playfield[rowDown][colDown] = new NoCircle(rowDown, colDown);
  66. counter++;
  67. break;
  68. }
  69. }
  70.  
  71. // left direction
  72. int rowLeft = row;
  73. int colLeft = col;
  74. while (true) {
  75. // if its not Greencircle then break the process
  76. if (!(playfield[rowLeft][--colLeft] instanceof GreenCircle)
  77. && !(playfield[rowLeft][colLeft] instanceof NoCircle))
  78. break;
  79. // if it is a greencircle then remove it increment the counter
  80. // and break the while process
  81. else if (playfield[rowLeft][colLeft] instanceof GreenCircle) {
  82. playfield[rowLeft][colLeft] = new NoCircle(rowLeft, colLeft);
  83. counter++;
  84. break;
  85. }
  86. }
  87. }
  88. }
Add Comment
Please, Sign In to add comment