Browse Source

Update Implementation AIGridGUI class

main
Thoumi Ngonga Brice 2 years ago
parent
commit
3167f700f1
  1. 34
      src/main/java/BattleShip/AIGridGUI.java
  2. BIN
      target/classes/BattleShip/AIGridGUI.class

34
src/main/java/BattleShip/AIGridGUI.java

@ -3,13 +3,15 @@ package BattleShip;
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.*;
public class AIGridGUI extends JPanel {
ArrayList<BSButton> buttons = new ArrayList<BSButton>();
ArrayList<Ship> allShips = new ArrayList<Ship>();
// public ArrayList<SetShipsListener> listeners = new ArrayList<SetShipsListener>();
public ArrayList<SetShipsListener> listeners = new ArrayList<SetShipsListener>();
int[] testLocations;
int numOfGuesses = 0;
@ -152,6 +154,18 @@ public class AIGridGUI extends JPanel {
shipsPlaced = true;
}
public void placeShips() {
//Add listeners to all cells in grid to listen for ship placement.
for(int i = 0; i < buttons.size(); i++) {
listeners.add(new SetShipsListener());
buttons.get(i).addMouseListener(listeners.get(i));
}
shipToPlace = allShips.get(0);
text = "Place " + shipToPlace.getName() + ". Right click to toggle horizontal/vertical.";
}
public boolean getEndGame() {
return endGame;
@ -418,4 +432,22 @@ public class AIGridGUI extends JPanel {
return ((Integer) two.getCount()).compareTo((Integer) one.getCount());
}
}
//Listen for mouse actions to place ships.
class SetShipsListener implements MouseListener {
public void mouseEntered(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
}
}

BIN
target/classes/BattleShip/AIGridGUI.class

Loading…
Cancel
Save