Compare commits
No commits in common. "main" and "FH_Fixes" have entirely different histories.
Binary file not shown.
Binary file not shown.
BIN
Sound/win.mp3
BIN
Sound/win.mp3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 396 B After Width: | Height: | Size: 1.6 KiB |
3
makefile
3
makefile
|
@ -29,9 +29,6 @@ test-jar: jar
|
|||
# $(JR) -cp "$(OUT_DIR)/:$(LIB_DIR)/*" $(MAIN_CLASS)
|
||||
$(JR) -jar $(OUT_DIR)/$(JAR_NAME)
|
||||
|
||||
docs:
|
||||
javadoc -cp "$(LIB_DIR)/*" -d "docs" $(SRC_DIR)/*.java
|
||||
|
||||
test: classfiles
|
||||
$(JR) -cp "$(OUT_DIR)$(SEPERATOR)$(LIB_DIR)/*" $(MAIN_CLASS)
|
||||
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
/**
|
||||
* Die Klasse AiPlayer ist die Basis für alle Ki Spieler und jede Spezifische Ki erweitert diese Klasse.
|
||||
* @author Florian und Florian
|
||||
* */
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Die Klasse AiPlayer ist die Basis für alle Ki Spieler und jede Spezifische Ki erweitert diese Klasse.
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
* */
|
||||
|
||||
public abstract class AiPlayer extends LocalPlayer implements Runnable {
|
||||
|
||||
/**
|
||||
|
@ -16,7 +18,6 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable {
|
|||
|
||||
/**
|
||||
* Konstruktor
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
*/
|
||||
public AiPlayer() {
|
||||
this.setName("AI Player");
|
||||
|
@ -26,7 +27,6 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable {
|
|||
/**
|
||||
* Gibt einen zufälligen Punkt im Spielfeld zurück.
|
||||
* @return Ein zufälliger Punkt
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
*/
|
||||
public Point RandomPoint() {
|
||||
Random random = new Random(); // Pseudo Random für zufallszahlen
|
||||
|
@ -38,7 +38,6 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable {
|
|||
/**
|
||||
* Initialisiert das Board.
|
||||
* @param size größe des Boards
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
*/
|
||||
@Override
|
||||
public void createBoard(int size) {
|
||||
|
@ -49,7 +48,6 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable {
|
|||
|
||||
/**
|
||||
* Ki Methode zum zufälligen Setzten der Schiffe
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
*/
|
||||
public void aiSetShips() {
|
||||
for(int i = 0; i < super.board.getShips().size(); i++) { // Interiert durch alle Shiffe
|
||||
|
@ -60,20 +58,13 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable {
|
|||
}
|
||||
/**
|
||||
* Ki Methode zum zufälligen Schießen auf das gegnerische Board.
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
*/
|
||||
public void aiShoot() {
|
||||
if (!this.myTurn) return;
|
||||
this.enemy.receiveShoot(RandomPoint());
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nachdem receiveShoot beim gegner den schuss verarbeitet hat,
|
||||
* wird diese Methode mit der antwort aufgerufen.
|
||||
* @param hitResponse the hitresponse
|
||||
* @author Florian Alexy und Florian Hantzschel und Luca Conte
|
||||
*/
|
||||
|
||||
@Override
|
||||
public synchronized void receiveHit(HitResponse hitResponse) {
|
||||
// Eltern-Klasse LocalPlayer updatet myTurn
|
||||
|
@ -87,11 +78,6 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Erhält einen schuss vom gegner und verarbeitet ihn.
|
||||
* @param point the location to be shot
|
||||
* @author Florian Alexy und Florian Hantzschel und Luca Conte
|
||||
*/
|
||||
@Override
|
||||
public synchronized void receiveShoot(Point point) {
|
||||
super.receiveShoot(point);
|
||||
|
@ -105,7 +91,6 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable {
|
|||
/**
|
||||
* Wird aufgerufen, wenn in determineCoinToss festgestellt wurde das die Ki anfängt.
|
||||
* Erster Schuss wird gestartet.
|
||||
* @author Florian Alexy und Florian Hantzschel und Luca Conte
|
||||
*/
|
||||
@Override
|
||||
public void beginTurn() {
|
||||
|
@ -115,8 +100,8 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Closes past threads and tries firing a shot.
|
||||
* @author Luca Conte, Florian Alexy und Florian Hantzschel
|
||||
* Die Methode wird immer aufgerufen, wenn ein Schuss abgefeuert werden soll.
|
||||
* Es wird erst ein Schuss abgefeuert, wenn der vorherige schuss abgeschlossen wurde.
|
||||
*/
|
||||
public void run() {
|
||||
Iterator<Thread> i = this.shootThreads.iterator();
|
||||
|
@ -143,25 +128,4 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable {
|
|||
|
||||
this.aiShoot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes all running threads and does some cleanup work so the garbage collector will delete the player
|
||||
* @author Luca Conte
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
super.destroy();
|
||||
Iterator<Thread> i = this.shootThreads.iterator();
|
||||
while(i.hasNext()) {
|
||||
Thread thread = i.next();
|
||||
try {
|
||||
thread.interrupt();
|
||||
thread.join();
|
||||
i.remove();
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,10 +7,6 @@ import java.net.InetSocketAddress;
|
|||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
|
||||
/**
|
||||
* Provides an Interface to communicate using a socket asynchronously
|
||||
* @author Luca Conte, Peer Ole Wachtel
|
||||
*/
|
||||
public class AsyncSocket {
|
||||
private Socket socket;
|
||||
private Thread checkerThread;
|
||||
|
@ -23,12 +19,6 @@ public class AsyncSocket {
|
|||
private BufferedReader in;
|
||||
private BufferedWriter out;
|
||||
|
||||
/**
|
||||
* Creates a socket server and turns the first incoming connection into an AsyncSocket
|
||||
* @param port the port to listen on for a connection
|
||||
* @param handler the handler that will be called when a message is received
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public AsyncSocket(int port, AsyncSocketListener handler) {
|
||||
this.setHandler(handler);
|
||||
|
||||
|
@ -55,12 +45,6 @@ public class AsyncSocket {
|
|||
this.connectorThread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects to the address provided and turns the resulting socket into an AsyncSocket
|
||||
* @param address the socket address to connect to
|
||||
* @param handler the handler that will be called when a message is received
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public AsyncSocket(InetSocketAddress address, AsyncSocketListener handler) {
|
||||
this.setHandler(handler);
|
||||
|
||||
|
@ -84,22 +68,11 @@ public class AsyncSocket {
|
|||
this.connectorThread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param socket the socket to be wrapped in an AsyncSocket
|
||||
* @param handler the handler that will be called when a message is received
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public AsyncSocket(Socket socket, AsyncSocketListener handler) throws IOException {
|
||||
this.setHandler(handler);
|
||||
this.initSocket(socket);
|
||||
}
|
||||
|
||||
/**
|
||||
* creates input and ouput writer / readers as well as a checker thread to repeatedly check
|
||||
* for incoming messages
|
||||
* @param socket the socket to be wrapped
|
||||
* @author Luca Conte
|
||||
*/
|
||||
private void initSocket(Socket socket) throws IOException {
|
||||
System.out.println("Initialising sockets");
|
||||
this.socket = socket;
|
||||
|
@ -149,39 +122,17 @@ public class AsyncSocket {
|
|||
this.flushBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the message handler for the async socket
|
||||
* @param handler the `AsyncSocketListener` to be set as the new handler
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public void setHandler(AsyncSocketListener handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* sends a message through the socket
|
||||
* @param socketPackage the socket package to be sent
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public synchronized void send(SocketPackage socketPackage) {
|
||||
this.sendLine(socketPackage.toString());
|
||||
}
|
||||
/**
|
||||
* sends a message through the socket
|
||||
* @param packageName the name of the package to be sent
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public synchronized void send(String packageName) {
|
||||
this.send(packageName, "");
|
||||
}
|
||||
/**
|
||||
* sends a message through the socket
|
||||
* @param packageName the name of the package to be sent
|
||||
* @param packageContent the content of the package to be sent.
|
||||
* `packageName` and `packageContent` are joined with a space " "
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public synchronized void send(String packageName, String packageContent) {
|
||||
if (packageContent.length() > 0) {
|
||||
packageContent = " " + packageContent;
|
||||
|
@ -189,19 +140,11 @@ public class AsyncSocket {
|
|||
this.sendLine(packageName + packageContent);
|
||||
}
|
||||
|
||||
/**
|
||||
* sends a string of text into the socket, concatenated with CRLF
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public synchronized void sendLine(String message) {
|
||||
sendBuffer = sendBuffer + message + "\r\n";
|
||||
this.flushBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* flushes the buffers to send all pending messages
|
||||
* @author Luca Conte
|
||||
*/
|
||||
private synchronized void flushBuffer() {
|
||||
if (!this.sendBuffer.isEmpty() && this.out != null) {
|
||||
try {
|
||||
|
@ -216,19 +159,12 @@ public class AsyncSocket {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* closes the socket connection and removes the checker thread
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public void close() {
|
||||
this.shouldStop = true;
|
||||
|
||||
try {
|
||||
this.socket.close();
|
||||
if (this.checkerThread != null) {
|
||||
this.checkerThread.interrupt();
|
||||
this.checkerThread.join();
|
||||
}
|
||||
this.checkerThread.join();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
/**
|
||||
* defines a message listener for AsyncSockets
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public interface AsyncSocketListener {
|
||||
public void receive(String message);
|
||||
}
|
|
@ -1,37 +1,14 @@
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Diese Klasse ist das Board von eimem spieler und enthält alle logischen operationen.
|
||||
* Sprich ist das Backend Board.
|
||||
*
|
||||
* @author Peer Ole Wachtel, Florian Alexy und Florian Hantzschel
|
||||
*/
|
||||
public class Board {
|
||||
|
||||
/**
|
||||
* Alle bisher empfangenen HitResponsen
|
||||
*/
|
||||
private List<HitResponse> hits;
|
||||
|
||||
/**
|
||||
* Alle Schiffe des Semesters
|
||||
*/
|
||||
private List<Ship> ships;
|
||||
|
||||
/**
|
||||
* Die größe des Spielfeldes
|
||||
*/
|
||||
private final int size;
|
||||
|
||||
|
||||
/**
|
||||
* Erstellt ein neues Board.
|
||||
* setzt die übergebene Spielfeldgröße.
|
||||
* Erstellt die Liste aller Schiffe des Semesters
|
||||
* @param size Die größe des Spielfeldes
|
||||
* @author Peer Ole Wachtel, Florian Alexy und Florian Hantzschel
|
||||
*/
|
||||
public Board(int size) {
|
||||
this.size = size;
|
||||
this.ships = new ArrayList<>();
|
||||
|
@ -39,12 +16,6 @@ public class Board {
|
|||
this.createShip(size - 13);
|
||||
}
|
||||
|
||||
/**
|
||||
* Nimmt einen punkt entgegen und Gibt einen HitResponse zurück.
|
||||
* @param point auf den geschossen wurde
|
||||
* @return
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public synchronized HitResponse hit (Point point){
|
||||
HitResponse response = new HitResponse(HitResponseType.MISS,point);
|
||||
for (int i = 0; i < this.ships.size(); i++) {
|
||||
|
@ -71,12 +42,6 @@ public class Board {
|
|||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* finds adjacened hit responses and sets their type to SUNK if they are currently HIT
|
||||
* this makes it so that all the points of the ship are marked as SUNK, not just the final hit
|
||||
* @param p the Point from which to propate the SUNK type
|
||||
* @author Luca Conte
|
||||
*/
|
||||
private void propagateSunk(Point p) {
|
||||
HitResponse hit = this.getHitResponseOnPoint(p);
|
||||
|
||||
|
@ -90,36 +55,17 @@ public class Board {
|
|||
propagateSunk(new Point(p.getX(), p.getY() - 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* creates all the ships on a board given a certain semester
|
||||
* @param semester the semester to be played in
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
private void createShip(int semester){
|
||||
List<ShipData> shipData = Ship.semeterList.get(semester-1);
|
||||
List<ShipData> shipData = Ship.semeterList.get(semester -1);
|
||||
for (int i = 0; i < shipData.size(); i++) {
|
||||
this.ships.add(new Ship(shipData.get(i).size(), shipData.get(i).name()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of all the Ships on the board
|
||||
* @return a list of all the Ships on the board
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public List<Ship> getShips() {
|
||||
return ships;
|
||||
}
|
||||
|
||||
/**
|
||||
* adds a HitResponse to the list of Hits on the board
|
||||
* If a hit response already exists on the same position, the hit response will not be added
|
||||
* If the hit response is of type `HitResponseType.SUNK` it will propagate this hit response type
|
||||
* to all adjacened hit responses with type HIT using `propagateSunk`.
|
||||
* @param hitResponse the HitResponse to be added
|
||||
* @return true when the hit response was added, otherwise false
|
||||
* @author Peer Ole Wachtel, Luca Conte
|
||||
*/
|
||||
public synchronized boolean addHits(HitResponse hitResponse) {
|
||||
if (this.getHitResponseOnPoint(hitResponse.getPoint()) == null){
|
||||
this.hits.add(hitResponse);
|
||||
|
@ -135,11 +81,6 @@ public class Board {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param point the position to get the hit response from
|
||||
* @return the hit response at the position `point`
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public synchronized HitResponse getHitResponseOnPoint(Point point) {
|
||||
for (int i = 0; i < this.hits.size(); i++){
|
||||
if (this.hits.get(i).getPoint().equals(point)){
|
||||
|
@ -149,11 +90,6 @@ public class Board {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the size of the board
|
||||
* @return the size of the board
|
||||
* @author Florian Alexy, Florian Hantzschel
|
||||
*/
|
||||
public int getSize() {
|
||||
return this.size;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ public class BoardDisplay extends JPanel {
|
|||
|
||||
/**
|
||||
* Fügt Buttons zu Liste hinzu und aktualisiert Feld durch Aufruf von paintFields
|
||||
* @param button Jeweiliger Button der hinzugefügt werden soll
|
||||
* @param button
|
||||
* @author Joshua Kuklok
|
||||
*/
|
||||
public void addShipButton(ShipButton button) {
|
||||
|
@ -31,15 +31,15 @@ public class BoardDisplay extends JPanel {
|
|||
|
||||
/**
|
||||
* Gibt currentShip zurück
|
||||
* @return currentShip Objekt der Klasse Schiff
|
||||
* @author Lucas Bronson Luca Conte
|
||||
* @return currentShip
|
||||
* @author Lucas Bronson, Luca Conte, Joshua Kuklok
|
||||
*/
|
||||
public Ship getCurrentShip() {
|
||||
return currentShip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Konstruktor des Board Displays
|
||||
* Konstruktor der startLocalGame.
|
||||
* @param gridSize Die Größe des Spielfelds
|
||||
* @param player Der Spieler
|
||||
* @author Lucas Bronson
|
||||
|
@ -55,8 +55,8 @@ public class BoardDisplay extends JPanel {
|
|||
// Erstellung vom Spielfeld
|
||||
for (int i = 0; i <= gridSize; i++) {
|
||||
for (int j = 0; j <= gridSize; j++) {
|
||||
final int x = j - 1; // Temporäre Variable für überspringen von Rahmenzeile-/spalte
|
||||
final int y = i - 1; // Temporäre Variable für überspringen von Rahmenzeile-/spalte
|
||||
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) {
|
||||
|
@ -67,7 +67,7 @@ public class BoardDisplay extends JPanel {
|
|||
} else if (j == 0) {
|
||||
JLabel rowLabel = new JLabel(String.valueOf((char) ('A' + i - 1)));
|
||||
rowLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
rowLabel.setFont(new Font("Roboto", Font.BOLD, 14));
|
||||
rowLabel.setFont(new Font("Arial", Font.BOLD, 14));
|
||||
add(rowLabel);
|
||||
} else {
|
||||
// Spielfeld (interaktive Zellen)
|
||||
|
@ -174,7 +174,6 @@ public class BoardDisplay extends JPanel {
|
|||
if(currentShip != null) {
|
||||
test = currentShip.getVirtualOccupiedPoints(mousePosition, horizontal);
|
||||
}
|
||||
if (player == null || player.getBoard() == null) return;
|
||||
for(int i = 0; i < gridSize; i++) {
|
||||
for(int j = 0; j < gridSize; j++) {
|
||||
if(fields[i][j] == null) {
|
||||
|
@ -212,7 +211,7 @@ public class BoardDisplay extends JPanel {
|
|||
}
|
||||
for(Ship ship: player.getBoard().getShips()) {
|
||||
if(ship.isShipOnPos(new Point(i,j))) {
|
||||
fields[i][j].setBackground(Color.WHITE);
|
||||
fields[i][j].setBackground(Color.LIGHT_GRAY);
|
||||
}
|
||||
}
|
||||
HitResponse hit = this.player.getBoard().getHitResponseOnPoint(new Point(i, j));
|
||||
|
|
|
@ -23,7 +23,7 @@ public class GameBoard extends JPanel {
|
|||
ImageIcon gameBoardX = new ImageIcon("graphics/gameboardx.png");
|
||||
|
||||
// kontextText Text-Strings
|
||||
String kT1 = "Bitte Schiffe setzten - Rechtsclick zum drehen";
|
||||
String kT1 = "Bitte Schiffe setzten";
|
||||
String kT2 = "Warte auf Gegner";
|
||||
String kT3 = "Du fängst an";
|
||||
String kT4 = "Dein Gegner fängt an";
|
||||
|
@ -40,7 +40,6 @@ public class GameBoard extends JPanel {
|
|||
// Buttons
|
||||
JButton giveUpButton = new JButton("Aufgeben");
|
||||
|
||||
|
||||
/**
|
||||
* Konstruktor von GameBoard.
|
||||
* @param frame Der Mainframe der Anwendung über den alle Panels angezeigt werden.
|
||||
|
@ -56,9 +55,12 @@ public class GameBoard extends JPanel {
|
|||
List<Ship> shipsP1 =p1.getBoard().getShips();
|
||||
List<Ship> shipsP2 =p2.getBoard().getShips();
|
||||
|
||||
giveUpButton.addActionListener((e) -> {
|
||||
frame.showPanel("MainMenu");
|
||||
p1.withdraw();
|
||||
giveUpButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Hier könnte Ihr Backend Code stehen
|
||||
frame.showPanel("MainMenu");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -106,7 +108,7 @@ public class GameBoard extends JPanel {
|
|||
JPanel headerPanel = new JPanel();
|
||||
headerPanel.setLayout(new BorderLayout());
|
||||
headerPanel.add(kontextText, BorderLayout.WEST);
|
||||
kontextText.setFont(new Font("Roboto", Font.BOLD, 30));
|
||||
kontextText.setFont(new Font("Roboto", Font.BOLD, 30)); //TODO setFont fixen
|
||||
headerPanel.add(giveUpButton, BorderLayout.EAST);
|
||||
|
||||
JPanel leftButtonsPanel = new JPanel();
|
||||
|
@ -134,6 +136,7 @@ public class GameBoard extends JPanel {
|
|||
opponentBoardPanel.addShipButton(shipButton);
|
||||
shipButton.setEnabled(false);
|
||||
}
|
||||
|
||||
JToggleButton readyButton = new JToggleButton("Bereit");
|
||||
readyButton.setBackground(Color.GREEN);
|
||||
rightButtonsPanel.add(readyButton);
|
||||
|
@ -148,18 +151,14 @@ public class GameBoard extends JPanel {
|
|||
ownBoardPanel.resetAllShips();
|
||||
}
|
||||
});
|
||||
|
||||
// TODO buttons erst disablen wenn alle Schiffe platziert sind
|
||||
// Um Bereit-Meldung and Backend zu geben, kontextText zu setzten und ready/reset Button zu deaktivieren
|
||||
readyButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
kontextText.setText(kT2);
|
||||
p1.ready();
|
||||
if(p1.isReady()) {
|
||||
remove(readyButton);
|
||||
remove(resetButton);
|
||||
remove(rightButtonsPanel);
|
||||
remove(leftButtonsPanel);
|
||||
if(true) {
|
||||
readyButton.setEnabled(false);
|
||||
resetButton.setEnabled(false);
|
||||
}
|
||||
|
@ -202,36 +201,15 @@ public class GameBoard extends JPanel {
|
|||
|
||||
/**
|
||||
* Aktualisiert Zustand(kontextText) je nach Zug
|
||||
* @author Luca Conte, Joshua Kuklok
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public void refresh() {
|
||||
if (this.p1.myTurn) {
|
||||
if (!kontextText.getText().equals(kT5)) {
|
||||
this.kontextText.setText(kT5);
|
||||
SoundHandler.playSound("yourturn");
|
||||
}
|
||||
this.kontextText.setText(kT5);
|
||||
} else {
|
||||
this.kontextText.setText(kT6);
|
||||
}
|
||||
this.ownBoardPanel.refresh();
|
||||
this.opponentBoardPanel.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter für Player1
|
||||
* @return Player 1
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public Player getP1() {
|
||||
return p1;
|
||||
}
|
||||
/**
|
||||
* Getter für Player2
|
||||
* @return Player 2
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public Player getP2() {
|
||||
return p2;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,65 +5,28 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The central Backend Component
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public class GameController {
|
||||
|
||||
private static MainFrame mainFrame;
|
||||
|
||||
/**
|
||||
* returns the current MainFrame
|
||||
* @return the current MainFrame
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public static MainFrame getMainFrame() {
|
||||
return GameController.mainFrame;
|
||||
}
|
||||
/**
|
||||
* sets the current MainFrame
|
||||
* @param mainFrame the current MainFrame
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public static void setMainFrame(MainFrame mainFrame) {
|
||||
GameController.mainFrame = mainFrame;
|
||||
}
|
||||
|
||||
/**
|
||||
* converts a semester to be played in into its respective board size
|
||||
* @param semester the semester to be played in
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public static int semesterToBoardSize(int semester) {
|
||||
return semester + 13;
|
||||
}
|
||||
/**
|
||||
* converts a board size into its respective semester
|
||||
* @param size the board size to get the semester of
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public static int boardSizeToSemester(int size) {
|
||||
return size - 13;
|
||||
}
|
||||
|
||||
/**
|
||||
* the list of supported versions of the online protocol
|
||||
* https://github.com/lgc-4/ProgProjekt-Netzwerkstandard
|
||||
*/
|
||||
public static HashMap<String, Class<? extends OnlinePlayer>> supportedVersions = new HashMap<>(Map.of(
|
||||
"1.1.0", OnlinePlayer_1_1_0.class
|
||||
));
|
||||
|
||||
/**
|
||||
* Starts a game with one local player and one online player.
|
||||
* @param localPlayerClass the class of the local player to be instantiated. must extend `LocalPlayer`
|
||||
* @param localPlayerName the name of the local player. Only necessarry when localPlayerClass is `HumanPlayer`
|
||||
* @param address the Address of the opposing player. If the hostname of the address is set to be 0.0.0.0, it
|
||||
* is interpreted that this instance should instead listen on the defined port for incoming connections.
|
||||
* @param size the board size that it is intended to be played in
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public static void startOnlineGame(Class<? extends LocalPlayer> localPlayerClass, String localPlayerName, InetSocketAddress address, int size) throws IOException {
|
||||
AsyncSocket clientSocket;
|
||||
|
||||
|
@ -126,8 +89,7 @@ public class GameController {
|
|||
|
||||
/**
|
||||
* finds the largest common version in two lists of version strings
|
||||
* @return null if no common versions are found otherwise returns the most recent version present in both lists
|
||||
* @author Luca Conte
|
||||
* @return null if no common versions are found
|
||||
*/
|
||||
public static String findMostRecentVersion(List<String> versions1, List<String> versions2) {
|
||||
if (versions1 == null || versions2 == null) return null;
|
||||
|
@ -152,13 +114,10 @@ public class GameController {
|
|||
|
||||
/**
|
||||
* compares two version strings
|
||||
* @param version1 the first version to be compared
|
||||
* @param version2 the second version to be compared
|
||||
* @return
|
||||
* 0 if versions are equal
|
||||
* 1 if version1 is more recent than version2
|
||||
* -1 otherwise
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public static int compareVersions(String version1, String version2) {
|
||||
if (!checkVersionString(version1) || !checkVersionString(version2)) {
|
||||
|
@ -184,21 +143,11 @@ public class GameController {
|
|||
|
||||
/**
|
||||
* checks if a provided string matches the format of a version number
|
||||
* @param versionString the version String to be checked
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public static boolean checkVersionString(String versionString) {
|
||||
return versionString != null && versionString.matches("\\d+\\.\\d+\\.\\d+");
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a game with two local players
|
||||
* @param localPlayerClass the class of the local player to be instantiated. must extend `LocalPlayer`
|
||||
* @param localPlayerName the name of the local player. Only necessarry when localPlayerClass is `HumanPlayer`
|
||||
* @param enemyClass the class of the enemy player. Must extend `AiPlayer`. For Humans VS Human games use an online game instead.
|
||||
* @param size the board size that it is intended to be played in
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public static void startLocalGame(Class<? extends LocalPlayer> localPlayerClass, String localPlayerName, Class<? extends AiPlayer> enemyClass, int size) {
|
||||
|
||||
LocalPlayer localPlayer;
|
||||
|
@ -226,13 +175,6 @@ public class GameController {
|
|||
startGameWithInstancedPlayers(localPlayer, aiPlayer, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* switches to the ingame screen
|
||||
* @param p1 the first player. This player is always shown on the left side of the screen and is expected to be the Human player, if there is one.
|
||||
* @param p2 the second player
|
||||
* @param boardSize the board size to be played in
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public static void startGameWithInstancedPlayers(LocalPlayer p1, Player p2, int boardSize) {
|
||||
mainFrame.showPanelSLG("GameBoard", boardSizeToSemester(boardSize), p1, p2);
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* Hauptklasse über die der MainFrame gestartet wird
|
||||
* @author Lucas Bronson, Peer Ole Wachtel, Joshua Kuklok
|
||||
* @author Lucas Bronson, Ole Wachtel, Joshua Kuklok
|
||||
*/
|
||||
public class HalloSchiffeVersenken {
|
||||
|
||||
|
@ -8,10 +8,19 @@ public class HalloSchiffeVersenken {
|
|||
* Erstellt und setzt den Mainframe
|
||||
* @param args Argumente an Main durch Konsole etc.
|
||||
* @throws InterruptedException
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
MainFrame mf = new MainFrame();
|
||||
mf.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*TODO
|
||||
* Alle Textfonts anpassen
|
||||
* SOUND interrupt?
|
||||
* BACKEND aufruf bei aufgeben
|
||||
* check bevor ready ob alle schiffe platziert?
|
||||
* testcode rausnehmen
|
||||
* FidgetButton als surprise (button während spiels, der zufällig farbe wechseln kann und sounds abspielt)
|
||||
*/
|
|
@ -1,38 +1,14 @@
|
|||
|
||||
/**
|
||||
* Eine Antwort auf einen Schuss
|
||||
* enthält einen Punkt, auf den geschossen wurde, sowie einen typen,
|
||||
* der angibt, ob es sich bei dem Schuss um einen Treffer handelt
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
|
||||
public class HitResponse {
|
||||
/**
|
||||
* Speichert den typ der HitResponse.
|
||||
*/
|
||||
private HitResponseType type;
|
||||
/**
|
||||
* Speicher den Punkt wofür die HitResponse gilt.
|
||||
*/
|
||||
private Point point;
|
||||
|
||||
/**
|
||||
* Erstellt eine neue HitResponse und setzt den Punkt und typ.
|
||||
* @param type der HitResponse.
|
||||
* @param point für den die HitResponse gilt.
|
||||
* @author Peer Ole Wachtel.
|
||||
*/
|
||||
public HitResponse(HitResponseType type, Point point) {
|
||||
this.type = type;
|
||||
this.point = point;
|
||||
}
|
||||
|
||||
/**
|
||||
*Erstellt eine neue HitResponse und setzt den Punkt und typ.
|
||||
* @param typeIndex der HitResponse.
|
||||
* @param point für den die HitResponse gilt.
|
||||
* @throws IllegalArgumentException wenn der übergebene int nicht auf ein typ referenziert werden kann.
|
||||
* @author Peer Ole Wachtel.
|
||||
*/
|
||||
public HitResponse (int typeIndex, Point point) {
|
||||
if (typeIndex >= 0 && typeIndex < HitResponseType.values().length) {
|
||||
this.type = HitResponseType.values()[typeIndex];
|
||||
|
@ -42,48 +18,23 @@ public class HitResponse {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the type of the HitResponse
|
||||
* @return the type of the HitResponse
|
||||
* @author Florian Hantzschel
|
||||
*/
|
||||
public HitResponseType getHitResponse() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the point of the HitResponse
|
||||
* @return the point of the HitResponse
|
||||
* @author Florian Hantzschel
|
||||
*/
|
||||
public Point getPoint() {
|
||||
return this.point;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter für den type
|
||||
* @param type auf den die HitResponse gesetzt werden soll.
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public void setType(HitResponseType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt den passenden string nach Netzwerkstandard für eine HitResponse zurück.
|
||||
* @return den passenden string nach Netzwerkstandard für eine HitResponse.
|
||||
* @author Peer Ole Wachtel.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getPoint().toString() + " " + this.type.ordinal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter für den typ der HitResponse.
|
||||
* @return den typ der HitRespnse.
|
||||
* @author Peer Ole Wachtel.
|
||||
*/
|
||||
public HitResponseType getType() {
|
||||
return type;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
/**
|
||||
* Stellt die verschiedenen möglichkeiten einer HitResponse als typ dar.
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public enum HitResponseType {
|
||||
MISS, HIT, SUNK, VICTORY
|
||||
}
|
||||
|
|
|
@ -1,18 +1,4 @@
|
|||
|
||||
/**
|
||||
* Repräsentiert einen menschlichen Spieler
|
||||
* @author Luca Conte, Florian Hantzschel
|
||||
*/
|
||||
public class HumanPlayer extends LocalPlayer {
|
||||
/**
|
||||
* shoots a shot onto the provided point on the enemy board
|
||||
* if it is not the players turn, this method does nothing.
|
||||
* @param point the location to be shot
|
||||
* @author Luca Conte
|
||||
*/
|
||||
@Override
|
||||
public void shoot(Point point) {
|
||||
if (!this.myTurn) return;
|
||||
enemy.receiveShoot(point);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,9 +12,6 @@ import java.net.InetSocketAddress;
|
|||
*/
|
||||
public class JoinGame extends JPanel {
|
||||
|
||||
// Funktionshilfen
|
||||
String standardPort = "51525";
|
||||
|
||||
// Grafiken
|
||||
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
|
||||
|
||||
|
@ -42,9 +39,9 @@ public class JoinGame extends JPanel {
|
|||
* @param playerName Name des Spielers
|
||||
* @author Lucas Bronson, Joshua Kuklok
|
||||
*/
|
||||
public JoinGame(MainFrame frame,int g,int playerType,String playerName, int semesterCounter) {
|
||||
public JoinGame(MainFrame frame,int g,int playerType,String playerName) {
|
||||
setLayout(null);
|
||||
buildPanel(frame,g,playerType,playerName, semesterCounter);
|
||||
buildPanel(frame,g,playerType,playerName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,8 +52,7 @@ public class JoinGame extends JPanel {
|
|||
* @param playerName Name des Spielers
|
||||
* @author Lucas Bronson, Joshua Kuklok
|
||||
*/
|
||||
private void buildPanel(MainFrame frame,int g,int playerType,String playerName, int semesterCounter) {
|
||||
System.out.println("semesterzahl in JoinGame" + semesterCounter);
|
||||
private void buildPanel(MainFrame frame,int g,int playerType,String playerName) {
|
||||
if(g==1){
|
||||
spielBeitretenLabel= new JLabel("Spiel beitreten");
|
||||
}else{
|
||||
|
@ -75,7 +71,6 @@ public class JoinGame extends JPanel {
|
|||
}
|
||||
|
||||
portTextField.setBounds(50, 225, 250, 50);
|
||||
portTextField.setText(standardPort);
|
||||
|
||||
spielBeitretenLabel.setFont(robotoFont.deriveFont(50f));
|
||||
|
||||
|
@ -105,7 +100,6 @@ public class JoinGame extends JPanel {
|
|||
if (ipAddress.isEmpty()) {
|
||||
ipAddress = "0.0.0.0";
|
||||
}
|
||||
System.out.println(portTextField.getText());
|
||||
String portText = portTextField.getText();
|
||||
|
||||
int port = Integer.parseInt(portText);
|
||||
|
@ -115,13 +109,13 @@ public class JoinGame extends JPanel {
|
|||
|
||||
try {
|
||||
if(playerType == 0) {
|
||||
GameController.startOnlineGame(HumanPlayer.class, playerName, address,GameController.semesterToBoardSize(semesterCounter));
|
||||
GameController.startOnlineGame(HumanPlayer.class, playerName, address,GameController.semesterToBoardSize(2));
|
||||
} else if(playerType == 1) {
|
||||
GameController.startOnlineGame(SpecificAiPlayerEasy.class, playerName, address,GameController.semesterToBoardSize(semesterCounter));
|
||||
GameController.startOnlineGame(SpecificAiPlayerEasy.class, playerName, address,GameController.semesterToBoardSize(2));
|
||||
} else if (playerType == 2) {
|
||||
GameController.startOnlineGame(SpecificAiPlayerMedium.class, playerName, address,GameController.semesterToBoardSize(semesterCounter));
|
||||
GameController.startOnlineGame(SpecificAiPlayerMedium.class, playerName, address,GameController.semesterToBoardSize(2));
|
||||
} else if (playerType == 3) {
|
||||
GameController.startOnlineGame(SpecificAiPlayerHard.class, playerName, address,GameController.semesterToBoardSize(semesterCounter));
|
||||
GameController.startOnlineGame(SpecificAiPlayerHard.class, playerName, address,GameController.semesterToBoardSize(2));
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
|
|
|
@ -1,36 +1,15 @@
|
|||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* repräsentiert einen Player, der Lokal an dem Gerät spielt,
|
||||
* auf dem dieses Programm läuft
|
||||
* @author Luca Conte, Peer Ole Wachtel, Florian Hantzschel
|
||||
*/
|
||||
public class LocalPlayer extends Player {
|
||||
|
||||
|
||||
/**
|
||||
* erstellt einen LocalPlayer und setzt myCoin random
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public LocalPlayer(){
|
||||
super();
|
||||
Random random = new Random();
|
||||
this.myCoin = random.nextBoolean();
|
||||
}
|
||||
|
||||
/**
|
||||
* receives a shot onto a point from the enemy
|
||||
* @param point the location to be shot
|
||||
* @author Luca Conte, Peer Ole Wachtel
|
||||
*/
|
||||
@Override
|
||||
public synchronized void receiveShoot(Point point) {
|
||||
if (!this.enemy.myTurn) {
|
||||
System.out.println("enemy tried to fire when not their turn!");
|
||||
return;
|
||||
}
|
||||
this.enemy.myTurn = false;
|
||||
|
||||
HitResponse hitResponse = board.getHitResponseOnPoint(point);
|
||||
if (!(hitResponse == null)){
|
||||
enemy.receiveHit(hitResponse);
|
||||
|
@ -43,34 +22,22 @@ public class LocalPlayer extends Player {
|
|||
switch (hitResponse.getType()) {
|
||||
case HIT, SUNK -> this.myTurn = false;
|
||||
case MISS -> this.myTurn = true;
|
||||
case VICTORY -> this.lose();
|
||||
case VICTORY -> System.out.println("Game Over"); //TODO Was halt bei victory passiert ist hier wurder verloheren
|
||||
}
|
||||
GameController.getMainFrame().refreshGameBoard();
|
||||
}
|
||||
|
||||
/**
|
||||
* receives a hit response from the enemy as a response to a receiveShoot call
|
||||
* @param hitResponse the hitresponse
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
@Override
|
||||
public synchronized void receiveHit(HitResponse hitResponse) {
|
||||
enemy.board.addHits(hitResponse);
|
||||
switch (hitResponse.getType()) {
|
||||
case HIT, SUNK -> this.myTurn = true;
|
||||
case MISS -> this.myTurn = false;
|
||||
case VICTORY -> this.win();
|
||||
case VICTORY -> System.out.println("Win"); // TODO was halt beim victory passier ist hier wurde gewonnen
|
||||
}
|
||||
GameController.getMainFrame().refreshGameBoard();
|
||||
}
|
||||
|
||||
/**
|
||||
* receives the enemies coin toss result
|
||||
* this method does nothing if the player has already received the enemies coin
|
||||
* it will also call `determineCoinToss`
|
||||
* @param coin the coin of the enemy player
|
||||
* @author Luca Conte
|
||||
*/
|
||||
@Override
|
||||
public synchronized void receiveCoin(boolean coin) {
|
||||
if (!this.hasReceivedCoin) {
|
||||
|
@ -79,20 +46,12 @@ public class LocalPlayer extends Player {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sends shot to enemy player.
|
||||
* should ONLY be called on HumanPlayer
|
||||
* @author Luca Conte
|
||||
*/
|
||||
@Override
|
||||
public void shoot(Point point){
|
||||
return;
|
||||
this.myTurn = false;
|
||||
enemy.receiveShoot(point);
|
||||
}
|
||||
|
||||
/**
|
||||
* marks the player as ready, if all ships have been placed
|
||||
* @author Luca Conte
|
||||
*/
|
||||
@Override
|
||||
public synchronized void ready() {
|
||||
for (Ship ship : this.board.getShips()) {
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* Klasse für Erstellung von looseScreen Objekten
|
||||
* Dient zur Anzeige das ein Spiel verloren wurde
|
||||
*/
|
||||
public class LooseScreen extends JPanel {
|
||||
JLabel looseLabel = new JLabel("Du hast Verloren");
|
||||
JButton okButton = new JButton("Zurück zum Hauptmenü");
|
||||
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
|
||||
|
||||
/**
|
||||
* Konstruktor der LooseScreen Klasse
|
||||
* @param frame Der Mainframe der Anwendung über den alle Panels angezeigt werden.
|
||||
* @author Lucas Bronson
|
||||
*/
|
||||
public LooseScreen(MainFrame frame) {
|
||||
setLayout(new BorderLayout());
|
||||
buildPanel(frame);
|
||||
}
|
||||
|
||||
/**
|
||||
* Panel bauen/Objekte hinzufügen
|
||||
* @param frame Der Mainframe der Anwendung über den alle Panels angezeigt werden.
|
||||
* @author Lucas Bronson
|
||||
*/
|
||||
public void buildPanel(MainFrame frame) {
|
||||
add(looseLabel);
|
||||
okButton.setBounds(650,525,200,50);
|
||||
looseLabel.setBounds(500,450,500,50);
|
||||
looseLabel.setFont(robotoFont);
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* Klasse für Erstellung von looseScreen Objekten
|
||||
* Dient zur Anzeige das ein Spiel verloren wurde
|
||||
* @author Joshua Kuklok, Luca Bronson
|
||||
*/
|
||||
public class LoseScreen extends JPanel {
|
||||
JLabel loseLabel = new JLabel("Du hast Verloren");
|
||||
JButton okButton = new JButton("Zurück zum Hauptmenü");
|
||||
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
|
||||
|
||||
/**
|
||||
* Konstruktor der LoseScreen Klasse
|
||||
* @param frame Der Mainframe der Anwendung über den alle Panels angezeigt werden.
|
||||
* @author Lucas Bronson
|
||||
*/
|
||||
public LoseScreen(MainFrame frame) {
|
||||
setLayout(null);
|
||||
buildPanel(frame);
|
||||
}
|
||||
|
||||
/**
|
||||
* Panel bauen/Objekte hinzufügen
|
||||
* @param frame Der Mainframe der Anwendung über den alle Panels angezeigt werden.
|
||||
* @author Lucas Bronson, Joshua Kuklok
|
||||
*/
|
||||
public void buildPanel(MainFrame frame) {
|
||||
add(loseLabel);
|
||||
okButton.setBounds(625,525,200,50);
|
||||
loseLabel.setBounds(550,450,500,50);
|
||||
loseLabel.setFont(robotoFont);
|
||||
SoundHandler.playSound("loose");
|
||||
|
||||
// Zurückkehren zum Hauptmenü, wenn okButton gedrückt wird
|
||||
okButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
frame.showPanel("MainMenu");
|
||||
}
|
||||
});
|
||||
add(loseLabel);
|
||||
add(okButton);
|
||||
}
|
||||
}
|
|
@ -45,12 +45,14 @@ public class MainFrame extends JFrame {
|
|||
MainMenuView mainMenuView = new MainMenuView(this);
|
||||
startLocalGame localGame = new startLocalGame(this);
|
||||
startMultiplayerGame multiplayerGame = new startMultiplayerGame(this);
|
||||
coinToss coinToss = new coinToss(this);
|
||||
Verbinden verbinden = new Verbinden(this);
|
||||
|
||||
// Panels hinzufügen
|
||||
mainPanel.add(mainMenuView, "MainMenu");
|
||||
mainPanel.add(localGame, "LocalGame");
|
||||
mainPanel.add(multiplayerGame, "MultiplayerGame");
|
||||
mainPanel.add(coinToss, "coinToss");
|
||||
mainPanel.add(verbinden, "Verbinden");
|
||||
// mainPanel.add(winLooseScreen, "WinLooseScreen");
|
||||
|
||||
|
@ -78,10 +80,10 @@ public class MainFrame extends JFrame {
|
|||
* @param playerName Name des Spielers
|
||||
* @author Lucas Bronson, Joshua Kuklok
|
||||
*/
|
||||
public void showPanelSMG(String panelName, int num, int playerType,String playerName, int semesterCounter) {
|
||||
public void showPanelSMG(String panelName, int num, int playerType,String playerName) {
|
||||
this.localMult = num;
|
||||
|
||||
JoinGame joinGame = new JoinGame(this, localMult, playerType, playerName, semesterCounter);
|
||||
JoinGame joinGame = new JoinGame(this, localMult, playerType, playerName);
|
||||
mainPanel.add(joinGame, panelName);
|
||||
mainPanel.revalidate();
|
||||
mainPanel.repaint();
|
||||
|
@ -125,19 +127,9 @@ public class MainFrame extends JFrame {
|
|||
/**
|
||||
* Spezifische ShowPanel für WinScreen Klasse
|
||||
* @param panelName Name des anzuzeigenden Panels
|
||||
* @param player Player von dem die funktion aufgerufen worden ist
|
||||
* @author Lucas Bronson, Peer Ole Wachtel, Luca Conte
|
||||
* @author Lucas Bronson
|
||||
*/
|
||||
public void showPanelWin(String panelName, Player player){
|
||||
if(gameBoard == null || player != gameBoard.getP1()){
|
||||
return;
|
||||
}
|
||||
|
||||
this.gameBoard.getP1().destroy();
|
||||
this.gameBoard.getP2().destroy();
|
||||
this.gameBoard.removeAll();
|
||||
this.gameBoard = null;
|
||||
|
||||
public void showPanelWin(String panelName){
|
||||
WinScreen winScreen = new WinScreen(this);
|
||||
mainPanel.add(winScreen, panelName);
|
||||
mainPanel.revalidate();
|
||||
|
@ -148,20 +140,10 @@ public class MainFrame extends JFrame {
|
|||
/**
|
||||
* Spezifische ShowPanel für LooseScreen Klasse
|
||||
* @param panelName Name des anzuzeigenden Panels
|
||||
* @param player Player von dem die funktion aufgerufen worden ist
|
||||
* @author Lucas Bronson, Peer Ole Wachtel, Luca Conte
|
||||
* @author Lucas Bronson
|
||||
*/
|
||||
public void showPanelLose(String panelName, Player player){
|
||||
if(gameBoard == null || player != gameBoard.getP1()){
|
||||
return;
|
||||
}
|
||||
|
||||
this.gameBoard.getP1().destroy();
|
||||
this.gameBoard.getP2().destroy();
|
||||
this.gameBoard.removeAll();
|
||||
this.gameBoard = null;
|
||||
|
||||
LoseScreen looseScreen = new LoseScreen(this);
|
||||
public void showPanelLoose(String panelName){
|
||||
LooseScreen looseScreen = new LooseScreen(this);
|
||||
mainPanel.add(looseScreen,panelName);
|
||||
mainPanel.revalidate();
|
||||
mainPanel.repaint();
|
||||
|
@ -169,7 +151,7 @@ public class MainFrame extends JFrame {
|
|||
}
|
||||
|
||||
/**
|
||||
* Aktualisiert das Spielfeld
|
||||
* Aktualisiert das Spielfeld (kontextText)
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public void refreshGameBoard() {
|
||||
|
|
|
@ -1,57 +1,28 @@
|
|||
/**
|
||||
* Abstrakte Repräsentation eines Spielers, der an einem anderen gerät spielt
|
||||
* und durch eine Online Verbindung mit dieser Instanz kommuniziert
|
||||
* @author Luca Conte, Peer Ole Wachtel
|
||||
*/
|
||||
public abstract class OnlinePlayer extends Player implements AsyncSocketListener {
|
||||
public abstract class OnlinePlayer extends Player implements AsyncSocketListener{
|
||||
protected AsyncSocket socket;
|
||||
protected int wantedBoardSize;
|
||||
|
||||
protected boolean hasReceivedCoinPackage;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param size the size of the board the enemy player wants to play with
|
||||
* the actual board size will be determined once the semester of the online partner is known
|
||||
* @param socket an AsyncSocket to communicate with the enemy through
|
||||
* @author Peer Ole Wachtel, Luca Conte
|
||||
*/
|
||||
public OnlinePlayer(Integer size, AsyncSocket socket) {
|
||||
this.socket = socket;
|
||||
this.wantedBoardSize = size;
|
||||
this.myCoin = null;
|
||||
socket.setHandler(this);
|
||||
//TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
/**
|
||||
* sends the IAM Package for introduction
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public abstract void sendIAM();
|
||||
|
||||
/**
|
||||
* receives a message from the AsyncSocket
|
||||
* satisfies AsyncSocketListener interface
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public abstract void receive(String message);
|
||||
|
||||
/**
|
||||
* receives the coin toss result from the enemy
|
||||
* @param coin the result of the coin toss
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
@Override
|
||||
public abstract void receiveShoot(Point point);
|
||||
|
||||
@Override
|
||||
public abstract void receiveHit(HitResponse hitResponse);
|
||||
|
||||
@Override
|
||||
public abstract void receiveCoin(boolean coin);
|
||||
|
||||
/**
|
||||
* closes the socket and does player cleanup work
|
||||
* @author Luca Conte
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
super.destroy();
|
||||
this.socket.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,29 +1,11 @@
|
|||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* eine Implementierung des Kommunikationsprotokoll nach Version 1.1.0 des Netzwerkstandards
|
||||
* https://github.com/lgc-4/ProgProjekt-Netzwerkstandard
|
||||
* @author Peer Ole Wachtel, Luca Conte
|
||||
*/
|
||||
public class OnlinePlayer_1_1_0 extends OnlinePlayer {
|
||||
|
||||
/**
|
||||
* Erstellt einen Online Player
|
||||
* @param size die maximale Größe des Spielfelds
|
||||
* @param socket der Socket zur Kommunikation mit dem Online Partner
|
||||
*/
|
||||
public OnlinePlayer_1_1_0(Integer size, AsyncSocket socket) {
|
||||
super(size, socket);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* receives a message from the AsyncSocket
|
||||
* implemented according to version 1.1.0 of https://github.com/lgc-4/ProgProjekt-Netzwerkstandard
|
||||
* @param message the message from the socket
|
||||
* @author Peer Ole Wachtel, Luca Conte, Florian Hantzschel
|
||||
*/
|
||||
@Override
|
||||
public void receive(String message) {
|
||||
SocketPackage p = new SocketPackage(message);
|
||||
|
@ -52,8 +34,8 @@ public class OnlinePlayer_1_1_0 extends OnlinePlayer {
|
|||
case "COIN":
|
||||
if(!this.hasReceivedCoinPackage && (p.getData().equals("1") || p.getData().equals("0"))){
|
||||
this.myCoin = p.getData().equals("1");
|
||||
this.hasReceivedCoinPackage = true;
|
||||
this.ready();
|
||||
this.hasReceivedCoinPackage = true;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -70,23 +52,7 @@ public class OnlinePlayer_1_1_0 extends OnlinePlayer {
|
|||
Point point = new Point(data.get(0));
|
||||
int typeIndex = Integer.parseInt(data.get(1));
|
||||
if (Point.isValidSyntax(data.get(0)) && typeIndex >= 0 && typeIndex < HitResponseType.values().length){
|
||||
|
||||
HitResponse hitResponse = new HitResponse(typeIndex, point);
|
||||
|
||||
this.enemy.receiveHit(hitResponse);
|
||||
|
||||
switch (hitResponse.getType()) {
|
||||
case HIT, SUNK:
|
||||
this.myTurn = false;
|
||||
break;
|
||||
case MISS:
|
||||
this.myTurn = true;
|
||||
break;
|
||||
|
||||
case VICTORY:
|
||||
// GameController.getMainFrame().showPanelWin("", this.enemy);
|
||||
break;
|
||||
}
|
||||
this.enemy.receiveHit(new HitResponse(typeIndex, point));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -95,66 +61,28 @@ public class OnlinePlayer_1_1_0 extends OnlinePlayer {
|
|||
//TODO CHAT
|
||||
break;
|
||||
|
||||
case "WITHDRAW":
|
||||
this.withdraw();
|
||||
break;
|
||||
|
||||
default:
|
||||
//nichts passier da Paket ungültig
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sends introduction package IAM to online partner.
|
||||
* @author Luca Conte
|
||||
*/
|
||||
@Override
|
||||
public synchronized void sendIAM() {
|
||||
if (this.enemy == null) throw new RuntimeException("enemy has not yet been defined");
|
||||
socket.send(new SocketPackage("IAM", GameController.boardSizeToSemester(this.wantedBoardSize) + " " + this.enemy.name));
|
||||
}
|
||||
|
||||
/**
|
||||
* receives a shot from the enemy and sends it to the online partner
|
||||
* if it is not the enemies turn, this method does nothing.
|
||||
* @param point the point to be shot
|
||||
* @author Peer Ole Wachtel, Luca Conte
|
||||
*/
|
||||
@Override
|
||||
public synchronized void receiveShoot(Point point){
|
||||
if (!this.enemy.myTurn) return;
|
||||
super.socket.send(new SocketPackage("SHOOT",point.toString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* receives a hitresponse from the enemy player and sends it to the online partner
|
||||
* @param hitResponse the hitresponse to be sent
|
||||
* @author Peer Ole Wachtel, Luca Conte
|
||||
*/
|
||||
@Override
|
||||
public synchronized void receiveHit(HitResponse hitResponse) {
|
||||
switch (hitResponse.getType()) {
|
||||
case HIT, SUNK:
|
||||
this.myTurn = true;
|
||||
break;
|
||||
case MISS:
|
||||
this.myTurn = false;
|
||||
break;
|
||||
|
||||
case VICTORY:
|
||||
// GameController.getMainFrame().showPanelLose("", this.enemy);
|
||||
break;
|
||||
}
|
||||
super.socket.send(new SocketPackage("HIT", hitResponse.toString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* receives the coin toss result from the enemy player and sends it to the online partner
|
||||
* if this player has already received the enemies coin, this method does nothing.
|
||||
* @param coin the result of the coin toss
|
||||
* @author Peer Ole Wachtel, Luca Conte
|
||||
*/
|
||||
@Override
|
||||
public synchronized void receiveCoin(boolean coin) {
|
||||
if (!this.hasReceivedCoin) {
|
||||
|
@ -164,25 +92,8 @@ public class OnlinePlayer_1_1_0 extends OnlinePlayer {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* für Online Player nicht zu implementieren
|
||||
* nur für HumanPlayer relevant
|
||||
* @author Luca Conte, Peer Ole Wachtel
|
||||
*/
|
||||
@Override
|
||||
public synchronized void shoot(Point point) {
|
||||
// SHOULD NEVER BE CALLED ON ONLINE PLAYER. ONLY ON HUMAN PLAYER
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* empfängt Withdraw vom Gegner und leitet es an den Online Partner weiter
|
||||
* beendet das Spiel
|
||||
* @author Luca Conte
|
||||
*/
|
||||
@Override
|
||||
public void receiveWithdraw() {
|
||||
this.socket.send(new SocketPackage("WITHDRAW"));
|
||||
super.receiveWithdraw();
|
||||
super.socket.send(new SocketPackage("SHOOT", point.toString()));
|
||||
}
|
||||
}
|
131
src/Player.java
131
src/Player.java
|
@ -1,7 +1,3 @@
|
|||
/**
|
||||
* abstrakte repräsentation eines Spielers
|
||||
* @author Peer Ole Wachtel, Luca Conte, Lucas Bronson
|
||||
*/
|
||||
public abstract class Player {
|
||||
protected boolean myTurn;
|
||||
protected boolean isServer;
|
||||
|
@ -16,10 +12,6 @@ public abstract class Player {
|
|||
|
||||
protected boolean hasReceivedCoin;
|
||||
|
||||
/**
|
||||
* Konstruktor
|
||||
* @author Peer Ole Wachtel, Luca Conte
|
||||
*/
|
||||
public Player() {
|
||||
this.setName("Player");
|
||||
this.hasReceivedCoin = false;
|
||||
|
@ -28,85 +20,35 @@ public abstract class Player {
|
|||
this.gameRunning = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* initialises this players board
|
||||
* @param size the size of the board to be created
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public void createBoard(int size) {
|
||||
this.board = new Board(size);
|
||||
}
|
||||
|
||||
/**
|
||||
* receives a shot onto a point from the enemy
|
||||
* @param point the location to be shot
|
||||
* @author Luca Conte, Peer Ole Wachtel
|
||||
*/
|
||||
public abstract void receiveShoot(Point point);
|
||||
|
||||
/**
|
||||
* receives a hit response from the enemy as a response to a receiveShoot call
|
||||
* @param hitResponse the hitresponse
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public abstract void receiveHit(HitResponse hitResponse);
|
||||
|
||||
/**
|
||||
* sends shot to enemy player.
|
||||
* should ONLY be called on HumanPlayer
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public abstract void shoot(Point point);
|
||||
|
||||
/**
|
||||
* only relevant for AI Players.
|
||||
* starts the first turn
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public void beginTurn() {
|
||||
System.out.println("issa my turn-a");
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the enemy Player
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public void setEnemy(Player enemy) {
|
||||
this.enemy = enemy;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the name of this player
|
||||
* @param name the name of this player
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the name of this player
|
||||
* @return the name of this player
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the board of this player
|
||||
* @return the board of this player
|
||||
* @author Lucas Bronson
|
||||
*/
|
||||
public Board getBoard() {
|
||||
return this.board;
|
||||
}
|
||||
|
||||
/**
|
||||
* marks the player as ready by sending their coin to the enemy player
|
||||
* calls determineCoinToss if the enemy coin has already been received
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public void ready() {
|
||||
this.enemy.receiveCoin(this.myCoin);
|
||||
this.sentCoin = true;
|
||||
|
@ -115,11 +57,6 @@ public abstract class Player {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* determines the result of the coin toss
|
||||
* this method does nothing if either player is not ready yet or has not yet sent their coin
|
||||
* @author Luca Conte, Peer Ole Wachtel
|
||||
*/
|
||||
protected void determineCoinToss() {
|
||||
if (!this.sentCoin || this.myCoin == null || !this.hasReceivedCoin || this.enemy.myCoin == null) return;
|
||||
boolean result = this.enemy.myCoin ^ this.myCoin; // XOR
|
||||
|
@ -131,81 +68,13 @@ public abstract class Player {
|
|||
GameController.getMainFrame().refreshGameBoard();
|
||||
}
|
||||
|
||||
/**
|
||||
* receives the coin toss from the enemy player
|
||||
* @param coin the coin of the enemy player
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public abstract void receiveCoin(boolean coin);
|
||||
|
||||
/**
|
||||
* returns whether the game this player is in has started, meaning both players are ready and have sent their coins
|
||||
* @return the game's running state
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public boolean isGameRunning() {
|
||||
return this.gameRunning;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns whether this player is ready and has sent their coin to the enemy player
|
||||
* @return the player's ready state
|
||||
* @author Lucas Bronson
|
||||
*/
|
||||
public boolean isReady() {
|
||||
return this.sentCoin;
|
||||
}
|
||||
|
||||
/**
|
||||
* removes connections to the enemy and its board as well as setting myTurn and gameRunning to false
|
||||
* this stops the AI Players from making more moves and allows the garbage collector to remove the boards
|
||||
* and players
|
||||
*
|
||||
* This method should be called at the end of a game
|
||||
*
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public void destroy() {
|
||||
this.myTurn = false;
|
||||
this.gameRunning = false;
|
||||
this.board = null;
|
||||
this.enemy = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* the player wins
|
||||
* ends the game
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public void win() {
|
||||
GameController.getMainFrame().showPanelWin("", this);
|
||||
}
|
||||
|
||||
/**
|
||||
* the player loses
|
||||
* ends the game
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public void lose() {
|
||||
GameController.getMainFrame().showPanelLose("", this);
|
||||
}
|
||||
|
||||
/**
|
||||
* the player loses by withdrawal
|
||||
* ends the game
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public void withdraw() {
|
||||
this.enemy.receiveWithdraw();
|
||||
this.lose();
|
||||
}
|
||||
|
||||
/**
|
||||
* the enemy player withdraws
|
||||
* ends the game
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public void receiveWithdraw(){
|
||||
this.win();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,32 +1,11 @@
|
|||
/**
|
||||
* repräsentation der Koordinaten eines Feldes auf dem Spielfeld
|
||||
* @author Peer Ole Wachtel, Luca Conte
|
||||
*/
|
||||
public class Point {
|
||||
private int x;
|
||||
private int y;
|
||||
|
||||
/**
|
||||
* initialises a point using X and Y coordinates starting at 0
|
||||
* @param x the x coordinate of the point starting at 0
|
||||
* @param y the y coordinate of the point starting at 0
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public Point (int x, int y) {
|
||||
this.setX(x);
|
||||
this.setY(y);
|
||||
}
|
||||
|
||||
/**
|
||||
* initialises a Point using a coordinate provided in the format of a letter followed by a number
|
||||
* this coordinate is checked using `isValidSyntax`
|
||||
* If the coordinate is not in a valid syntax, an `IllegalArgumentException` will be thrown, stating as such
|
||||
* The number part of the coordinate starts at 1 instead of 0 so for example, the
|
||||
* string A1 will result in the X and Y coordinates of (0, 0)
|
||||
* @param str the coordinate in alphanumeric format
|
||||
* @throws IllegalArgumentException if the coordinate is invalid according to `isValidSyntax`
|
||||
* @author Peer Ole Wachtel, Luca Conte
|
||||
*/
|
||||
public Point (String str) {
|
||||
if (Point.isValidSyntax(str)) {
|
||||
this.setX(str.charAt(0));
|
||||
|
@ -36,78 +15,34 @@ public class Point {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns this point as a string in its alphanumeric format
|
||||
* @return this point as a string in its alphanumeric format
|
||||
* @author Luca Conte, Peer Ole Wachtel
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return (char) ('A' + this.x) + String.valueOf(this.y + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the X coordinate of the point starting at 0
|
||||
* @return the X coordinate of the point starting at 0
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the Y coordinate of the point starting at 0
|
||||
* @return the Y coordinate of the point starting at 0
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the X coordinate of the point starting at 0
|
||||
* @param x the X coordinate of the point starting at 0
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the Y coordinate of the point starting at 0
|
||||
* @param y the Y coordinate of the point starting at 0
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the X coordinate of the from its character value in alphanumeric form
|
||||
* @param c the character to be transformed into
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public void setX(char c) {
|
||||
this.x = c - 'A';
|
||||
}
|
||||
|
||||
/**
|
||||
* checks whether a string is a valid alphanumeric point coordinate
|
||||
* @param str the string to be tested
|
||||
* @return whether the string is valid according to the regular expression `^[A-Z]\\d+$`
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public static boolean isValidSyntax(String str) {
|
||||
return str.matches("^[A-Z]\\d+$");
|
||||
}
|
||||
|
||||
/**
|
||||
* returns whether two points are equal
|
||||
* two points with equivalent coordinates are considered equal
|
||||
* @param o the other object/Point to compare this one to
|
||||
* @return whether the objects are equal
|
||||
* @author Luca Conte
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
@ -117,13 +52,6 @@ public class Point {
|
|||
return p.getX() == this.getX() && p.getY() == this.getY();
|
||||
}
|
||||
|
||||
/**
|
||||
* determines whether two points are neighbours
|
||||
* points are considered neighbours if their positions are equal or within a difference of 1 on both X and Y axis
|
||||
* @param other the point to check for neighbourship
|
||||
* @return whether the points are neighbours
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public boolean neighbours(Point other) {
|
||||
if (other == null) return false;
|
||||
return (int)Math.abs(this.getX() - other.getX()) <= 1 && (int)Math.abs(this.getY() - other.getY()) <= 1;
|
||||
|
|
181
src/Ship.java
181
src/Ship.java
|
@ -5,56 +5,44 @@ import java.util.List;
|
|||
|
||||
record ShipData (int size, String name){}
|
||||
|
||||
/**
|
||||
* repräsentation eines Schiffes auf dem Spielfeld
|
||||
* @author Peer Ole Wachtel, Lucas Bronson, Florian Hanzschel
|
||||
*/
|
||||
public class Ship {
|
||||
static List<List<ShipData>> semeterList =
|
||||
Arrays.asList(
|
||||
Arrays.asList(
|
||||
new ShipData(2, "PRG 1"),
|
||||
new ShipData(2, "GDI"),
|
||||
new ShipData(2, "MAT 1"),
|
||||
new ShipData(2, "THI"),
|
||||
new ShipData(4, "STP"),
|
||||
new ShipData(6, "ENG")
|
||||
),
|
||||
Arrays.asList(
|
||||
new ShipData(2, "PRG 2"),
|
||||
new ShipData(2, "DBS 1"),
|
||||
new ShipData(2, "MAT 2"),
|
||||
new ShipData(2, "STA"),
|
||||
new ShipData(2, "AUD")
|
||||
),
|
||||
Arrays.asList(
|
||||
new ShipData(2, "PRG 3"),
|
||||
new ShipData(2, "DBS 2"),
|
||||
new ShipData(2, "MAT 3"),
|
||||
new ShipData(2, "BSN 1"),
|
||||
new ShipData(4, "PRP"),
|
||||
new ShipData(6, "BWL")
|
||||
),
|
||||
Arrays.asList(
|
||||
new ShipData(2, "WEB"),
|
||||
new ShipData(2, "SE 1"),
|
||||
new ShipData(2, "CG 1"),
|
||||
new ShipData(2, "BSN 2"),
|
||||
new ShipData(4, "SEM"),
|
||||
new ShipData(6, "E BWL")
|
||||
),
|
||||
Arrays.asList(
|
||||
new ShipData(2, "WPF 1"),
|
||||
new ShipData(2, "SE 2"),
|
||||
new ShipData(2, "CG 2"),
|
||||
new ShipData(2, "PXP 1"),
|
||||
new ShipData(6, "EF 1")
|
||||
),
|
||||
Arrays.asList(
|
||||
new ShipData(2, "WPF 2"),
|
||||
new ShipData(1, "PXP 2"),
|
||||
new ShipData(8, "BAA")
|
||||
)
|
||||
static List<List<ShipData>> semeterList = Arrays.asList(Arrays.asList(
|
||||
new ShipData(2, "PRG 1"),
|
||||
new ShipData(2, "GDI"),
|
||||
new ShipData(2, "MAT 1"),
|
||||
new ShipData(2, "THI"),
|
||||
new ShipData(4, "STP"),
|
||||
new ShipData(6, "ENG")),
|
||||
Arrays.asList(
|
||||
new ShipData(2, "PRG 2"),
|
||||
new ShipData(2, "DBS 1"),
|
||||
new ShipData(2, "MAT 2"),
|
||||
new ShipData(2, "STA"),
|
||||
new ShipData(2, "AUD")),
|
||||
Arrays.asList(
|
||||
new ShipData(2, "PRG 3"),
|
||||
new ShipData(2, "DBS 2"),
|
||||
new ShipData(2, "MAT 3"),
|
||||
new ShipData(2, "BSN 1"),
|
||||
new ShipData(4, "PRP"),
|
||||
new ShipData(6, "BWL")),
|
||||
Arrays.asList(
|
||||
new ShipData(2, "WEB"),
|
||||
new ShipData(2, "SE 1"),
|
||||
new ShipData(2, "CG 1"),
|
||||
new ShipData(2, "BSN 2"),
|
||||
new ShipData(4, "SEM"),
|
||||
new ShipData(6, "E BWL")),
|
||||
Arrays.asList(
|
||||
new ShipData(2, "WPF 1"),
|
||||
new ShipData(2, "SE 2"),
|
||||
new ShipData(2, "CG 2"),
|
||||
new ShipData(2, "PXP 1"),
|
||||
new ShipData(6, "EF 1")),
|
||||
Arrays.asList(
|
||||
new ShipData(2, "WPF 2"),
|
||||
new ShipData(1, "PXP 2"),
|
||||
new ShipData(8, "BAA"))
|
||||
);
|
||||
|
||||
private int size;
|
||||
|
@ -64,12 +52,6 @@ public class Ship {
|
|||
private int hitsOnMe;
|
||||
private boolean sunk;
|
||||
|
||||
/**
|
||||
* initialises a Ship with a given size and name
|
||||
* @param size the size of the ship
|
||||
* @param name the name of the ship
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public Ship (int size, String name) {
|
||||
this.size = size;
|
||||
this.name = name;
|
||||
|
@ -79,23 +61,10 @@ public class Ship {
|
|||
this.sunk = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* resets the position of this ship
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public void resetPosition() {
|
||||
this.position = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the position of this ship, provided it is valid
|
||||
* @param pos the position to move the ship to
|
||||
* @param horizontal whether the ship is horizontal or not
|
||||
* @param shipsList the list of other ships on this board. It will be checked whether the ship is touching any of them
|
||||
* @param boardSize the size of the board the ship is to be placed on
|
||||
* @return true if the position was set successfully. false if the ship is out of the bounds of the board or touches a different ship
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public boolean setPosition(Point pos, boolean horizontal, List<Ship> shipsList, int boardSize) {
|
||||
if (!this.checkValidPlacement(pos, horizontal, shipsList, boardSize)) return false;
|
||||
|
||||
|
@ -105,15 +74,6 @@ public class Ship {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* checks whether a position is valid for ship placement
|
||||
* @param pos the position to check the ship placement at
|
||||
* @param horizontal whether the ship is to be placed horizontally or not
|
||||
* @param shipsList the list of other ships on this board. It will be checked whether the ship is touching any of them
|
||||
* @param boardSize the size of the board the ship is to be placed on
|
||||
* @return true if the position is valid. false if the ship is out of the bounds of the board or touches a different ship
|
||||
* @author Florian Hantzschel, Peer Ole Wachtel, Luca Conte
|
||||
*/
|
||||
public boolean checkValidPlacement(Point pos, boolean horizontal, List<Ship> shipsList, int boardSize) {
|
||||
// ueberpruefe boundaries
|
||||
if (pos.getX() < 0 || pos.getY() < 0 || pos.getX() >= boardSize || pos.getY() >= boardSize) {
|
||||
|
@ -162,11 +122,7 @@ public class Ship {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the Points on the ship if it were to be placed at position `pos` in orientation defined by `horizontal`
|
||||
* @param pos the position where the ship should be placed
|
||||
* @param horizontal whether the ship should be placed horizontally
|
||||
* @return a list of points the ship would occupy, were it placed at position `pos` in orientation `horizontal`
|
||||
* @author Florian Hantzschel, Luca Conte
|
||||
* Returns the Points on the ship if it were to be placed at positino `pos` in orientation defined by `horizontal`
|
||||
*/
|
||||
public List<Point> getVirtualOccupiedPoints(Point pos, boolean horizontal) {
|
||||
List<Point> points = new ArrayList<>();
|
||||
|
@ -181,30 +137,23 @@ public class Ship {
|
|||
return points;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Points the ship occupies
|
||||
* @return a list of points the ship occupies
|
||||
* @author Florian Hantzschel, Luca Conte
|
||||
*/
|
||||
public List<Point> getOccupiedPoints() {
|
||||
return this.getVirtualOccupiedPoints(this.position, this.horizontal);
|
||||
List<Point> points = new ArrayList<>();
|
||||
if (this.position == null) {
|
||||
return points;
|
||||
}
|
||||
for (int i = 0; i < this.size; i++) {
|
||||
int x = this.horizontal ? this.position.getX() + i : this.position.getX();
|
||||
int y = this.horizontal ? this.position.getY() : this.position.getY() + i;
|
||||
points.add(new Point(x, y));
|
||||
}
|
||||
return points;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the position of this ship
|
||||
* @return the position of this ship
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public Point getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
/**
|
||||
* checks whether the ship occupies a certain point
|
||||
* @param pos the point to be checkd
|
||||
* @return whether the point provided is one of the points occupied by the ship
|
||||
* @author Peer Ole Wachtel, Lucas Bronson
|
||||
*/
|
||||
public boolean isShipOnPos(Point pos){
|
||||
if(this.position == null){
|
||||
return false;
|
||||
|
@ -216,13 +165,6 @@ public class Ship {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* "shoots" this ship.
|
||||
* @return a hit response, depending on whether the ship was hit or not. If the amount of times
|
||||
* the ship was hit is greater or equal to the size of the ship, the ship is considered sunk.
|
||||
* @param pos the point where the ship is shot
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public HitResponseType shootOnShip(Point pos) {
|
||||
if (this.isShipOnPos(pos)) {
|
||||
hitsOnMe++;
|
||||
|
@ -237,47 +179,22 @@ public class Ship {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns whether the ship has been sunk or not
|
||||
* @return whether the ship has been sunk or not
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public boolean isSunk() {
|
||||
return sunk;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the orientation of the ship
|
||||
* @param horizontal whether the ship is to be placed in a horizontal orientation
|
||||
* @author Lucas Bronson
|
||||
*/
|
||||
public void setHorizontal(boolean horizontal) {
|
||||
this.horizontal = horizontal;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the size of the ship
|
||||
* @return the size of the ship
|
||||
* @author Lucas Bronson
|
||||
*/
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the name of the ship
|
||||
* @return the name of the ship
|
||||
* @author Lucas Bronson
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns whether the ship has been placed or not
|
||||
* @return whether the ship has been placed or not
|
||||
* @author Lucas Bronson
|
||||
*/
|
||||
//potentiell falsch neu
|
||||
public boolean isPlaced(){
|
||||
return this.position != null;
|
||||
}
|
||||
|
|
|
@ -11,9 +11,9 @@ public class ShipButton extends JButton {
|
|||
private BoardDisplay boardDisplay;
|
||||
|
||||
/**
|
||||
* Erstellt Buttons für die beiden Spieler (Module/Schiffe)
|
||||
* @param ship Schiff von welchem der Name genommen wird
|
||||
* @param boardDisplay Klasse für Interaktion
|
||||
* TODO fertig beschreiben
|
||||
* @param ship
|
||||
* @param boardDisplay
|
||||
* @author Lucas Bronson, Luca Conte, Joshua Kuklok
|
||||
*/
|
||||
public ShipButton(Ship ship, BoardDisplay boardDisplay) {
|
||||
|
|
|
@ -1,39 +1,17 @@
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
/**
|
||||
* beschreibt ein Package das durch einen AsyncSocket gesendet werden kann nach Netzwerkstandard
|
||||
* https://github.com/lgc-4/ProgProjekt-Netzwerkstandard
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public class SocketPackage {
|
||||
|
||||
private String name = "";
|
||||
private String data = "";
|
||||
|
||||
/**
|
||||
* initialises a socket package by prividing a package name and data
|
||||
* @param name the name of the package
|
||||
* @param data the data of the package
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public SocketPackage(String name, String data) {
|
||||
this.setName(name);
|
||||
this.setData(data);
|
||||
}
|
||||
/**
|
||||
* initialises an empty socket package
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public SocketPackage() {
|
||||
this("","");
|
||||
}
|
||||
|
||||
/**
|
||||
* initialises a socket package from a message
|
||||
* the message is parsed according to https://github.com/lgc-4/ProgProjekt-Netzwerkstandard
|
||||
* @param message the message to be parsed
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public SocketPackage(String message) {
|
||||
if (message.length() <= 0) {
|
||||
throw new IllegalArgumentException("Socket message cannot be empty.");
|
||||
|
@ -47,51 +25,24 @@ public class SocketPackage {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the package name
|
||||
* the name is always stored in upper case
|
||||
* @param name the new name of the package
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public void setName(String name) {
|
||||
if (name == null) name = "";
|
||||
this.name = name.toUpperCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the package data
|
||||
* @param name the new data of the package
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public void setData(String data) {
|
||||
if (data == null) data = "";
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the name of the package
|
||||
* @return the name of the package
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the data of the package
|
||||
* @return the data of the package
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public String getData() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* parses the package into a string according to https://github.com/lgc-4/ProgProjekt-Netzwerkstandard
|
||||
* the package name and data are joined using a space " " `0x20`
|
||||
* @return the package in string format
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public String toString() {
|
||||
if (this.data == null || this.data.length() == 0) {
|
||||
return this.name;
|
||||
|
@ -100,11 +51,6 @@ public class SocketPackage {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the data string as a list, split at every space " " `0x20`
|
||||
* @return the data string as a list, split at every space " " `0x20`
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public List<String> splitData() {
|
||||
return Arrays.asList(this.data.split(" "));
|
||||
}
|
||||
|
|
|
@ -25,9 +25,7 @@ public class SoundHandler {
|
|||
"hit", "./Sound/hit.mp3",
|
||||
"destroyed", "./Sound/hit.mp3",
|
||||
"plop", "./Sound/plop.mp3",
|
||||
"loose", "./Sound/loosescreenlaugh.mp3",
|
||||
"win", "./Sound/win.mp3",
|
||||
"yourturn", "./Sound/yourturn.mp3"
|
||||
"loose", "./Sound/loosescreenWAH.mp3"
|
||||
));
|
||||
|
||||
/**
|
||||
|
@ -69,9 +67,9 @@ public class SoundHandler {
|
|||
}
|
||||
|
||||
/**
|
||||
* fügt einen neuen Sound zum SoundHanlder hinzu
|
||||
* @param soundName der intern zu verwendende Name des Sounds
|
||||
* @param path der Dateipfad zur Sound Datei
|
||||
* TODO funktion beschreiben (potentiell nicht benötigte Funktion?)
|
||||
* @param soundName
|
||||
* @param path
|
||||
* @author Ole Wachtel
|
||||
*/
|
||||
static void add(String soundName, String path){
|
||||
|
@ -79,8 +77,8 @@ public class SoundHandler {
|
|||
}
|
||||
|
||||
/**
|
||||
* schaltet den Ton an oder aus
|
||||
* @param sound ob der sound an ist
|
||||
* TODO funktion beschreiben (potentiell nicht benötigte Funktion?)
|
||||
* @param sound
|
||||
* @author Ole Wachtel
|
||||
*/
|
||||
static void setSoundOn(boolean sound){
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
/**
|
||||
* Diese Klasse implementiert den Einfachsten Ki Spieler.
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
* @author Florian und Florian
|
||||
* */
|
||||
public class SpecificAiPlayerEasy extends AiPlayer{
|
||||
|
||||
/**
|
||||
* Bein einfachen Ki Spieler wird nur der AiPlayer initialisiert und der Name gesetzt,
|
||||
* da in der Eltern-Klasse AiPlayer eine default implementierung für alle Methoden existieren.
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
*/
|
||||
public SpecificAiPlayerEasy() {
|
||||
super();
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
import java.util.ArrayList;
|
||||
// import java.util.Random; wird nicht mehr verwendet
|
||||
|
||||
/**
|
||||
* Diese Klasse implementiert den Harten Ki Spieler.
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
* @author Florian und Florian
|
||||
* */
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
public class SpecificAiPlayerHard extends AiPlayer{
|
||||
|
||||
private int gridSize;
|
||||
private boolean[][] shotsFired;
|
||||
private final ArrayList<Point> hitQueue;
|
||||
//private final Random random; wird nicht mehr verwendet
|
||||
private final Random random;
|
||||
private int nextChessRow;
|
||||
private int nextChessCol;
|
||||
|
||||
|
@ -21,15 +21,10 @@ public class SpecificAiPlayerHard extends AiPlayer{
|
|||
VERTIKAL
|
||||
}
|
||||
private Orientierung orientierung;
|
||||
// Speichert den ersten Treffer zur Bestimmung der Orientierung
|
||||
private Point firstHit;
|
||||
private Point firstHit; // Speichert den ersten Treffer zur Bestimmung der Orientierung
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Eltern-Klasse wird initialisiert und alle lokalen variablen,
|
||||
* die gesetzt werden können, werden initialisiert.
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
*/
|
||||
public SpecificAiPlayerHard() {
|
||||
super();
|
||||
this.setName("AI Player Hard");
|
||||
|
@ -37,28 +32,19 @@ public class SpecificAiPlayerHard extends AiPlayer{
|
|||
this.shotsFired = new boolean[gridSize][gridSize];*/
|
||||
this.gridSize = 0;
|
||||
this.hitQueue = new ArrayList<>();
|
||||
//this.random = new Random(); wird nicht mehr verwendet
|
||||
this.random = new Random();
|
||||
this.nextChessRow = 0;
|
||||
this.nextChessCol = 0;
|
||||
this.orientierung = Orientierung.UNBEKANNT;
|
||||
this.firstHit = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft, ob auf den punkt schonmal geschossen wurde.
|
||||
* @param p zu prüfender Punkt
|
||||
* @return boolean
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
*/
|
||||
// Checks if a position has already been shot at
|
||||
public boolean alreadyShot(Point p) {
|
||||
return shotsFired[p.getX()][p.getY()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Bestimmt den nächsten punkt, der beschossen werden soll.
|
||||
* @return Position
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
*/
|
||||
// Generates the next move for the AI
|
||||
public Point getNextMove() {
|
||||
if(gridSize == 0) {
|
||||
this.gridSize = super.board.getSize();
|
||||
|
@ -87,12 +73,6 @@ public class SpecificAiPlayerHard extends AiPlayer{
|
|||
return new Point(row, col);
|
||||
}
|
||||
|
||||
/**
|
||||
* Nachdem receiveShoot beim gegner den schuss verarbeitet hat,
|
||||
* wird diese Methode mit der antwort aufgerufen.
|
||||
* @param hitResponse the hitresponse
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
*/
|
||||
@Override
|
||||
public synchronized void receiveHit(HitResponse hitResponse) {
|
||||
super.receiveHit(hitResponse);
|
||||
|
@ -133,7 +113,6 @@ public class SpecificAiPlayerHard extends AiPlayer{
|
|||
|
||||
/**
|
||||
* Entfernt aus der hitQueue alle Punkte, die nicht der erkannten Orientierung entsprechen.
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
*/
|
||||
private void cleanUpHitQueue() {
|
||||
if (firstHit == null || this.orientierung == Orientierung.UNBEKANNT) {
|
||||
|
@ -157,10 +136,9 @@ public class SpecificAiPlayerHard extends AiPlayer{
|
|||
}
|
||||
|
||||
/**
|
||||
* Fügt benachbarte Felder in der erkannten Orientierung hinzu.
|
||||
* Ist die Orientierung HORIZONTAL, so werden nur links/rechts hinzugefügt.
|
||||
* Ist sie VERTICAL, so werden nur oben/unten hinzugefügt.
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
* Fügt benachbarte Felder in der **erkannten Orientierung** hinzu.
|
||||
* - Ist die Orientierung HORIZONTAL, so werden nur links/rechts hinzugefügt.
|
||||
* - Ist sie VERTICAL, so werden nur oben/unten hinzugefügt.
|
||||
*/
|
||||
private void addPointsByOrientation(Point point) {
|
||||
if (this.orientierung == Orientierung.UNBEKANNT) {
|
||||
|
@ -200,7 +178,6 @@ public class SpecificAiPlayerHard extends AiPlayer{
|
|||
/**
|
||||
* Diese Methode erweitert die hitsQueue um die umliegenden Punkte die Schiffe seien könnten.
|
||||
* @param point
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
*/
|
||||
private void addAdjacentPoints(Point point) {
|
||||
int x = point.getX();
|
||||
|
@ -224,7 +201,6 @@ public class SpecificAiPlayerHard extends AiPlayer{
|
|||
* Die Methode gibt zurück, ob eine Position auf dem Board ist. (Boolean)
|
||||
* @param point Punkt der geprüft werden soll
|
||||
* @return Ist auf dem Board oder nicht.
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
*/
|
||||
private boolean isValidPoint(Point point) {
|
||||
return point.getX() >= 0 && point.getX() < gridSize &&
|
||||
|
@ -232,17 +208,13 @@ public class SpecificAiPlayerHard extends AiPlayer{
|
|||
}
|
||||
/**
|
||||
* Ki Methode um zu schießen.
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
*/
|
||||
@Override
|
||||
public void aiShoot() {
|
||||
this.enemy.receiveShoot(getNextMove());
|
||||
}
|
||||
|
||||
/**
|
||||
* Die Zeilen und spalten variable wird hier angepasst, sodass beim nächsten schuss im Muster geschossen wird.
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
*/
|
||||
// Advances the chess pattern to the next cell
|
||||
private void advanceChessPattern() {
|
||||
nextChessCol += 2;
|
||||
if (nextChessCol >= gridSize) {
|
||||
|
|
|
@ -1,20 +1,16 @@
|
|||
/**
|
||||
* Diese Klasse implementiert den Medium Ki Spieler.
|
||||
* @author Florian und Florian
|
||||
* */
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Diese Klasse implementiert den Medium Ki Spieler.
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
* */
|
||||
public class SpecificAiPlayerMedium extends AiPlayer{
|
||||
/**
|
||||
* Liste an Punkten die beschossen werden sollen. (Mögliche weitere Segmente vom schiff)
|
||||
*/
|
||||
private List<Point> hitsQueue = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Eltern-Klasse wird initialisiert und der Name wird gesetzt.
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
*/
|
||||
public SpecificAiPlayerMedium() {
|
||||
super();
|
||||
this.setName("AI Player Medium");
|
||||
|
@ -22,7 +18,6 @@ public class SpecificAiPlayerMedium extends AiPlayer{
|
|||
|
||||
/**
|
||||
* Ki Methode um zu schießen.
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
*/
|
||||
@Override
|
||||
public void aiShoot() {
|
||||
|
@ -31,12 +26,6 @@ public class SpecificAiPlayerMedium extends AiPlayer{
|
|||
enemy.receiveShoot(nextShot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Nachdem receiveShoot beim gegner den schuss verarbeitet hat,
|
||||
* wird diese Methode mit der antwort aufgerufen.
|
||||
* @param hitResponse the hitresponse
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
*/
|
||||
@Override
|
||||
public synchronized void receiveHit(HitResponse hitResponse) {
|
||||
super.receiveHit(hitResponse);
|
||||
|
@ -48,8 +37,7 @@ public class SpecificAiPlayerMedium extends AiPlayer{
|
|||
|
||||
/**
|
||||
* Die Methode bestimmt welche Position als nächstes beschossen werden soll.
|
||||
* @return der Punkt auf den als nächtest geschossen werden soll
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
* @return
|
||||
*/
|
||||
public Point ComputeNextShot() {
|
||||
Point nextShot;
|
||||
|
@ -72,8 +60,7 @@ public class SpecificAiPlayerMedium extends AiPlayer{
|
|||
|
||||
/**
|
||||
* Diese Methode erweitert die hitsQueue um die umliegenden Punkte die Schiffe seien könnten.
|
||||
* @param point der Punkt dessen nachbarn zur hitQueue hinzugefügt werden sollen
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
* @param point
|
||||
*/
|
||||
private void addAdjacentPoints(Point point) {
|
||||
int x = point.getX();
|
||||
|
@ -98,7 +85,6 @@ public class SpecificAiPlayerMedium extends AiPlayer{
|
|||
* Diese Methode gibt zurück, ob eine Position schon beschossen wurde. (Boolean)
|
||||
* @param p Punkt der geprüft werden soll
|
||||
* @return wurde schon beschossen oder nicht.
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
*/
|
||||
private boolean alreadyShot(Point p) {
|
||||
|
||||
|
@ -110,7 +96,6 @@ public class SpecificAiPlayerMedium extends AiPlayer{
|
|||
* Die Methode gibt zurück, ob eine Position auf dem Board ist. (Boolean)
|
||||
* @param point Punkt der geprüft werden soll
|
||||
* @return Ist auf dem Board oder nicht.
|
||||
* @author Florian Alexy und Florian Hantzschel
|
||||
*/
|
||||
private boolean isValidPoint(Point point) {
|
||||
return point.getX() >= 0 && point.getX() < board.getSize() &&
|
||||
|
|
|
@ -7,7 +7,7 @@ import java.awt.*;
|
|||
*/
|
||||
public class Verbinden extends JPanel{
|
||||
|
||||
//ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
|
||||
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
|
||||
|
||||
JLabel verbindenLabel = new JLabel("Verbinde . . .",SwingConstants.CENTER);
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ public class WinScreen extends JPanel {
|
|||
/**
|
||||
* Panel bauen/Objekte hinzufuegen
|
||||
* @param frame Der Mainframe der Anwendung über den alle Panels angezeigt werden.
|
||||
* @author Lucas Bronson, Joshua Kuklok
|
||||
* @author Lucas Bronson
|
||||
*/
|
||||
public void buildPanel(MainFrame frame) {
|
||||
Timer timer = new Timer(5, new ActionListener() {
|
||||
|
@ -50,14 +50,13 @@ public class WinScreen extends JPanel {
|
|||
timer.start(); // Timer starten
|
||||
winLabel.setFont(robotoFont);
|
||||
winLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
SoundHandler.playSound("win");
|
||||
|
||||
// Zurückkehren zum Hauptmenü, wenn okButton gedrückt wird
|
||||
//Zurückkehren zum Hauptmenü, wenn okButton gedrückt wird
|
||||
okButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
frame.showPanel("MainMenu");
|
||||
}
|
||||
|
||||
});
|
||||
add(winLabel);
|
||||
add(okButton);
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
// TODO Klasse löschen da nicht gebraucht
|
||||
public class coinToss extends JPanel {
|
||||
private int reihenfolge = 1; // 1 = Spieler 1 fängt an, 0 = Spieler 2 fängt an
|
||||
private Timer timer;
|
||||
private JLabel infoLabel;
|
||||
|
||||
// Konstruktor
|
||||
public coinToss(MainFrame frame) {
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
// Info-Label für den Anzeigetext
|
||||
infoLabel = new JLabel("", SwingConstants.CENTER);
|
||||
infoLabel.setFont(new Font("Arial", Font.BOLD, 24));
|
||||
add(infoLabel, BorderLayout.CENTER);
|
||||
|
||||
// Bestimme den Anfangstext basierend auf der "reihenfolge" Variable
|
||||
if (reihenfolge == 1) {
|
||||
infoLabel.setText("Du fängst an, mach dich bereit...");
|
||||
} else {
|
||||
infoLabel.setText("Dein Gegner fängt an, mach dich bereit...");
|
||||
}
|
||||
|
||||
// Erster Timer, der den Text nach 3 Sekunden auf "Es geht Los!" setzt
|
||||
/*timer = new Timer(3000, e -> {
|
||||
infoLabel.setText("Es geht Los!");
|
||||
|
||||
// Zweiter Timer, der nach weiteren 3 Sekunden zum Hauptmenü zurückkehrt
|
||||
Timer backToMenuTimer = new Timer(3000, ev -> {
|
||||
frame.showPanel("MainMenu");
|
||||
});
|
||||
//backToMenuTimer.setRepeats(false); // Timer nur einmal ausführen
|
||||
backToMenuTimer.start();
|
||||
});
|
||||
//timer.setRepeats(false); // Erster Timer soll nur einmal ausgeführt werden
|
||||
timer.start();*/
|
||||
}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.HashMap;
|
||||
|
@ -7,9 +6,13 @@ import java.util.HashMap;
|
|||
/**
|
||||
* Das startLocalGame Panel dient dem Erstellen eines lokalen Spiels.
|
||||
* Hier kann der Benutzer Spieler inklusive Namen und das Semester, in dem sich der Benutzer befindet, einstellen.
|
||||
* @author Lucas Bronson, Joshua Kuklok, Luca Conte
|
||||
* @author Lucas Bronson, Joshua Kuklok
|
||||
*/
|
||||
public class startLocalGame extends JPanel {
|
||||
// Player
|
||||
// TODO: entfernen (generell auch test button)
|
||||
Player p1;
|
||||
Player p2;
|
||||
|
||||
// Funktionshilfen
|
||||
int semesterCounter = 1; // Semester Counter Label
|
||||
|
@ -41,12 +44,12 @@ public class startLocalGame extends JPanel {
|
|||
JButton rightPlayerLeftButton = new JButton("<-");
|
||||
JButton rightPlayerRightButton = new JButton("->");
|
||||
JButton startButton = new JButton("Start!");
|
||||
JButton testButton = new JButton("Test");
|
||||
|
||||
// Textfelder
|
||||
JTextField leftPlayerTextField = new JTextField(20);
|
||||
JTextField rightPlayerTextField = new JTextField(20);
|
||||
|
||||
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
|
||||
/**
|
||||
* Konstruktor der startLocalGame.
|
||||
* Fügt Buttons, Textfelder und Label hinzu.
|
||||
|
@ -60,8 +63,7 @@ public class startLocalGame extends JPanel {
|
|||
setLayout(null);
|
||||
|
||||
// Setze Komponentenpositionen
|
||||
frameTitle.setBounds(20, 20, 500, 60);
|
||||
frameTitle.setFont(robotoFont.deriveFont(50f));
|
||||
frameTitle.setBounds(20, 20, 200, 30);
|
||||
add(frameTitle);
|
||||
|
||||
semesterLabel.setBounds(700, 300, 200, 30);
|
||||
|
@ -79,10 +81,13 @@ public class startLocalGame extends JPanel {
|
|||
rightPlayerIcon.setBounds(1225, 400, 200, 128);
|
||||
add(rightPlayerIcon);
|
||||
|
||||
semesterCounterLabel.setBounds(705, 475, 50, 50);
|
||||
semesterCounterLabel.setBounds(725, 475, 50, 50);
|
||||
semesterCounterLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
add(semesterCounterLabel);
|
||||
|
||||
testButton.setBounds(500,800,50,50);
|
||||
add(testButton);
|
||||
|
||||
backButton.setBounds(1380, 20, 80, 80);
|
||||
add(backButton);
|
||||
|
||||
|
@ -92,10 +97,10 @@ public class startLocalGame extends JPanel {
|
|||
leftPlayerRightButton.setBounds(250, 450, 50, 50);
|
||||
add(leftPlayerRightButton);
|
||||
|
||||
semesterUpButton.setBounds(705, 400, 50, 50);
|
||||
semesterUpButton.setBounds(725, 400, 50, 50);
|
||||
add(semesterUpButton);
|
||||
|
||||
semesterDownButton.setBounds(705, 550, 50, 50);
|
||||
semesterDownButton.setBounds(725, 550, 50, 50);
|
||||
add(semesterDownButton);
|
||||
|
||||
rightPlayerLeftButton.setBounds(1200, 450, 50, 50);
|
||||
|
@ -191,6 +196,14 @@ public class startLocalGame extends JPanel {
|
|||
}
|
||||
});
|
||||
|
||||
// Um zum Gameboard zu wechseln.
|
||||
testButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
frame.showPanelWin("WinPanel");
|
||||
}
|
||||
});
|
||||
|
||||
// Um zum startLocalGameLoadingScreen zu wechseln und Daten an Backend weiterzureichen.
|
||||
startButton.addActionListener(new ActionListener() {
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -203,7 +216,7 @@ public class startLocalGame extends JPanel {
|
|||
playerClassMap.put(aiPlayerHardIcon, SpecificAiPlayerHard.class);
|
||||
|
||||
|
||||
frame.showPanelSLGLS("startLocalGameLoadingScreen", semesterCounter);
|
||||
frame.showPanelSLGLS("startLocalGameLoadingScreen", semesterCounter); //TODO
|
||||
|
||||
Class<? extends LocalPlayer> leftPlayerClass = playerClassMap.get(leftPlayerIcon.getIcon());
|
||||
Class<? extends AiPlayer> rightPlayerClass = (Class<? extends AiPlayer>) playerClassMap.get(rightPlayerIcon.getIcon());
|
||||
|
@ -212,6 +225,41 @@ public class startLocalGame extends JPanel {
|
|||
rightPlayerClass,
|
||||
GameController.semesterToBoardSize(semesterCounter)
|
||||
);
|
||||
|
||||
// if (leftPlayerIcon.getIcon() == humanPlayerIcon) {// TODO Wird name wirklich weitergegeben?
|
||||
// if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||
// GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerEasy.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||
// GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerMedium.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||
// GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerHard.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
// }
|
||||
// } else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||
// if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||
// GameController.startLocalGame(SpecificAiPlayerEasy.class, leftPlayerNickname, SpecificAiPlayerEasy.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||
// GameController.startLocalGame(SpecificAiPlayerEasy.class, leftPlayerNickname, SpecificAiPlayerMedium.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||
// GameController.startLocalGame(SpecificAiPlayerEasy.class, leftPlayerNickname, SpecificAiPlayerHard.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
// }
|
||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||
// if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||
// GameController.startLocalGame(SpecificAiPlayerMedium.class, leftPlayerNickname, SpecificAiPlayerEasy.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||
// GameController.startLocalGame(SpecificAiPlayerMedium.class, leftPlayerNickname, SpecificAiPlayerMedium.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||
// GameController.startLocalGame(SpecificAiPlayerMedium.class, leftPlayerNickname, SpecificAiPlayerHard.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
// }
|
||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||
// if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||
// GameController.startLocalGame(SpecificAiPlayerHard.class, leftPlayerNickname, SpecificAiPlayerEasy.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||
// GameController.startLocalGame(SpecificAiPlayerHard.class, leftPlayerNickname, SpecificAiPlayerMedium.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||
// GameController.startLocalGame(SpecificAiPlayerHard.class, leftPlayerNickname, SpecificAiPlayerHard.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -225,13 +273,10 @@ public class startLocalGame extends JPanel {
|
|||
private void toggleLeftPlayerIconLeft() {
|
||||
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
|
||||
leftPlayerIcon.setIcon(aiPlayerHardIcon);
|
||||
|
||||
} else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon){
|
||||
leftPlayerIcon.setIcon(humanPlayerIcon);
|
||||
|
||||
} else if (leftPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||
leftPlayerIcon.setIcon(aiPlayerEasyIcon);
|
||||
|
||||
} else if (leftPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||
leftPlayerIcon.setIcon(aiPlayerNormalIcon);
|
||||
}
|
||||
|
@ -244,13 +289,10 @@ public class startLocalGame extends JPanel {
|
|||
private void toggleLeftPlayerIconRight() {
|
||||
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
|
||||
leftPlayerIcon.setIcon(aiPlayerEasyIcon);
|
||||
|
||||
} else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon){
|
||||
leftPlayerIcon.setIcon(aiPlayerNormalIcon);
|
||||
|
||||
} else if (leftPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||
leftPlayerIcon.setIcon(aiPlayerHardIcon);
|
||||
|
||||
} else if (leftPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||
leftPlayerIcon.setIcon(humanPlayerIcon);
|
||||
}
|
||||
|
@ -263,10 +305,8 @@ public class startLocalGame extends JPanel {
|
|||
private void toggleRightPlayerIconLeft() {
|
||||
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||
rightPlayerIcon.setIcon(aiPlayerHardIcon);
|
||||
|
||||
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon){
|
||||
rightPlayerIcon.setIcon(aiPlayerEasyIcon);
|
||||
|
||||
} else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||
rightPlayerIcon.setIcon(aiPlayerNormalIcon);
|
||||
}
|
||||
|
@ -279,10 +319,8 @@ public class startLocalGame extends JPanel {
|
|||
private void toggleRightPlayerIconRight() {
|
||||
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||
rightPlayerIcon.setIcon(aiPlayerNormalIcon);
|
||||
|
||||
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon){
|
||||
rightPlayerIcon.setIcon(aiPlayerHardIcon);
|
||||
|
||||
} else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||
rightPlayerIcon.setIcon(aiPlayerEasyIcon);
|
||||
}
|
||||
|
@ -296,13 +334,10 @@ public class startLocalGame extends JPanel {
|
|||
// Für Linken Spieler
|
||||
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
|
||||
leftPlayerTextField.setText(leftPlayerNickname);
|
||||
|
||||
} else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon){
|
||||
leftPlayerTextField.setText("Einfach");
|
||||
|
||||
} else if (leftPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||
leftPlayerTextField.setText("Mittel");
|
||||
|
||||
} else if (leftPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||
leftPlayerTextField.setText("Schwer");
|
||||
}
|
||||
|
@ -310,10 +345,8 @@ public class startLocalGame extends JPanel {
|
|||
// Für Rechten Spieler
|
||||
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon){
|
||||
rightPlayerTextField.setText("Einfach");
|
||||
|
||||
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||
rightPlayerTextField.setText("Mittel");
|
||||
|
||||
} else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||
rightPlayerTextField.setText("Schwer");
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
|
@ -40,14 +39,12 @@ public class startMultiplayerGame extends JPanel {
|
|||
// Textfelder
|
||||
JTextField PlayerTextField = new JTextField(20);
|
||||
|
||||
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
|
||||
|
||||
/**
|
||||
* Konstruktor der startLocalGame.
|
||||
* Fügt Buttons, Textfelder und Label hinzu.
|
||||
* Fügt ebenfalls ActionListeners hinzu, damit Buttons etc. ihre gewünschte Funktion haben
|
||||
* @param frame Der Mainframe der Anwendung über den alle Panels angezeigt werden.
|
||||
* @author Joshua Kuklok, Lucas Bronson
|
||||
* @author Joshua Kuklok
|
||||
*/
|
||||
startMultiplayerGame(MainFrame frame) {
|
||||
|
||||
|
@ -55,8 +52,7 @@ public class startMultiplayerGame extends JPanel {
|
|||
setLayout(null);
|
||||
|
||||
// Setze Komponentenpositionen
|
||||
frameTitle.setBounds(20, 20, 500, 60);
|
||||
frameTitle.setFont(robotoFont.deriveFont(50f));
|
||||
frameTitle.setBounds(20, 20, 200, 30);
|
||||
add(frameTitle);
|
||||
|
||||
semesterLabel.setBounds(700, 300, 200, 30);
|
||||
|
@ -68,7 +64,7 @@ public class startMultiplayerGame extends JPanel {
|
|||
PlayerIcon.setBounds(75, 400, 200, 128);
|
||||
add(PlayerIcon);
|
||||
|
||||
semesterCounterLabel.setBounds(705, 475, 50, 50); // zwischen den Up/Down-Buttons
|
||||
semesterCounterLabel.setBounds(725, 475, 50, 50); // zwischen den Up/Down-Buttons
|
||||
semesterCounterLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
add(semesterCounterLabel);
|
||||
|
||||
|
@ -81,10 +77,10 @@ public class startMultiplayerGame extends JPanel {
|
|||
PlayerRightButton.setBounds(250, 450, 50, 50);
|
||||
add(PlayerRightButton);
|
||||
|
||||
semesterUpButton.setBounds(705, 400, 50, 50);
|
||||
semesterUpButton.setBounds(725, 400, 50, 50);
|
||||
add(semesterUpButton);
|
||||
|
||||
semesterDownButton.setBounds(705, 550, 50, 50);
|
||||
semesterDownButton.setBounds(725, 550, 50, 50);
|
||||
add(semesterDownButton);
|
||||
|
||||
joinGameButton.setBounds(1100, 350, 200, 50);
|
||||
|
@ -154,13 +150,13 @@ public class startMultiplayerGame extends JPanel {
|
|||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (PlayerIcon.getIcon() == humanPlayerIcon) {
|
||||
frame.showPanelSMG("JoinGame",1,0, PlayerNickname, semesterCounter);
|
||||
frame.showPanelSMG("JoinGame",1,0, PlayerNickname);
|
||||
} else if ( PlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||
frame.showPanelSMG("JoinGame",1,1, PlayerNickname, semesterCounter);
|
||||
frame.showPanelSMG("JoinGame",1,1, PlayerNickname);
|
||||
} else if ( PlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||
frame.showPanelSMG("JoinGame",1,2, PlayerNickname, semesterCounter);
|
||||
frame.showPanelSMG("JoinGame",1,2, PlayerNickname);
|
||||
} else if ( PlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||
frame.showPanelSMG("JoinGame",1,3, PlayerNickname, semesterCounter);
|
||||
frame.showPanelSMG("JoinGame",1,3, PlayerNickname);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -171,13 +167,13 @@ public class startMultiplayerGame extends JPanel {
|
|||
public void actionPerformed(ActionEvent e) {
|
||||
//Parameter -> panelName, Spiel erstellen oder beitreten (int), Spielertyp(int 0-3), Spielername
|
||||
if (PlayerIcon.getIcon() == humanPlayerIcon) {
|
||||
frame.showPanelSMG("JoinGame",0,0, PlayerNickname, semesterCounter);
|
||||
frame.showPanelSMG("JoinGame",0,0, PlayerNickname);
|
||||
} else if ( PlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||
frame.showPanelSMG("JoinGame",0,1, PlayerNickname, semesterCounter);
|
||||
frame.showPanelSMG("JoinGame",0,1, PlayerNickname);
|
||||
} else if ( PlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||
frame.showPanelSMG("JoinGame",0,2, PlayerNickname, semesterCounter);
|
||||
frame.showPanelSMG("JoinGame",0,2, PlayerNickname);
|
||||
} else if ( PlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||
frame.showPanelSMG("JoinGame",0,3, PlayerNickname, semesterCounter);
|
||||
frame.showPanelSMG("JoinGame",0,3, PlayerNickname);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -192,13 +188,10 @@ public class startMultiplayerGame extends JPanel {
|
|||
private void togglePlayerIconLeft() {
|
||||
if (PlayerIcon.getIcon() == humanPlayerIcon) {
|
||||
PlayerIcon.setIcon(aiPlayerHardIcon);
|
||||
|
||||
} else if (PlayerIcon.getIcon() == aiPlayerEasyIcon){
|
||||
PlayerIcon.setIcon(humanPlayerIcon);
|
||||
|
||||
} else if (PlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||
PlayerIcon.setIcon(aiPlayerEasyIcon);
|
||||
|
||||
} else if (PlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||
PlayerIcon.setIcon(aiPlayerNormalIcon);
|
||||
}
|
||||
|
@ -211,13 +204,10 @@ public class startMultiplayerGame extends JPanel {
|
|||
private void togglePlayerIconRight() {
|
||||
if (PlayerIcon.getIcon() == humanPlayerIcon) {
|
||||
PlayerIcon.setIcon(aiPlayerEasyIcon);
|
||||
|
||||
} else if (PlayerIcon.getIcon() == aiPlayerEasyIcon){
|
||||
PlayerIcon.setIcon(aiPlayerNormalIcon);
|
||||
|
||||
} else if (PlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||
PlayerIcon.setIcon(aiPlayerHardIcon);
|
||||
|
||||
} else if (PlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||
PlayerIcon.setIcon(humanPlayerIcon);
|
||||
}
|
||||
|
@ -230,13 +220,10 @@ public class startMultiplayerGame extends JPanel {
|
|||
private void updateTextFields() {
|
||||
if (PlayerIcon.getIcon() == humanPlayerIcon) {
|
||||
PlayerTextField.setText(PlayerNickname);
|
||||
|
||||
} else if (PlayerIcon.getIcon() == aiPlayerEasyIcon){
|
||||
PlayerTextField.setText("Einfach");
|
||||
|
||||
} else if (PlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||
PlayerTextField.setText("Mittel");
|
||||
|
||||
} else if (PlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||
PlayerTextField.setText("Schwer");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue