Compare commits
No commits in common. "d8804d536920a5c01ec3da518d2910ac3a075872" and "37a984772cb150938f8506a5e73ff875561b539c" have entirely different histories.
d8804d5369
...
37a984772c
|
@ -21,7 +21,7 @@ public class Board {
|
||||||
for (int i = 0; i < this.ships.size(); i++) {
|
for (int i = 0; i < this.ships.size(); i++) {
|
||||||
HitResponseType type = this.ships.get(i).shootOnShip(point);
|
HitResponseType type = this.ships.get(i).shootOnShip(point);
|
||||||
if ( type == HitResponseType.SUNK) {
|
if ( type == HitResponseType.SUNK) {
|
||||||
for (int ii = 0; ii < this.ships.size(); ii++) {
|
for (int ii = 0; i < this.ships.size(); ii++) {
|
||||||
if (!this.ships.get(ii).isSunk()) {
|
if (!this.ships.get(ii).isSunk()) {
|
||||||
response.setType(type);
|
response.setType(type);
|
||||||
this.addHits(response);
|
this.addHits(response);
|
||||||
|
|
|
@ -17,7 +17,6 @@ public class BoardDisplay extends JPanel {
|
||||||
private Player player;
|
private Player player;
|
||||||
private boolean horizontal = false;
|
private boolean horizontal = false;
|
||||||
private List<ShipButton> shipButtonList;
|
private List<ShipButton> shipButtonList;
|
||||||
private boolean enemyBoard;
|
|
||||||
private Point mousePosition;
|
private Point mousePosition;
|
||||||
|
|
||||||
public void addShipButton(ShipButton button) {
|
public void addShipButton(ShipButton button) {
|
||||||
|
@ -35,14 +34,13 @@ public class BoardDisplay extends JPanel {
|
||||||
* @param gridSize
|
* @param gridSize
|
||||||
* @param player
|
* @param player
|
||||||
*/
|
*/
|
||||||
public BoardDisplay(int gridSize, Player player, boolean enemyBoard) {
|
public BoardDisplay(int gridSize, Player player) {
|
||||||
super(new GridLayout(gridSize + 1, gridSize + 1)); // +1 wegen extra Zeile/Spalte
|
super(new GridLayout(gridSize + 1, gridSize + 1)); // +1 wegen extra Zeile/Spalte
|
||||||
this.fields = new JButton[gridSize][gridSize];
|
this.fields = new JButton[gridSize][gridSize];
|
||||||
//this.ships = new ArrayList<>();
|
//this.ships = new ArrayList<>();
|
||||||
this.shipButtonList = new ArrayList<>();
|
this.shipButtonList = new ArrayList<>();
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.gridSize = gridSize;
|
this.gridSize = gridSize;
|
||||||
this.enemyBoard = enemyBoard;
|
|
||||||
System.out.println("Name in Boarddisplay: " + player.getName());//Testausgabe
|
System.out.println("Name in Boarddisplay: " + player.getName());//Testausgabe
|
||||||
// Erstellung von Spielfeld
|
// Erstellung von Spielfeld
|
||||||
for (int i = 0; i <= gridSize; i++) {
|
for (int i = 0; i <= gridSize; i++) {
|
||||||
|
@ -149,12 +147,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) {
|
||||||
System.out.println("CLICK " + o);
|
if (!this.currentShip.setPosition(o, horizontal, player.getBoard().getShips(),this.gridSize)) {
|
||||||
if (!this.enemyBoard && !this.player.isGameRunning() && !this.player.isReady()) {
|
|
||||||
this.currentShip.setPosition(o, horizontal, player.getBoard().getShips(),this.gridSize);
|
|
||||||
}
|
|
||||||
if (this.enemyBoard && this.player.isGameRunning() && this.player.enemy.myTurn) {
|
|
||||||
this.player.enemy.shoot(o);
|
|
||||||
}
|
}
|
||||||
paintFields();
|
paintFields();
|
||||||
//if(this.currentShip.isPlaced()){
|
//if(this.currentShip.isPlaced()){
|
||||||
|
@ -182,20 +175,6 @@ public class BoardDisplay extends JPanel {
|
||||||
if(fields[i][j] == null) {
|
if(fields[i][j] == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (this.enemyBoard) {
|
|
||||||
// enemy board only accessible if game is running AND it's "enemy's" so local player's turn
|
|
||||||
if (!this.player.isGameRunning() || !this.player.enemy.myTurn) {
|
|
||||||
fields[i][j].setEnabled(false);
|
|
||||||
} else {
|
|
||||||
fields[i][j].setEnabled(true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (this.player.isGameRunning() || this.player.isReady()) {
|
|
||||||
fields[i][j].setEnabled(false);
|
|
||||||
} else {
|
|
||||||
fields[i][j].setEnabled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fields[i][j].setBackground(Color.BLUE);
|
fields[i][j].setBackground(Color.BLUE);
|
||||||
for(Point p : test) {
|
for(Point p : test) {
|
||||||
if(i==p.getX() && j==p.getY() && currentShip.checkValidPlacement(mousePosition,horizontal,player.getBoard().getShips(),gridSize)) {
|
if(i==p.getX() && j==p.getY() && currentShip.checkValidPlacement(mousePosition,horizontal,player.getBoard().getShips(),gridSize)) {
|
||||||
|
@ -210,19 +189,6 @@ public class BoardDisplay extends JPanel {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HitResponse hit = this.player.getBoard().getHitResponsOnPoint(new Point(i, j));
|
|
||||||
if (hit != null) {
|
|
||||||
switch (hit.getType()) {
|
|
||||||
case HIT:
|
|
||||||
case SUNK:
|
|
||||||
case VICTORY:
|
|
||||||
fields[i][j].setBackground(Color.ORANGE);
|
|
||||||
break;
|
|
||||||
case MISS:
|
|
||||||
fields[i][j].setBackground(Color.CYAN);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for( ShipButton shipButton: shipButtonList) {
|
for( ShipButton shipButton: shipButtonList) {
|
||||||
|
|
|
@ -122,8 +122,8 @@ public class GameBoard extends JPanel {
|
||||||
// Spielfelder erstellen (eigenes und gegnerisches)
|
// Spielfelder erstellen (eigenes und gegnerisches)
|
||||||
// Spielfelder werden in BoardDisplay erstellt
|
// Spielfelder werden in BoardDisplay erstellt
|
||||||
int gridSize = GameController.semesterToBoardSize(semesterCounter); // Größe des Spielfelds
|
int gridSize = GameController.semesterToBoardSize(semesterCounter); // Größe des Spielfelds
|
||||||
this.ownBoardPanel = new BoardDisplay(gridSize,p1, false);
|
this.ownBoardPanel = new BoardDisplay(gridSize,p1);
|
||||||
this.opponentBoardPanel = new BoardDisplay(gridSize, p2, true);
|
this.opponentBoardPanel = new BoardDisplay(gridSize, p2);
|
||||||
|
|
||||||
// Panel für das Kontext-Text-Feld
|
// Panel für das Kontext-Text-Feld
|
||||||
JPanel headerPanel = new JPanel();
|
JPanel headerPanel = new JPanel();
|
||||||
|
|
|
@ -24,7 +24,6 @@ public class LocalPlayer extends Player {
|
||||||
case MISS -> this.myTurn = true;
|
case MISS -> this.myTurn = true;
|
||||||
case VICTORY -> System.out.println("Game Over"); //TODO Was halt bei victory passiert ist hier wurder verloheren
|
case VICTORY -> System.out.println("Game Over"); //TODO Was halt bei victory passiert ist hier wurder verloheren
|
||||||
}
|
}
|
||||||
GameController.getMainFrame().refreshGameBoard();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -35,7 +34,6 @@ public class LocalPlayer extends Player {
|
||||||
case MISS -> this.myTurn = false;
|
case MISS -> this.myTurn = false;
|
||||||
case VICTORY -> System.out.println("Win"); // TODO was halt beim victory passier ist hier wurde gewonnen
|
case VICTORY -> System.out.println("Win"); // TODO was halt beim victory passier ist hier wurde gewonnen
|
||||||
}
|
}
|
||||||
GameController.getMainFrame().refreshGameBoard();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
//TODO Generell ready und reset weg nachdem ready gedrückt
|
//TODO Generell button ausblenden anpassen
|
||||||
// Aufgeben button hinzufügen (anstadt backbutton) (funktion existiert noch noch nicht)
|
|
||||||
// win/lose screen (aufruffunktion für backend)
|
|
||||||
//
|
|
||||||
/**
|
/**
|
||||||
* Der MainFrame dient als Hub und Übergreifendes Fenster auf dem alle weiteren Panel angezeigt werden.
|
* Der MainFrame dient als Hub und Übergreifendes Fenster auf dem alle weiteren Panel angezeigt werden.
|
||||||
* Dadurch werden keine weiteren Fenster geöffnet.
|
* Dadurch werden keine weiteren Fenster geöffnet.
|
||||||
|
|
|
@ -6,7 +6,6 @@ public abstract class Player {
|
||||||
protected String name;
|
protected String name;
|
||||||
protected Board board;
|
protected Board board;
|
||||||
protected Boolean myCoin;
|
protected Boolean myCoin;
|
||||||
protected boolean gameRunning;
|
|
||||||
|
|
||||||
protected boolean sentCoin;
|
protected boolean sentCoin;
|
||||||
|
|
||||||
|
@ -17,7 +16,6 @@ public abstract class Player {
|
||||||
this.hasReceivedCoin = false;
|
this.hasReceivedCoin = false;
|
||||||
this.sentCoin = false;
|
this.sentCoin = false;
|
||||||
this.myTurn = false;
|
this.myTurn = false;
|
||||||
this.gameRunning = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createBoard(int size) {
|
public void createBoard(int size) {
|
||||||
|
@ -64,17 +62,8 @@ public abstract class Player {
|
||||||
if (this.myTurn) {
|
if (this.myTurn) {
|
||||||
this.beginTurn();
|
this.beginTurn();
|
||||||
}
|
}
|
||||||
this.gameRunning = true;
|
|
||||||
GameController.getMainFrame().refreshGameBoard();
|
GameController.getMainFrame().refreshGameBoard();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void receiveCoin(boolean coin);
|
public abstract void receiveCoin(boolean coin);
|
||||||
|
|
||||||
public boolean isGameRunning() {
|
|
||||||
return this.gameRunning;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isReady() {
|
|
||||||
return this.sentCoin;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue