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