|
@ -12,11 +12,13 @@ public class BShip { |
|
|
JPanel textPanel = new JPanel(); |
|
|
JPanel textPanel = new JPanel(); |
|
|
JTextArea textArea = new JTextArea(); |
|
|
JTextArea textArea = new JTextArea(); |
|
|
JFrame theFrame = new JFrame("Battleship"); |
|
|
JFrame theFrame = new JFrame("Battleship"); |
|
|
|
|
|
public boolean autoPlacement = false; |
|
|
JMenuItem auto; |
|
|
JMenuItem auto; |
|
|
JMenuItem[] boardSize = new JMenuItem[3]; |
|
|
JMenuItem[] boardSize = new JMenuItem[3]; |
|
|
public AIGridGUI grid2; |
|
|
public AIGridGUI grid2; |
|
|
int rows = 10; |
|
|
int rows = 10; |
|
|
int columns = 10; |
|
|
int columns = 10; |
|
|
|
|
|
boolean shipsPlaced = false; |
|
|
|
|
|
|
|
|
public void startGame() { |
|
|
public void startGame() { |
|
|
|
|
|
|
|
@ -28,6 +30,16 @@ public class BShip { |
|
|
grid2 = new AIGridGUI(rows, columns); |
|
|
grid2 = new AIGridGUI(rows, columns); |
|
|
|
|
|
|
|
|
buildGUI(); |
|
|
buildGUI(); |
|
|
|
|
|
|
|
|
|
|
|
//Place ships on grid 2. |
|
|
|
|
|
|
|
|
|
|
|
if(autoPlacement) { |
|
|
|
|
|
grid2.autoPlaceShips(); |
|
|
|
|
|
} else { |
|
|
|
|
|
grid2.placeShips(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//.. |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void buildGUI() { |
|
|
public void buildGUI() { |
|
@ -78,7 +90,14 @@ public class BShip { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public class NewGameListener implements ActionListener { |
|
|
public class NewGameListener implements ActionListener { |
|
|
public void actionPerformed(ActionEvent a) {} |
|
|
|
|
|
|
|
|
public void actionPerformed(ActionEvent a) { |
|
|
|
|
|
|
|
|
|
|
|
thePanel.remove(grid1); |
|
|
|
|
|
thePanel.remove(grid2); |
|
|
|
|
|
grid1 = null; |
|
|
|
|
|
grid2 = null; |
|
|
|
|
|
shipsPlaced = false; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |