Browse Source

Refratoring int f to firstHit

main
Thoumi Ngonga Brice 2 years ago
parent
commit
d475d3834d
  1. 14
      src/main/java/BattleShip/AIGridGUI.java

14
src/main/java/BattleShip/AIGridGUI.java

@ -23,7 +23,7 @@ public class AIGridGUI extends JPanel {
boolean[] cellsHit;
boolean[] cellsKilled;
boolean randomGuess = true;
int f; // it is the first
int firstHit;
Color darkRed = new Color(100, 0, 0); //
Border loweredBevel = BorderFactory.createLoweredBevelBorder();
Border raisedbevel = BorderFactory.createRaisedBevelBorder();
@ -261,7 +261,7 @@ public class AIGridGUI extends JPanel {
//Starting from the location of the first hit on the ship, test each direction to determine how many consecutive hits have been made in that direction.
int u = f;
int u = firstHit;
int upCount = -1;
while(u >= 0 && cellsHit[u] && !cellsKilled[u]) {
u = moveUp(u);
@ -270,7 +270,7 @@ public class AIGridGUI extends JPanel {
up.setCell(u);
up.setCount(upCount);
int d = f;
int d = firstHit;
int downCount = -1;
while(d >= 0 && cellsHit[d] && !cellsKilled[d]) {
d = moveDown(d);
@ -279,7 +279,7 @@ public class AIGridGUI extends JPanel {
down.setCell(d);
down.setCount(downCount);
int r = f;
int r = firstHit;
int rightCount = -1;
while(r >= 0 && cellsHit[r] && !cellsKilled[r]) {
r = moveRight(r);
@ -288,7 +288,7 @@ public class AIGridGUI extends JPanel {
right.setCell(r);
right.setCount(rightCount);
int l = f;
int l = firstHit;
int leftCount = -1;
while(l >= 0 && cellsHit[l] && !cellsKilled[l]) {
l = moveLeft(l);
@ -358,7 +358,7 @@ public class AIGridGUI extends JPanel {
}
//Mark if any cell remains that has been hit but not yet killed. If so, lock onto that cell.
if(cellsHit[bu.getGridLocation()] && !cellsKilled[bu.getGridLocation()]) {
f = bu.getGridLocation();
firstHit = bu.getGridLocation();
unkilledCells = true;
}
}
@ -372,7 +372,7 @@ public class AIGridGUI extends JPanel {
b.setBackground(Color.red);
//If previously random guessing, switch to locking onto the hit cell.
if(randomGuess) {
f = b.getGridLocation();
firstHit = b.getGridLocation();
randomGuess = false;
}
cellsHit[guessLocation] = true;

Loading…
Cancel
Save