fix horizontal #15
|
@ -14,7 +14,8 @@ public abstract class AiPlayer extends LocalPlayer {
|
|||
|
||||
public void AiSetShips() {
|
||||
for(int i = 0; i < super.board.getShips().size(); i++) { // Interiert durch alle Shiffe
|
||||
while(!super.board.getShips().get(i).setPosition(RandomPoint(), super.board.getShips(), super.board.getSize())) {}
|
||||
//TODO: set horizontal
|
||||
while(!super.board.getShips().get(i).setPosition(RandomPoint(), true, super.board.getShips(), super.board.getSize())) {}
|
||||
} // Versucht das Aktuelle Shiff zu setzten und wiederholt solange bis es funktioniert
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ public class BoardDisplay extends JPanel {
|
|||
//private List <Ship> ships;//brauchen wir nicht mehr
|
||||
private Ship currentShip;
|
||||
private Player player;
|
||||
private boolean vertical = false;
|
||||
private boolean horizontal = false;
|
||||
private List<ShipButton> shipButtonList;
|
||||
|
||||
public void addShipButton(ShipButton button) {
|
||||
|
@ -44,8 +44,8 @@ public class BoardDisplay extends JPanel {
|
|||
// Erstellung von Spielfeld
|
||||
for (int i = 0; i <= gridSize; i++) {
|
||||
for (int j = 0; j <= gridSize; j++) {
|
||||
final int x = i - 1; // Temporäre Variable
|
||||
final int y = j - 1; // Temporäre Variable
|
||||
final int x = j - 1; // Temporäre Variable
|
||||
final int y = i - 1; // Temporäre Variable
|
||||
if (i == 0 && j == 0) {
|
||||
add(new JLabel(" "));
|
||||
} else if (i == 0) {
|
||||
|
@ -60,11 +60,11 @@ public class BoardDisplay extends JPanel {
|
|||
add(rowLabel);
|
||||
} else {
|
||||
// Spielfeld (interaktive Zellen)
|
||||
JButton field = new JButton("");
|
||||
JButton field = new JButton(x + ", " + y);
|
||||
field.setBackground(Color.BLUE);
|
||||
field.setOpaque(true);
|
||||
field.setBorderPainted(true);
|
||||
fields[i - 1][j - 1] = field;
|
||||
fields[x][y] = field;
|
||||
add(field);
|
||||
//field.addMouseListener(new MouseAdapter() {
|
||||
// @Override
|
||||
|
@ -86,7 +86,6 @@ public class BoardDisplay extends JPanel {
|
|||
togglePlacementDirection(); // Ausrichtung ändern
|
||||
} else if (SwingUtilities.isLeftMouseButton(e)) {
|
||||
Point o = new Point(x, y);
|
||||
currentShip.setHorizontal(vertical);
|
||||
handleFieldClick(o); // Linksklick -> Schiff platzieren
|
||||
}
|
||||
}
|
||||
|
@ -132,8 +131,8 @@ public class BoardDisplay extends JPanel {
|
|||
* Wechselt die Platzierungsrichtung zwischen horizontal und vertikal.
|
||||
*/
|
||||
private void togglePlacementDirection() {
|
||||
vertical = !vertical;
|
||||
String direction = vertical ? "vertikal" : "horizontal";
|
||||
horizontal = !horizontal;
|
||||
String direction = horizontal ? "horizontal" : "vertikal";
|
||||
System.out.println("Platzierungsrichtung geändert zu: " + direction);
|
||||
}
|
||||
|
||||
|
@ -142,7 +141,7 @@ public class BoardDisplay extends JPanel {
|
|||
* @param o Die Koordinaten des Klicks.
|
||||
*/
|
||||
private void handleFieldClick(Point o) {
|
||||
if (!this.currentShip.setPosition(o,player.getBoard().getShips(),this.gridSize)) {
|
||||
if (!this.currentShip.setPosition(o, horizontal, player.getBoard().getShips(),this.gridSize)) {
|
||||
}
|
||||
paintFields();
|
||||
//if(this.currentShip.isPlaced()){
|
||||
|
|
Loading…
Reference in New Issue