Compare commits

..

35 Commits

Author SHA1 Message Date
Luca Conte 3c7d68109a Merge pull request 'fix ready' (#31) from game-end-stuff into main
Reviewed-on: #31
2024-12-23 22:22:00 +00:00
Luca Conte eaa5b64956 fix ready 2024-12-23 23:21:48 +01:00
Luca Conte 5b3ecb52bb Merge pull request 'add rotate instruction' (#30) from game-end-stuff into main
Reviewed-on: #30
2024-12-23 22:15:19 +00:00
Luca Conte 9ea176cc6d add rotate instruction 2024-12-23 23:15:04 +01:00
Luca Conte 7a706e1b73 Merge pull request 'game-end-stuff' (#29) from game-end-stuff into main
Reviewed-on: #29
2024-12-23 22:13:57 +00:00
Luca Conte 175241395e add docs to makefile 2024-12-23 23:13:11 +01:00
Luca Conte 1b08b39105 don't repaint fields after game end 2024-12-23 23:12:43 +01:00
Luca Conte 8dd697bb66 proper game closing 2024-12-23 23:04:16 +01:00
Luca Conte 30360c7bd4 Merge pull request 'kommentar-check' (#28) from kommentar-check into main
Reviewed-on: #28
2024-12-23 20:37:06 +00:00
Luca Conte 6f98a82a90 KOOMMMEEENTTAAAREEEEEEEE 2024-12-23 21:36:19 +01:00
Luca Conte a4cb3f68d5 Merge branch 'FH_Last_changes' into kommentar-check 2024-12-23 20:51:53 +01:00
Luca Conte 27157fb0a3 Merge pull request 'Add komentare' (#27) from ole into main
Reviewed-on: #27
2024-12-23 19:49:01 +00:00
Luca Conte 0fef0069f8 wtf 2024-12-23 20:48:51 +01:00
Luca Conte 5839b13980 Merge branch 'main' into ole 2024-12-23 20:47:40 +01:00
Luca Conte 0f42a66e4a Merge pull request 'lucasjoshua' (#26) from lucasjoshua into main
Reviewed-on: #26
2024-12-23 19:46:03 +00:00
Luca Conte c14f7d5bfe Merge branch 'main' into lucasjoshua 2024-12-23 20:44:31 +01:00
Luca Conte f13e0ab2ba Merge pull request 'Kommentare und Withdraw' (#24) from FH_Last_changes into main
Reviewed-on: #24
2024-12-23 19:39:53 +00:00
Luca Conte e85f151b33 a bit cleaner withdraw 2024-12-23 20:28:06 +01:00
Luca Conte 7fb19bfeac Merge branch 'main' into FH_Last_changes 2024-12-23 20:17:51 +01:00
Luca Conte 9ed0dc1e9e Merge pull request 'wip-fix-ai-players' (#25) from wip-fix-ai-players into main
Reviewed-on: #25
2024-12-23 19:14:59 +00:00
Luca Conte 9d51e708e5 remove game board on win or lose 2024-12-23 20:13:52 +01:00
Luca Conte 44f04a454f proper thread killing and online player myTurn handling 2024-12-23 20:02:11 +01:00
Joshua 678ed9d81e Got rid of some todos 2024-12-23 19:28:02 +01:00
Luca Conte be6b50739f Merge branch 'lucasjoshua' into wip-fix-ai-players 2024-12-23 19:05:24 +01:00
Joshua 458aa46638 Merge remote-tracking branch 'origin/lucasjoshua' into lucasjoshua 2024-12-23 18:51:02 +01:00
Joshua be46f3587e Fixed semesterCounter for onlineGame. 2024-12-23 18:50:39 +01:00
Kaver 9c6d629357 fix Board halb 2024-12-23 18:41:10 +01:00
ole 70749c2c62 add Komentare 2024-12-23 18:36:15 +01:00
Joshua 3ad7233383 JoinGame now calls GameController.startOnlineGame(...) correctly. 2024-12-23 18:35:22 +01:00
Joshua 529178f4db Updated backButton.png. 2024-12-23 18:08:40 +01:00
Kaver 0cea473146 smol jdoc changes 2024-12-22 23:17:52 +01:00
Kaver 1e58626e6f jdoc 2024-12-22 00:02:03 +01:00
Joshua 8933a40d53 Changed the color of ships to white, as to make AI ships invisible. 2024-12-21 16:54:08 +01:00
Joshua cb9b110621 Added and integrated new sounds.
Added standardPort to be default value of port field.
2024-12-21 16:26:10 +01:00
Kaver 4dd1c9b39b Code aufräumen und kleine Anpassungen/Korrekturen vorgenommen 2024-12-20 19:39:56 +01:00
37 changed files with 478 additions and 259 deletions

Binary file not shown.

BIN
Sound/loosescreenlaugh.mp3 Normal file

Binary file not shown.

BIN
Sound/win.mp3 Normal file

Binary file not shown.

BIN
Sound/yourturn.mp3 Normal file

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 396 B

View File

@ -29,6 +29,9 @@ test-jar: jar
# $(JR) -cp "$(OUT_DIR)/:$(LIB_DIR)/*" $(MAIN_CLASS) # $(JR) -cp "$(OUT_DIR)/:$(LIB_DIR)/*" $(MAIN_CLASS)
$(JR) -jar $(OUT_DIR)/$(JAR_NAME) $(JR) -jar $(OUT_DIR)/$(JAR_NAME)
docs:
javadoc -cp "$(LIB_DIR)/*" -d "docs" $(SRC_DIR)/*.java
test: classfiles test: classfiles
$(JR) -cp "$(OUT_DIR)$(SEPERATOR)$(LIB_DIR)/*" $(MAIN_CLASS) $(JR) -cp "$(OUT_DIR)$(SEPERATOR)$(LIB_DIR)/*" $(MAIN_CLASS)

View File

@ -1,14 +1,12 @@
/**
* Die Klasse AiPlayer ist die Basis für alle Ki Spieler und jede Spezifische Ki erweitert diese Klasse.
* @author Florian Alexy und Florian Hantzschel
* */
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Random; 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 { public abstract class AiPlayer extends LocalPlayer implements Runnable {
/** /**
@ -18,6 +16,7 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable {
/** /**
* Konstruktor * Konstruktor
* @author Florian Alexy und Florian Hantzschel
*/ */
public AiPlayer() { public AiPlayer() {
this.setName("AI Player"); this.setName("AI Player");
@ -73,7 +72,7 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable {
* Nachdem receiveShoot beim gegner den schuss verarbeitet hat, * Nachdem receiveShoot beim gegner den schuss verarbeitet hat,
* wird diese Methode mit der antwort aufgerufen. * wird diese Methode mit der antwort aufgerufen.
* @param hitResponse the hitresponse * @param hitResponse the hitresponse
* @author Florian Alexy und Florian Hantzschel * @author Florian Alexy und Florian Hantzschel und Luca Conte
*/ */
@Override @Override
public synchronized void receiveHit(HitResponse hitResponse) { public synchronized void receiveHit(HitResponse hitResponse) {
@ -91,7 +90,7 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable {
/** /**
* Erhält einen schuss vom gegner und verarbeitet ihn. * Erhält einen schuss vom gegner und verarbeitet ihn.
* @param point the location to be shot * @param point the location to be shot
* @author Florian Alexy und Florian Hantzschel * @author Florian Alexy und Florian Hantzschel und Luca Conte
*/ */
@Override @Override
public synchronized void receiveShoot(Point point) { public synchronized void receiveShoot(Point point) {
@ -106,7 +105,7 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable {
/** /**
* Wird aufgerufen, wenn in determineCoinToss festgestellt wurde das die Ki anfängt. * Wird aufgerufen, wenn in determineCoinToss festgestellt wurde das die Ki anfängt.
* Erster Schuss wird gestartet. * Erster Schuss wird gestartet.
* @author Florian Alexy und Florian Hantzschel * @author Florian Alexy und Florian Hantzschel und Luca Conte
*/ */
@Override @Override
public void beginTurn() { public void beginTurn() {
@ -156,6 +155,7 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable {
while(i.hasNext()) { while(i.hasNext()) {
Thread thread = i.next(); Thread thread = i.next();
try { try {
thread.interrupt();
thread.join(); thread.join();
i.remove(); i.remove();
} catch (InterruptedException e) { } catch (InterruptedException e) {

View File

@ -9,7 +9,7 @@ import java.net.Socket;
/** /**
* Provides an Interface to communicate using a socket asynchronously * Provides an Interface to communicate using a socket asynchronously
* @author Luca Conte * @author Luca Conte, Peer Ole Wachtel
*/ */
public class AsyncSocket { public class AsyncSocket {
private Socket socket; private Socket socket;
@ -225,7 +225,10 @@ public class AsyncSocket {
try { try {
this.socket.close(); this.socket.close();
if (this.checkerThread != null) this.checkerThread.join(); if (this.checkerThread != null) {
this.checkerThread.interrupt();
this.checkerThread.join();
}
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} catch (InterruptedException e) { } catch (InterruptedException e) {

View File

@ -1,4 +1,5 @@
/** /**
* defines a message listener for AsyncSockets
* @author Luca Conte * @author Luca Conte
*/ */
public interface AsyncSocketListener { public interface AsyncSocketListener {

View File

@ -1,20 +1,35 @@
/**
* Die Board-Klasse repräsentiert das Spielfeld.
* @author Peer Ole Wachtel, Florian Alexy und Florian Hantzschel
*/
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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 { public class Board {
/**
* Alle bisher empfangenen HitResponsen
*/
private List<HitResponse> hits; private List<HitResponse> hits;
private List<Ship> ships;
private final int size;
/** /**
* Initialisiert das Board und die zu Setzenden schiffe. * Alle Schiffe des Semesters
* @param size */
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 * @author Peer Ole Wachtel, Florian Alexy und Florian Hantzschel
*/ */
public Board(int size) { public Board(int size) {
@ -24,6 +39,12 @@ public class Board {
this.createShip(size - 13); 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){ public synchronized HitResponse hit (Point point){
HitResponse response = new HitResponse(HitResponseType.MISS,point); HitResponse response = new HitResponse(HitResponseType.MISS,point);
for (int i = 0; i < this.ships.size(); i++) { for (int i = 0; i < this.ships.size(); i++) {
@ -75,14 +96,16 @@ public class Board {
* @author Peer Ole Wachtel * @author Peer Ole Wachtel
*/ */
private void createShip(int semester){ 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++) { for (int i = 0; i < shipData.size(); i++) {
this.ships.add(new Ship(shipData.get(i).size(), shipData.get(i).name())); 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 * @return a list of all the Ships on the board
* @author Peer Ole Wachtel
*/ */
public List<Ship> getShips() { public List<Ship> getShips() {
return ships; return ships;
@ -95,7 +118,7 @@ public class Board {
* to all adjacened hit responses with type HIT using `propagateSunk`. * to all adjacened hit responses with type HIT using `propagateSunk`.
* @param hitResponse the HitResponse to be added * @param hitResponse the HitResponse to be added
* @return true when the hit response was added, otherwise false * @return true when the hit response was added, otherwise false
* * @author Peer Ole Wachtel, Luca Conte
*/ */
public synchronized boolean addHits(HitResponse hitResponse) { public synchronized boolean addHits(HitResponse hitResponse) {
if (this.getHitResponseOnPoint(hitResponse.getPoint()) == null){ if (this.getHitResponseOnPoint(hitResponse.getPoint()) == null){
@ -115,6 +138,7 @@ public class Board {
/** /**
* @param point the position to get the hit response from * @param point the position to get the hit response from
* @return the hit response at the position `point` * @return the hit response at the position `point`
* @author Peer Ole Wachtel
*/ */
public synchronized HitResponse getHitResponseOnPoint(Point point) { public synchronized HitResponse getHitResponseOnPoint(Point point) {
for (int i = 0; i < this.hits.size(); i++){ for (int i = 0; i < this.hits.size(); i++){
@ -126,7 +150,9 @@ public class Board {
} }
/** /**
* returns the size of the board
* @return the size of the board * @return the size of the board
* @author Florian Alexy, Florian Hantzschel
*/ */
public int getSize() { public int getSize() {
return this.size; return this.size;

View File

@ -21,7 +21,7 @@ public class BoardDisplay extends JPanel {
/** /**
* Fügt Buttons zu Liste hinzu und aktualisiert Feld durch Aufruf von paintFields * Fügt Buttons zu Liste hinzu und aktualisiert Feld durch Aufruf von paintFields
* @param button * @param button Jeweiliger Button der hinzugefügt werden soll
* @author Joshua Kuklok * @author Joshua Kuklok
*/ */
public void addShipButton(ShipButton button) { public void addShipButton(ShipButton button) {
@ -31,15 +31,15 @@ public class BoardDisplay extends JPanel {
/** /**
* Gibt currentShip zurück * Gibt currentShip zurück
* @return currentShip * @return currentShip Objekt der Klasse Schiff
* @author Lucas Bronson, Luca Conte, Joshua Kuklok * @author Lucas Bronson Luca Conte
*/ */
public Ship getCurrentShip() { public Ship getCurrentShip() {
return currentShip; return currentShip;
} }
/** /**
* Konstruktor der startLocalGame. * Konstruktor des Board Displays
* @param gridSize Die Größe des Spielfelds * @param gridSize Die Größe des Spielfelds
* @param player Der Spieler * @param player Der Spieler
* @author Lucas Bronson * @author Lucas Bronson
@ -55,8 +55,8 @@ public class BoardDisplay extends JPanel {
// Erstellung vom Spielfeld // Erstellung vom Spielfeld
for (int i = 0; i <= gridSize; i++) { for (int i = 0; i <= gridSize; i++) {
for (int j = 0; j <= gridSize; j++) { for (int j = 0; j <= gridSize; j++) {
final int x = j - 1; // Temporäre Variable final int x = j - 1; // Temporäre Variable für überspringen von Rahmenzeile-/spalte
final int y = i - 1; // Temporäre Variable final int y = i - 1; // Temporäre Variable für überspringen von Rahmenzeile-/spalte
if (i == 0 && j == 0) { if (i == 0 && j == 0) {
add(new JLabel(" ")); add(new JLabel(" "));
} else if (i == 0) { } else if (i == 0) {
@ -67,7 +67,7 @@ public class BoardDisplay extends JPanel {
} else if (j == 0) { } else if (j == 0) {
JLabel rowLabel = new JLabel(String.valueOf((char) ('A' + i - 1))); JLabel rowLabel = new JLabel(String.valueOf((char) ('A' + i - 1)));
rowLabel.setHorizontalAlignment(SwingConstants.CENTER); rowLabel.setHorizontalAlignment(SwingConstants.CENTER);
rowLabel.setFont(new Font("Arial", Font.BOLD, 14)); rowLabel.setFont(new Font("Roboto", Font.BOLD, 14));
add(rowLabel); add(rowLabel);
} else { } else {
// Spielfeld (interaktive Zellen) // Spielfeld (interaktive Zellen)
@ -174,6 +174,7 @@ public class BoardDisplay extends JPanel {
if(currentShip != null) { if(currentShip != null) {
test = currentShip.getVirtualOccupiedPoints(mousePosition, horizontal); test = currentShip.getVirtualOccupiedPoints(mousePosition, horizontal);
} }
if (player == null || player.getBoard() == null) return;
for(int i = 0; i < gridSize; i++) { for(int i = 0; i < gridSize; i++) {
for(int j = 0; j < gridSize; j++) { for(int j = 0; j < gridSize; j++) {
if(fields[i][j] == null) { if(fields[i][j] == null) {
@ -211,7 +212,7 @@ public class BoardDisplay extends JPanel {
} }
for(Ship ship: player.getBoard().getShips()) { for(Ship ship: player.getBoard().getShips()) {
if(ship.isShipOnPos(new Point(i,j))) { if(ship.isShipOnPos(new Point(i,j))) {
fields[i][j].setBackground(Color.LIGHT_GRAY); fields[i][j].setBackground(Color.WHITE);
} }
} }
HitResponse hit = this.player.getBoard().getHitResponseOnPoint(new Point(i, j)); HitResponse hit = this.player.getBoard().getHitResponseOnPoint(new Point(i, j));

View File

@ -23,7 +23,7 @@ public class GameBoard extends JPanel {
ImageIcon gameBoardX = new ImageIcon("graphics/gameboardx.png"); ImageIcon gameBoardX = new ImageIcon("graphics/gameboardx.png");
// kontextText Text-Strings // kontextText Text-Strings
String kT1 = "Bitte Schiffe setzten"; String kT1 = "Bitte Schiffe setzten - Rechtsclick zum drehen";
String kT2 = "Warte auf Gegner"; String kT2 = "Warte auf Gegner";
String kT3 = "Du fängst an"; String kT3 = "Du fängst an";
String kT4 = "Dein Gegner fängt an"; String kT4 = "Dein Gegner fängt an";
@ -40,6 +40,7 @@ public class GameBoard extends JPanel {
// Buttons // Buttons
JButton giveUpButton = new JButton("Aufgeben"); JButton giveUpButton = new JButton("Aufgeben");
/** /**
* Konstruktor von GameBoard. * Konstruktor von GameBoard.
* @param frame Der Mainframe der Anwendung über den alle Panels angezeigt werden. * @param frame Der Mainframe der Anwendung über den alle Panels angezeigt werden.
@ -55,12 +56,9 @@ public class GameBoard extends JPanel {
List<Ship> shipsP1 =p1.getBoard().getShips(); List<Ship> shipsP1 =p1.getBoard().getShips();
List<Ship> shipsP2 =p2.getBoard().getShips(); List<Ship> shipsP2 =p2.getBoard().getShips();
giveUpButton.addActionListener(new ActionListener() { giveUpButton.addActionListener((e) -> {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Hier könnte Ihr Backend Code stehen
frame.showPanel("MainMenu"); frame.showPanel("MainMenu");
} p1.withdraw();
}); });
} }
@ -108,7 +106,7 @@ public class GameBoard extends JPanel {
JPanel headerPanel = new JPanel(); JPanel headerPanel = new JPanel();
headerPanel.setLayout(new BorderLayout()); headerPanel.setLayout(new BorderLayout());
headerPanel.add(kontextText, BorderLayout.WEST); headerPanel.add(kontextText, BorderLayout.WEST);
kontextText.setFont(new Font("Roboto", Font.BOLD, 30)); //TODO setFont fixen kontextText.setFont(new Font("Roboto", Font.BOLD, 30));
headerPanel.add(giveUpButton, BorderLayout.EAST); headerPanel.add(giveUpButton, BorderLayout.EAST);
JPanel leftButtonsPanel = new JPanel(); JPanel leftButtonsPanel = new JPanel();
@ -136,7 +134,6 @@ public class GameBoard extends JPanel {
opponentBoardPanel.addShipButton(shipButton); opponentBoardPanel.addShipButton(shipButton);
shipButton.setEnabled(false); shipButton.setEnabled(false);
} }
JToggleButton readyButton = new JToggleButton("Bereit"); JToggleButton readyButton = new JToggleButton("Bereit");
readyButton.setBackground(Color.GREEN); readyButton.setBackground(Color.GREEN);
rightButtonsPanel.add(readyButton); rightButtonsPanel.add(readyButton);
@ -151,14 +148,18 @@ public class GameBoard extends JPanel {
ownBoardPanel.resetAllShips(); 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 // Um Bereit-Meldung and Backend zu geben, kontextText zu setzten und ready/reset Button zu deaktivieren
readyButton.addActionListener(new ActionListener() { readyButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
kontextText.setText(kT2); kontextText.setText(kT2);
p1.ready(); p1.ready();
if(true) { if(p1.isReady()) {
remove(readyButton);
remove(resetButton);
remove(rightButtonsPanel);
remove(leftButtonsPanel);
readyButton.setEnabled(false); readyButton.setEnabled(false);
resetButton.setEnabled(false); resetButton.setEnabled(false);
} }
@ -201,11 +202,14 @@ public class GameBoard extends JPanel {
/** /**
* Aktualisiert Zustand(kontextText) je nach Zug * Aktualisiert Zustand(kontextText) je nach Zug
* @author Luca Conte * @author Luca Conte, Joshua Kuklok
*/ */
public void refresh() { public void refresh() {
if (this.p1.myTurn) { if (this.p1.myTurn) {
if (!kontextText.getText().equals(kT5)) {
this.kontextText.setText(kT5); this.kontextText.setText(kT5);
SoundHandler.playSound("yourturn");
}
} else { } else {
this.kontextText.setText(kT6); this.kontextText.setText(kT6);
} }
@ -221,6 +225,11 @@ public class GameBoard extends JPanel {
public Player getP1() { public Player getP1() {
return p1; return p1;
} }
/**
* Getter für Player2
* @return Player 2
* @author Luca Conte
*/
public Player getP2() { public Player getP2() {
return p2; return p2;
} }

View File

@ -14,6 +14,7 @@ public class GameController {
private static MainFrame mainFrame; private static MainFrame mainFrame;
/** /**
* returns the current MainFrame
* @return the current MainFrame * @return the current MainFrame
* @author Luca Conte * @author Luca Conte
*/ */
@ -21,6 +22,7 @@ public class GameController {
return GameController.mainFrame; return GameController.mainFrame;
} }
/** /**
* sets the current MainFrame
* @param mainFrame the current MainFrame * @param mainFrame the current MainFrame
* @author Luca Conte * @author Luca Conte
*/ */
@ -124,7 +126,7 @@ public class GameController {
/** /**
* finds the largest common version in two lists of version strings * finds the largest common version in two lists of version strings
* @return null if no common versions are found * @return null if no common versions are found otherwise returns the most recent version present in both lists
* @author Luca Conte * @author Luca Conte
*/ */
public static String findMostRecentVersion(List<String> versions1, List<String> versions2) { public static String findMostRecentVersion(List<String> versions1, List<String> versions2) {

View File

@ -1,6 +1,6 @@
/** /**
* Hauptklasse über die der MainFrame gestartet wird * Hauptklasse über die der MainFrame gestartet wird
* @author Lucas Bronson, Ole Wachtel, Joshua Kuklok * @author Lucas Bronson, Peer Ole Wachtel, Joshua Kuklok
*/ */
public class HalloSchiffeVersenken { public class HalloSchiffeVersenken {
@ -8,19 +8,10 @@ public class HalloSchiffeVersenken {
* Erstellt und setzt den Mainframe * Erstellt und setzt den Mainframe
* @param args Argumente an Main durch Konsole etc. * @param args Argumente an Main durch Konsole etc.
* @throws InterruptedException * @throws InterruptedException
* @author Peer Ole Wachtel
*/ */
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {
MainFrame mf = new MainFrame(); MainFrame mf = new MainFrame();
mf.setVisible(true); 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)
*/

View File

@ -1,14 +1,38 @@
/**
* 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 { public class HitResponse {
/**
* Speichert den typ der HitResponse.
*/
private HitResponseType type; private HitResponseType type;
/**
* Speicher den Punkt wofür die HitResponse gilt.
*/
private Point point; 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) { public HitResponse(HitResponseType type, Point point) {
this.type = type; this.type = type;
this.point = point; 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) { public HitResponse (int typeIndex, Point point) {
if (typeIndex >= 0 && typeIndex < HitResponseType.values().length) { if (typeIndex >= 0 && typeIndex < HitResponseType.values().length) {
this.type = HitResponseType.values()[typeIndex]; this.type = HitResponseType.values()[typeIndex];
@ -18,24 +42,48 @@ public class HitResponse {
} }
} }
/**
* returns the type of the HitResponse
* @return the type of the HitResponse
* @author Florian Hantzschel
*/
public HitResponseType getHitResponse() { public HitResponseType getHitResponse() {
return this.type; return this.type;
} }
/**
* returns the point of the HitResponse
* @return the point of the HitResponse
* @author Florian Hantzschel
*/
public Point getPoint() { public Point getPoint() {
return this.point; return this.point;
} }
public HitResponse setType(HitResponseType type) { /**
* 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; this.type = type;
return null;
} }
/**
* 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 @Override
public String toString() { public String toString() {
return this.getPoint().toString() + " " + this.type.ordinal(); 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() { public HitResponseType getType() {
return type; return type;
} }

View File

@ -1,3 +1,7 @@
/**
* Stellt die verschiedenen möglichkeiten einer HitResponse als typ dar.
* @author Peer Ole Wachtel
*/
public enum HitResponseType { public enum HitResponseType {
MISS, HIT, SUNK, VICTORY MISS, HIT, SUNK, VICTORY
} }

View File

@ -1,4 +1,8 @@
/**
* Repräsentiert einen menschlichen Spieler
* @author Luca Conte, Florian Hantzschel
*/
public class HumanPlayer extends LocalPlayer { public class HumanPlayer extends LocalPlayer {
/** /**
* shoots a shot onto the provided point on the enemy board * shoots a shot onto the provided point on the enemy board
@ -9,7 +13,6 @@ public class HumanPlayer extends LocalPlayer {
@Override @Override
public void shoot(Point point) { public void shoot(Point point) {
if (!this.myTurn) return; if (!this.myTurn) return;
this.myTurn = false;
enemy.receiveShoot(point); enemy.receiveShoot(point);
} }
} }

View File

@ -12,6 +12,9 @@ import java.net.InetSocketAddress;
*/ */
public class JoinGame extends JPanel { public class JoinGame extends JPanel {
// Funktionshilfen
String standardPort = "51525";
// Grafiken // Grafiken
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png"); ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
@ -39,9 +42,9 @@ public class JoinGame extends JPanel {
* @param playerName Name des Spielers * @param playerName Name des Spielers
* @author Lucas Bronson, Joshua Kuklok * @author Lucas Bronson, Joshua Kuklok
*/ */
public JoinGame(MainFrame frame,int g,int playerType,String playerName) { public JoinGame(MainFrame frame,int g,int playerType,String playerName, int semesterCounter) {
setLayout(null); setLayout(null);
buildPanel(frame,g,playerType,playerName); buildPanel(frame,g,playerType,playerName, semesterCounter);
} }
/** /**
@ -52,7 +55,8 @@ public class JoinGame extends JPanel {
* @param playerName Name des Spielers * @param playerName Name des Spielers
* @author Lucas Bronson, Joshua Kuklok * @author Lucas Bronson, Joshua Kuklok
*/ */
private void buildPanel(MainFrame frame,int g,int playerType,String playerName) { private void buildPanel(MainFrame frame,int g,int playerType,String playerName, int semesterCounter) {
System.out.println("semesterzahl in JoinGame" + semesterCounter);
if(g==1){ if(g==1){
spielBeitretenLabel= new JLabel("Spiel beitreten"); spielBeitretenLabel= new JLabel("Spiel beitreten");
}else{ }else{
@ -71,6 +75,7 @@ public class JoinGame extends JPanel {
} }
portTextField.setBounds(50, 225, 250, 50); portTextField.setBounds(50, 225, 250, 50);
portTextField.setText(standardPort);
spielBeitretenLabel.setFont(robotoFont.deriveFont(50f)); spielBeitretenLabel.setFont(robotoFont.deriveFont(50f));
@ -100,6 +105,7 @@ public class JoinGame extends JPanel {
if (ipAddress.isEmpty()) { if (ipAddress.isEmpty()) {
ipAddress = "0.0.0.0"; ipAddress = "0.0.0.0";
} }
System.out.println(portTextField.getText());
String portText = portTextField.getText(); String portText = portTextField.getText();
int port = Integer.parseInt(portText); int port = Integer.parseInt(portText);
@ -109,13 +115,13 @@ public class JoinGame extends JPanel {
try { try {
if(playerType == 0) { if(playerType == 0) {
GameController.startOnlineGame(HumanPlayer.class, playerName, address,GameController.semesterToBoardSize(2)); GameController.startOnlineGame(HumanPlayer.class, playerName, address,GameController.semesterToBoardSize(semesterCounter));
} else if(playerType == 1) { } else if(playerType == 1) {
GameController.startOnlineGame(SpecificAiPlayerEasy.class, playerName, address,GameController.semesterToBoardSize(2)); GameController.startOnlineGame(SpecificAiPlayerEasy.class, playerName, address,GameController.semesterToBoardSize(semesterCounter));
} else if (playerType == 2) { } else if (playerType == 2) {
GameController.startOnlineGame(SpecificAiPlayerMedium.class, playerName, address,GameController.semesterToBoardSize(2)); GameController.startOnlineGame(SpecificAiPlayerMedium.class, playerName, address,GameController.semesterToBoardSize(semesterCounter));
} else if (playerType == 3) { } else if (playerType == 3) {
GameController.startOnlineGame(SpecificAiPlayerHard.class, playerName, address,GameController.semesterToBoardSize(2)); GameController.startOnlineGame(SpecificAiPlayerHard.class, playerName, address,GameController.semesterToBoardSize(semesterCounter));
} }
} catch (IOException ex) { } catch (IOException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);

View File

@ -1,7 +1,17 @@
import java.util.Random; 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 { public class LocalPlayer extends Player {
/**
* erstellt einen LocalPlayer und setzt myCoin random
* @author Peer Ole Wachtel
*/
public LocalPlayer(){ public LocalPlayer(){
super(); super();
Random random = new Random(); Random random = new Random();
@ -15,7 +25,11 @@ public class LocalPlayer extends Player {
*/ */
@Override @Override
public synchronized void receiveShoot(Point point) { public synchronized void receiveShoot(Point point) {
if (!this.enemy.myTurn) return; 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); HitResponse hitResponse = board.getHitResponseOnPoint(point);
if (!(hitResponse == null)){ if (!(hitResponse == null)){
@ -29,7 +43,7 @@ public class LocalPlayer extends Player {
switch (hitResponse.getType()) { switch (hitResponse.getType()) {
case HIT, SUNK -> this.myTurn = false; case HIT, SUNK -> this.myTurn = false;
case MISS -> this.myTurn = true; case MISS -> this.myTurn = true;
case VICTORY -> GameController.getMainFrame().showPanelLoose("", this); //TODO Was halt bei victory passiert ist hier wurder verloheren case VICTORY -> this.lose();
} }
GameController.getMainFrame().refreshGameBoard(); GameController.getMainFrame().refreshGameBoard();
} }
@ -45,7 +59,7 @@ public class LocalPlayer extends Player {
switch (hitResponse.getType()) { switch (hitResponse.getType()) {
case HIT, SUNK -> this.myTurn = true; case HIT, SUNK -> this.myTurn = true;
case MISS -> this.myTurn = false; case MISS -> this.myTurn = false;
case VICTORY -> GameController.getMainFrame().showPanelWin("", this); // TODO was halt beim victory passier ist hier wurde gewonnen case VICTORY -> this.win();
} }
GameController.getMainFrame().refreshGameBoard(); GameController.getMainFrame().refreshGameBoard();
} }
@ -68,6 +82,7 @@ public class LocalPlayer extends Player {
/** /**
* sends shot to enemy player. * sends shot to enemy player.
* should ONLY be called on HumanPlayer * should ONLY be called on HumanPlayer
* @author Luca Conte
*/ */
@Override @Override
public void shoot(Point point){ public void shoot(Point point){

View File

@ -1,34 +0,0 @@
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);
}
}

48
src/LoseScreen.java Normal file
View File

@ -0,0 +1,48 @@
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);
}
}

View File

@ -45,14 +45,12 @@ public class MainFrame extends JFrame {
MainMenuView mainMenuView = new MainMenuView(this); MainMenuView mainMenuView = new MainMenuView(this);
startLocalGame localGame = new startLocalGame(this); startLocalGame localGame = new startLocalGame(this);
startMultiplayerGame multiplayerGame = new startMultiplayerGame(this); startMultiplayerGame multiplayerGame = new startMultiplayerGame(this);
coinToss coinToss = new coinToss(this);
Verbinden verbinden = new Verbinden(this); Verbinden verbinden = new Verbinden(this);
// Panels hinzufügen // Panels hinzufügen
mainPanel.add(mainMenuView, "MainMenu"); mainPanel.add(mainMenuView, "MainMenu");
mainPanel.add(localGame, "LocalGame"); mainPanel.add(localGame, "LocalGame");
mainPanel.add(multiplayerGame, "MultiplayerGame"); mainPanel.add(multiplayerGame, "MultiplayerGame");
mainPanel.add(coinToss, "coinToss");
mainPanel.add(verbinden, "Verbinden"); mainPanel.add(verbinden, "Verbinden");
// mainPanel.add(winLooseScreen, "WinLooseScreen"); // mainPanel.add(winLooseScreen, "WinLooseScreen");
@ -80,10 +78,10 @@ public class MainFrame extends JFrame {
* @param playerName Name des Spielers * @param playerName Name des Spielers
* @author Lucas Bronson, Joshua Kuklok * @author Lucas Bronson, Joshua Kuklok
*/ */
public void showPanelSMG(String panelName, int num, int playerType,String playerName) { public void showPanelSMG(String panelName, int num, int playerType,String playerName, int semesterCounter) {
this.localMult = num; this.localMult = num;
JoinGame joinGame = new JoinGame(this, localMult, playerType, playerName); JoinGame joinGame = new JoinGame(this, localMult, playerType, playerName, semesterCounter);
mainPanel.add(joinGame, panelName); mainPanel.add(joinGame, panelName);
mainPanel.revalidate(); mainPanel.revalidate();
mainPanel.repaint(); mainPanel.repaint();
@ -128,12 +126,18 @@ public class MainFrame extends JFrame {
* Spezifische ShowPanel für WinScreen Klasse * Spezifische ShowPanel für WinScreen Klasse
* @param panelName Name des anzuzeigenden Panels * @param panelName Name des anzuzeigenden Panels
* @param player Player von dem die funktion aufgerufen worden ist * @param player Player von dem die funktion aufgerufen worden ist
* @author Lucas Bronson, Peer Ole Wachtel * @author Lucas Bronson, Peer Ole Wachtel, Luca Conte
*/ */
public void showPanelWin(String panelName, Player player){ public void showPanelWin(String panelName, Player player){
if(player != gameBoard.getP1()){ if(gameBoard == null || player != gameBoard.getP1()){
return; return;
} }
this.gameBoard.getP1().destroy();
this.gameBoard.getP2().destroy();
this.gameBoard.removeAll();
this.gameBoard = null;
WinScreen winScreen = new WinScreen(this); WinScreen winScreen = new WinScreen(this);
mainPanel.add(winScreen, panelName); mainPanel.add(winScreen, panelName);
mainPanel.revalidate(); mainPanel.revalidate();
@ -145,15 +149,19 @@ public class MainFrame extends JFrame {
* Spezifische ShowPanel für LooseScreen Klasse * Spezifische ShowPanel für LooseScreen Klasse
* @param panelName Name des anzuzeigenden Panels * @param panelName Name des anzuzeigenden Panels
* @param player Player von dem die funktion aufgerufen worden ist * @param player Player von dem die funktion aufgerufen worden ist
* @author Lucas Bronson, Peer Ole Wachtel * @author Lucas Bronson, Peer Ole Wachtel, Luca Conte
*/ */
public void showPanelLoose(String panelName, Player player){ public void showPanelLose(String panelName, Player player){
if(player != gameBoard.getP1()){ if(gameBoard == null || player != gameBoard.getP1()){
return; return;
} }
this.gameBoard.getP1().destroy(); this.gameBoard.getP1().destroy();
this.gameBoard.getP2().destroy(); this.gameBoard.getP2().destroy();
LooseScreen looseScreen = new LooseScreen(this); this.gameBoard.removeAll();
this.gameBoard = null;
LoseScreen looseScreen = new LoseScreen(this);
mainPanel.add(looseScreen,panelName); mainPanel.add(looseScreen,panelName);
mainPanel.revalidate(); mainPanel.revalidate();
mainPanel.repaint(); mainPanel.repaint();
@ -161,7 +169,7 @@ public class MainFrame extends JFrame {
} }
/** /**
* Aktualisiert das Spielfeld (kontextText) * Aktualisiert das Spielfeld
* @author Luca Conte * @author Luca Conte
*/ */
public void refreshGameBoard() { public void refreshGameBoard() {

View File

@ -1,3 +1,8 @@
/**
* 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 AsyncSocket socket;
protected int wantedBoardSize; protected int wantedBoardSize;
@ -9,25 +14,33 @@ public abstract class OnlinePlayer extends Player implements AsyncSocketListener
* @param size the size of the board the enemy player wants to play with * @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 * 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 * @param socket an AsyncSocket to communicate with the enemy through
* @author Peer Ole Wachtel, Luca Conte
*/ */
public OnlinePlayer(Integer size, AsyncSocket socket) { public OnlinePlayer(Integer size, AsyncSocket socket) {
this.socket = socket; this.socket = socket;
this.wantedBoardSize = size; this.wantedBoardSize = size;
this.myCoin = null; this.myCoin = null;
socket.setHandler(this); socket.setHandler(this);
//TODO Auto-generated constructor stub
} }
/**
* sends the IAM Package for introduction
* @author Luca Conte
*/
public abstract void sendIAM(); public abstract void sendIAM();
/**
* receives a message from the AsyncSocket
* satisfies AsyncSocketListener interface
* @author Luca Conte
*/
public abstract void receive(String message); public abstract void receive(String message);
@Override /**
public abstract void receiveShoot(Point point); * receives the coin toss result from the enemy
* @param coin the result of the coin toss
@Override * @author Peer Ole Wachtel
public abstract void receiveHit(HitResponse hitResponse); */
@Override @Override
public abstract void receiveCoin(boolean coin); public abstract void receiveCoin(boolean coin);

View File

@ -1,6 +1,18 @@
import java.util.List; 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 { 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) { public OnlinePlayer_1_1_0(Integer size, AsyncSocket socket) {
super(size, socket); super(size, socket);
} }
@ -58,7 +70,23 @@ public class OnlinePlayer_1_1_0 extends OnlinePlayer {
Point point = new Point(data.get(0)); Point point = new Point(data.get(0));
int typeIndex = Integer.parseInt(data.get(1)); int typeIndex = Integer.parseInt(data.get(1));
if (Point.isValidSyntax(data.get(0)) && typeIndex >= 0 && typeIndex < HitResponseType.values().length){ if (Point.isValidSyntax(data.get(0)) && typeIndex >= 0 && typeIndex < HitResponseType.values().length){
this.enemy.receiveHit(new HitResponse(typeIndex, point));
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;
}
} }
} }
break; break;
@ -68,10 +96,7 @@ public class OnlinePlayer_1_1_0 extends OnlinePlayer {
break; break;
case "WITHDRAW": case "WITHDRAW":
//Found funny cheese to do this without GUI Access this.withdraw();
HitResponse tmp_hit = new HitResponse(0, new Point(0,0));
tmp_hit.setType(HitResponseType.VICTORY);
this.receiveHit(tmp_hit);
break; break;
default: default:
@ -94,7 +119,7 @@ public class OnlinePlayer_1_1_0 extends OnlinePlayer {
* receives a shot from the enemy and sends it to the online partner * receives a shot from the enemy and sends it to the online partner
* if it is not the enemies turn, this method does nothing. * if it is not the enemies turn, this method does nothing.
* @param point the point to be shot * @param point the point to be shot
* @author Peer Ole Wachtel * @author Peer Ole Wachtel, Luca Conte
*/ */
@Override @Override
public synchronized void receiveShoot(Point point){ public synchronized void receiveShoot(Point point){
@ -105,10 +130,22 @@ public class OnlinePlayer_1_1_0 extends OnlinePlayer {
/** /**
* receives a hitresponse from the enemy player and sends it to the online partner * receives a hitresponse from the enemy player and sends it to the online partner
* @param hitResponse the hitresponse to be sent * @param hitResponse the hitresponse to be sent
* @author Peer Ole Wachtel * @author Peer Ole Wachtel, Luca Conte
*/ */
@Override @Override
public synchronized void receiveHit(HitResponse hitResponse) { 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())); super.socket.send(new SocketPackage("HIT", hitResponse.toString()));
} }
@ -127,9 +164,25 @@ 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 @Override
public synchronized void shoot(Point point) { public synchronized void shoot(Point point) {
// SHOULD NEVER BE CALLED ON ONLINE PLAYER. ONLY ON HUMAN PLAYER // SHOULD NEVER BE CALLED ON ONLINE PLAYER. ONLY ON HUMAN PLAYER
return; 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();
}
} }

View File

@ -1,3 +1,7 @@
/**
* abstrakte repräsentation eines Spielers
* @author Peer Ole Wachtel, Luca Conte, Lucas Bronson
*/
public abstract class Player { public abstract class Player {
protected boolean myTurn; protected boolean myTurn;
protected boolean isServer; protected boolean isServer;
@ -12,6 +16,10 @@ public abstract class Player {
protected boolean hasReceivedCoin; protected boolean hasReceivedCoin;
/**
* Konstruktor
* @author Peer Ole Wachtel, Luca Conte
*/
public Player() { public Player() {
this.setName("Player"); this.setName("Player");
this.hasReceivedCoin = false; this.hasReceivedCoin = false;
@ -29,10 +37,25 @@ public abstract class Player {
this.board = new Board(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); 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); 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); public abstract void shoot(Point point);
/** /**
@ -60,6 +83,7 @@ public abstract class Player {
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
/** /**
* returns the name of this player * returns the name of this player
* @return the name of this player * @return the name of this player
@ -126,6 +150,7 @@ public abstract class Player {
/** /**
* returns whether this player is ready and has sent their coin to the enemy player * returns whether this player is ready and has sent their coin to the enemy player
* @return the player's ready state * @return the player's ready state
* @author Lucas Bronson
*/ */
public boolean isReady() { public boolean isReady() {
return this.sentCoin; return this.sentCoin;
@ -146,4 +171,41 @@ public abstract class Player {
this.board = null; this.board = null;
this.enemy = 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();
}
} }

View File

@ -1,3 +1,7 @@
/**
* repräsentation der Koordinaten eines Feldes auf dem Spielfeld
* @author Peer Ole Wachtel, Luca Conte
*/
public class Point { public class Point {
private int x; private int x;
private int y; private int y;
@ -6,6 +10,7 @@ public class Point {
* initialises a point using X and Y coordinates starting at 0 * initialises a point using X and Y coordinates starting at 0
* @param x the x coordinate of the point 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 * @param y the y coordinate of the point starting at 0
* @author Peer Ole Wachtel
*/ */
public Point (int x, int y) { public Point (int x, int y) {
this.setX(x); this.setX(x);

View File

@ -5,6 +5,10 @@ import java.util.List;
record ShipData (int size, String name){} record ShipData (int size, String name){}
/**
* repräsentation eines Schiffes auf dem Spielfeld
* @author Peer Ole Wachtel, Lucas Bronson, Florian Hanzschel
*/
public class Ship { public class Ship {
static List<List<ShipData>> semeterList = static List<List<ShipData>> semeterList =
Arrays.asList( Arrays.asList(
@ -189,7 +193,7 @@ public class Ship {
/** /**
* returns the position of this ship * returns the position of this ship
* @return the position of this ship * @return the position of this ship
* @author Peer Ole Wachte * @author Peer Ole Wachtel
*/ */
public Point getPosition() { public Point getPosition() {
return position; return position;

View File

@ -11,9 +11,9 @@ public class ShipButton extends JButton {
private BoardDisplay boardDisplay; private BoardDisplay boardDisplay;
/** /**
* TODO fertig beschreiben * Erstellt Buttons für die beiden Spieler (Module/Schiffe)
* @param ship * @param ship Schiff von welchem der Name genommen wird
* @param boardDisplay * @param boardDisplay Klasse für Interaktion
* @author Lucas Bronson, Luca Conte, Joshua Kuklok * @author Lucas Bronson, Luca Conte, Joshua Kuklok
*/ */
public ShipButton(Ship ship, BoardDisplay boardDisplay) { public ShipButton(Ship ship, BoardDisplay boardDisplay) {

View File

@ -1,6 +1,8 @@
import java.util.Arrays; import java.util.Arrays;
import java.util.List; 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 * @author Luca Conte
*/ */
public class SocketPackage { public class SocketPackage {
@ -88,6 +90,7 @@ public class SocketPackage {
* parses the package into a string according to https://github.com/lgc-4/ProgProjekt-Netzwerkstandard * 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` * the package name and data are joined using a space " " `0x20`
* @return the package in string format * @return the package in string format
* @author Luca Conte
*/ */
public String toString() { public String toString() {
if (this.data == null || this.data.length() == 0) { if (this.data == null || this.data.length() == 0) {

View File

@ -25,7 +25,9 @@ public class SoundHandler {
"hit", "./Sound/hit.mp3", "hit", "./Sound/hit.mp3",
"destroyed", "./Sound/hit.mp3", "destroyed", "./Sound/hit.mp3",
"plop", "./Sound/plop.mp3", "plop", "./Sound/plop.mp3",
"loose", "./Sound/loosescreenWAH.mp3" "loose", "./Sound/loosescreenlaugh.mp3",
"win", "./Sound/win.mp3",
"yourturn", "./Sound/yourturn.mp3"
)); ));
/** /**

View File

@ -1,10 +1,10 @@
import java.util.ArrayList;
// import java.util.Random; wird nicht mehr verwendet
/** /**
* Diese Klasse implementiert den Harten Ki Spieler. * Diese Klasse implementiert den Harten Ki Spieler.
* @author Florian Alexy und Florian Hantzschel * @author Florian Alexy und Florian Hantzschel
* */ * */
import java.util.ArrayList;
// import java.util.Random; wird nicht mehr verwendet
public class SpecificAiPlayerHard extends AiPlayer{ public class SpecificAiPlayerHard extends AiPlayer{
private int gridSize; private int gridSize;
@ -21,7 +21,8 @@ public class SpecificAiPlayerHard extends AiPlayer{
VERTIKAL VERTIKAL
} }
private Orientierung orientierung; private Orientierung orientierung;
private Point firstHit; // Speichert den ersten Treffer zur Bestimmung der Orientierung // Speichert den ersten Treffer zur Bestimmung der Orientierung
private Point firstHit;
/** /**

View File

@ -1,10 +1,10 @@
import java.util.ArrayList;
import java.util.List;
/** /**
* Diese Klasse implementiert den Medium Ki Spieler. * Diese Klasse implementiert den Medium Ki Spieler.
* @author Florian Alexy und Florian Hantzschel * @author Florian Alexy und Florian Hantzschel
* */ * */
import java.util.ArrayList;
import java.util.List;
public class SpecificAiPlayerMedium extends AiPlayer{ public class SpecificAiPlayerMedium extends AiPlayer{
/** /**
* Liste an Punkten die beschossen werden sollen. (Mögliche weitere Segmente vom schiff) * Liste an Punkten die beschossen werden sollen. (Mögliche weitere Segmente vom schiff)
@ -48,7 +48,7 @@ public class SpecificAiPlayerMedium extends AiPlayer{
/** /**
* Die Methode bestimmt welche Position als nächstes beschossen werden soll. * Die Methode bestimmt welche Position als nächstes beschossen werden soll.
* @return * @return der Punkt auf den als nächtest geschossen werden soll
* @author Florian Alexy und Florian Hantzschel * @author Florian Alexy und Florian Hantzschel
*/ */
public Point ComputeNextShot() { public Point ComputeNextShot() {
@ -72,7 +72,7 @@ public class SpecificAiPlayerMedium extends AiPlayer{
/** /**
* Diese Methode erweitert die hitsQueue um die umliegenden Punkte die Schiffe seien könnten. * Diese Methode erweitert die hitsQueue um die umliegenden Punkte die Schiffe seien könnten.
* @param point * @param point der Punkt dessen nachbarn zur hitQueue hinzugefügt werden sollen
* @author Florian Alexy und Florian Hantzschel * @author Florian Alexy und Florian Hantzschel
*/ */
private void addAdjacentPoints(Point point) { private void addAdjacentPoints(Point point) {

View File

@ -7,7 +7,7 @@ import java.awt.*;
*/ */
public class Verbinden extends JPanel{ 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); JLabel verbindenLabel = new JLabel("Verbinde . . .",SwingConstants.CENTER);

View File

@ -26,7 +26,7 @@ public class WinScreen extends JPanel {
/** /**
* Panel bauen/Objekte hinzufuegen * Panel bauen/Objekte hinzufuegen
* @param frame Der Mainframe der Anwendung über den alle Panels angezeigt werden. * @param frame Der Mainframe der Anwendung über den alle Panels angezeigt werden.
* @author Lucas Bronson * @author Lucas Bronson, Joshua Kuklok
*/ */
public void buildPanel(MainFrame frame) { public void buildPanel(MainFrame frame) {
Timer timer = new Timer(5, new ActionListener() { Timer timer = new Timer(5, new ActionListener() {
@ -50,13 +50,14 @@ public class WinScreen extends JPanel {
timer.start(); // Timer starten timer.start(); // Timer starten
winLabel.setFont(robotoFont); winLabel.setFont(robotoFont);
winLabel.setHorizontalAlignment(SwingConstants.CENTER); winLabel.setHorizontalAlignment(SwingConstants.CENTER);
//Zurückkehren zum Hauptmenü, wenn okButton gedrückt wird SoundHandler.playSound("win");
// Zurückkehren zum Hauptmenü, wenn okButton gedrückt wird
okButton.addActionListener(new ActionListener() { okButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
frame.showPanel("MainMenu"); frame.showPanel("MainMenu");
} }
}); });
add(winLabel); add(winLabel);
add(okButton); add(okButton);

View File

@ -1,39 +0,0 @@
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();*/
}
}

View File

@ -1,4 +1,5 @@
import javax.swing.*; import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.HashMap; import java.util.HashMap;
@ -6,13 +7,9 @@ import java.util.HashMap;
/** /**
* Das startLocalGame Panel dient dem Erstellen eines lokalen Spiels. * 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. * Hier kann der Benutzer Spieler inklusive Namen und das Semester, in dem sich der Benutzer befindet, einstellen.
* @author Lucas Bronson, Joshua Kuklok * @author Lucas Bronson, Joshua Kuklok, Luca Conte
*/ */
public class startLocalGame extends JPanel { public class startLocalGame extends JPanel {
// Player
// TODO: entfernen (generell auch test button)
Player p1;
Player p2;
// Funktionshilfen // Funktionshilfen
int semesterCounter = 1; // Semester Counter Label int semesterCounter = 1; // Semester Counter Label
@ -44,12 +41,12 @@ public class startLocalGame extends JPanel {
JButton rightPlayerLeftButton = new JButton("<-"); JButton rightPlayerLeftButton = new JButton("<-");
JButton rightPlayerRightButton = new JButton("->"); JButton rightPlayerRightButton = new JButton("->");
JButton startButton = new JButton("Start!"); JButton startButton = new JButton("Start!");
JButton testButton = new JButton("Test");
// Textfelder // Textfelder
JTextField leftPlayerTextField = new JTextField(20); JTextField leftPlayerTextField = new JTextField(20);
JTextField rightPlayerTextField = new JTextField(20); JTextField rightPlayerTextField = new JTextField(20);
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
/** /**
* Konstruktor der startLocalGame. * Konstruktor der startLocalGame.
* Fügt Buttons, Textfelder und Label hinzu. * Fügt Buttons, Textfelder und Label hinzu.
@ -63,7 +60,8 @@ public class startLocalGame extends JPanel {
setLayout(null); setLayout(null);
// Setze Komponentenpositionen // Setze Komponentenpositionen
frameTitle.setBounds(20, 20, 200, 30); frameTitle.setBounds(20, 20, 500, 60);
frameTitle.setFont(robotoFont.deriveFont(50f));
add(frameTitle); add(frameTitle);
semesterLabel.setBounds(700, 300, 200, 30); semesterLabel.setBounds(700, 300, 200, 30);
@ -81,13 +79,10 @@ public class startLocalGame extends JPanel {
rightPlayerIcon.setBounds(1225, 400, 200, 128); rightPlayerIcon.setBounds(1225, 400, 200, 128);
add(rightPlayerIcon); add(rightPlayerIcon);
semesterCounterLabel.setBounds(725, 475, 50, 50); semesterCounterLabel.setBounds(705, 475, 50, 50);
semesterCounterLabel.setHorizontalAlignment(SwingConstants.CENTER); semesterCounterLabel.setHorizontalAlignment(SwingConstants.CENTER);
add(semesterCounterLabel); add(semesterCounterLabel);
testButton.setBounds(500,800,50,50);
add(testButton);
backButton.setBounds(1380, 20, 80, 80); backButton.setBounds(1380, 20, 80, 80);
add(backButton); add(backButton);
@ -97,10 +92,10 @@ public class startLocalGame extends JPanel {
leftPlayerRightButton.setBounds(250, 450, 50, 50); leftPlayerRightButton.setBounds(250, 450, 50, 50);
add(leftPlayerRightButton); add(leftPlayerRightButton);
semesterUpButton.setBounds(725, 400, 50, 50); semesterUpButton.setBounds(705, 400, 50, 50);
add(semesterUpButton); add(semesterUpButton);
semesterDownButton.setBounds(725, 550, 50, 50); semesterDownButton.setBounds(705, 550, 50, 50);
add(semesterDownButton); add(semesterDownButton);
rightPlayerLeftButton.setBounds(1200, 450, 50, 50); rightPlayerLeftButton.setBounds(1200, 450, 50, 50);
@ -196,14 +191,6 @@ 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. // Um zum startLocalGameLoadingScreen zu wechseln und Daten an Backend weiterzureichen.
startButton.addActionListener(new ActionListener() { startButton.addActionListener(new ActionListener() {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -216,7 +203,7 @@ public class startLocalGame extends JPanel {
playerClassMap.put(aiPlayerHardIcon, SpecificAiPlayerHard.class); playerClassMap.put(aiPlayerHardIcon, SpecificAiPlayerHard.class);
frame.showPanelSLGLS("startLocalGameLoadingScreen", semesterCounter); //TODO frame.showPanelSLGLS("startLocalGameLoadingScreen", semesterCounter);
Class<? extends LocalPlayer> leftPlayerClass = playerClassMap.get(leftPlayerIcon.getIcon()); Class<? extends LocalPlayer> leftPlayerClass = playerClassMap.get(leftPlayerIcon.getIcon());
Class<? extends AiPlayer> rightPlayerClass = (Class<? extends AiPlayer>) playerClassMap.get(rightPlayerIcon.getIcon()); Class<? extends AiPlayer> rightPlayerClass = (Class<? extends AiPlayer>) playerClassMap.get(rightPlayerIcon.getIcon());
@ -225,41 +212,6 @@ public class startLocalGame extends JPanel {
rightPlayerClass, rightPlayerClass,
GameController.semesterToBoardSize(semesterCounter) 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));
// }
// }
} }
}); });
@ -273,10 +225,13 @@ public class startLocalGame extends JPanel {
private void toggleLeftPlayerIconLeft() { private void toggleLeftPlayerIconLeft() {
if (leftPlayerIcon.getIcon() == humanPlayerIcon) { if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
leftPlayerIcon.setIcon(aiPlayerHardIcon); leftPlayerIcon.setIcon(aiPlayerHardIcon);
} else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon){ } else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon){
leftPlayerIcon.setIcon(humanPlayerIcon); leftPlayerIcon.setIcon(humanPlayerIcon);
} else if (leftPlayerIcon.getIcon() == aiPlayerNormalIcon) { } else if (leftPlayerIcon.getIcon() == aiPlayerNormalIcon) {
leftPlayerIcon.setIcon(aiPlayerEasyIcon); leftPlayerIcon.setIcon(aiPlayerEasyIcon);
} else if (leftPlayerIcon.getIcon() == aiPlayerHardIcon) { } else if (leftPlayerIcon.getIcon() == aiPlayerHardIcon) {
leftPlayerIcon.setIcon(aiPlayerNormalIcon); leftPlayerIcon.setIcon(aiPlayerNormalIcon);
} }
@ -289,10 +244,13 @@ public class startLocalGame extends JPanel {
private void toggleLeftPlayerIconRight() { private void toggleLeftPlayerIconRight() {
if (leftPlayerIcon.getIcon() == humanPlayerIcon) { if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
leftPlayerIcon.setIcon(aiPlayerEasyIcon); leftPlayerIcon.setIcon(aiPlayerEasyIcon);
} else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon){ } else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon){
leftPlayerIcon.setIcon(aiPlayerNormalIcon); leftPlayerIcon.setIcon(aiPlayerNormalIcon);
} else if (leftPlayerIcon.getIcon() == aiPlayerNormalIcon) { } else if (leftPlayerIcon.getIcon() == aiPlayerNormalIcon) {
leftPlayerIcon.setIcon(aiPlayerHardIcon); leftPlayerIcon.setIcon(aiPlayerHardIcon);
} else if (leftPlayerIcon.getIcon() == aiPlayerHardIcon) { } else if (leftPlayerIcon.getIcon() == aiPlayerHardIcon) {
leftPlayerIcon.setIcon(humanPlayerIcon); leftPlayerIcon.setIcon(humanPlayerIcon);
} }
@ -305,8 +263,10 @@ public class startLocalGame extends JPanel {
private void toggleRightPlayerIconLeft() { private void toggleRightPlayerIconLeft() {
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) { if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
rightPlayerIcon.setIcon(aiPlayerHardIcon); rightPlayerIcon.setIcon(aiPlayerHardIcon);
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon){ } else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon){
rightPlayerIcon.setIcon(aiPlayerEasyIcon); rightPlayerIcon.setIcon(aiPlayerEasyIcon);
} else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) { } else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
rightPlayerIcon.setIcon(aiPlayerNormalIcon); rightPlayerIcon.setIcon(aiPlayerNormalIcon);
} }
@ -319,8 +279,10 @@ public class startLocalGame extends JPanel {
private void toggleRightPlayerIconRight() { private void toggleRightPlayerIconRight() {
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) { if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
rightPlayerIcon.setIcon(aiPlayerNormalIcon); rightPlayerIcon.setIcon(aiPlayerNormalIcon);
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon){ } else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon){
rightPlayerIcon.setIcon(aiPlayerHardIcon); rightPlayerIcon.setIcon(aiPlayerHardIcon);
} else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) { } else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
rightPlayerIcon.setIcon(aiPlayerEasyIcon); rightPlayerIcon.setIcon(aiPlayerEasyIcon);
} }
@ -334,10 +296,13 @@ public class startLocalGame extends JPanel {
// Für Linken Spieler // Für Linken Spieler
if (leftPlayerIcon.getIcon() == humanPlayerIcon) { if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
leftPlayerTextField.setText(leftPlayerNickname); leftPlayerTextField.setText(leftPlayerNickname);
} else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon){ } else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon){
leftPlayerTextField.setText("Einfach"); leftPlayerTextField.setText("Einfach");
} else if (leftPlayerIcon.getIcon() == aiPlayerNormalIcon) { } else if (leftPlayerIcon.getIcon() == aiPlayerNormalIcon) {
leftPlayerTextField.setText("Mittel"); leftPlayerTextField.setText("Mittel");
} else if (leftPlayerIcon.getIcon() == aiPlayerHardIcon) { } else if (leftPlayerIcon.getIcon() == aiPlayerHardIcon) {
leftPlayerTextField.setText("Schwer"); leftPlayerTextField.setText("Schwer");
} }
@ -345,8 +310,10 @@ public class startLocalGame extends JPanel {
// Für Rechten Spieler // Für Rechten Spieler
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon){ if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon){
rightPlayerTextField.setText("Einfach"); rightPlayerTextField.setText("Einfach");
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) { } else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
rightPlayerTextField.setText("Mittel"); rightPlayerTextField.setText("Mittel");
} else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) { } else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
rightPlayerTextField.setText("Schwer"); rightPlayerTextField.setText("Schwer");
} }

View File

@ -1,4 +1,5 @@
import javax.swing.*; import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
@ -39,12 +40,14 @@ public class startMultiplayerGame extends JPanel {
// Textfelder // Textfelder
JTextField PlayerTextField = new JTextField(20); JTextField PlayerTextField = new JTextField(20);
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
/** /**
* Konstruktor der startLocalGame. * Konstruktor der startLocalGame.
* Fügt Buttons, Textfelder und Label hinzu. * Fügt Buttons, Textfelder und Label hinzu.
* Fügt ebenfalls ActionListeners hinzu, damit Buttons etc. ihre gewünschte Funktion haben * 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. * @param frame Der Mainframe der Anwendung über den alle Panels angezeigt werden.
* @author Joshua Kuklok * @author Joshua Kuklok, Lucas Bronson
*/ */
startMultiplayerGame(MainFrame frame) { startMultiplayerGame(MainFrame frame) {
@ -52,7 +55,8 @@ public class startMultiplayerGame extends JPanel {
setLayout(null); setLayout(null);
// Setze Komponentenpositionen // Setze Komponentenpositionen
frameTitle.setBounds(20, 20, 200, 30); frameTitle.setBounds(20, 20, 500, 60);
frameTitle.setFont(robotoFont.deriveFont(50f));
add(frameTitle); add(frameTitle);
semesterLabel.setBounds(700, 300, 200, 30); semesterLabel.setBounds(700, 300, 200, 30);
@ -64,7 +68,7 @@ public class startMultiplayerGame extends JPanel {
PlayerIcon.setBounds(75, 400, 200, 128); PlayerIcon.setBounds(75, 400, 200, 128);
add(PlayerIcon); add(PlayerIcon);
semesterCounterLabel.setBounds(725, 475, 50, 50); // zwischen den Up/Down-Buttons semesterCounterLabel.setBounds(705, 475, 50, 50); // zwischen den Up/Down-Buttons
semesterCounterLabel.setHorizontalAlignment(SwingConstants.CENTER); semesterCounterLabel.setHorizontalAlignment(SwingConstants.CENTER);
add(semesterCounterLabel); add(semesterCounterLabel);
@ -77,10 +81,10 @@ public class startMultiplayerGame extends JPanel {
PlayerRightButton.setBounds(250, 450, 50, 50); PlayerRightButton.setBounds(250, 450, 50, 50);
add(PlayerRightButton); add(PlayerRightButton);
semesterUpButton.setBounds(725, 400, 50, 50); semesterUpButton.setBounds(705, 400, 50, 50);
add(semesterUpButton); add(semesterUpButton);
semesterDownButton.setBounds(725, 550, 50, 50); semesterDownButton.setBounds(705, 550, 50, 50);
add(semesterDownButton); add(semesterDownButton);
joinGameButton.setBounds(1100, 350, 200, 50); joinGameButton.setBounds(1100, 350, 200, 50);
@ -150,13 +154,13 @@ public class startMultiplayerGame extends JPanel {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (PlayerIcon.getIcon() == humanPlayerIcon) { if (PlayerIcon.getIcon() == humanPlayerIcon) {
frame.showPanelSMG("JoinGame",1,0, PlayerNickname); frame.showPanelSMG("JoinGame",1,0, PlayerNickname, semesterCounter);
} else if ( PlayerIcon.getIcon() == aiPlayerEasyIcon) { } else if ( PlayerIcon.getIcon() == aiPlayerEasyIcon) {
frame.showPanelSMG("JoinGame",1,1, PlayerNickname); frame.showPanelSMG("JoinGame",1,1, PlayerNickname, semesterCounter);
} else if ( PlayerIcon.getIcon() == aiPlayerNormalIcon) { } else if ( PlayerIcon.getIcon() == aiPlayerNormalIcon) {
frame.showPanelSMG("JoinGame",1,2, PlayerNickname); frame.showPanelSMG("JoinGame",1,2, PlayerNickname, semesterCounter);
} else if ( PlayerIcon.getIcon() == aiPlayerHardIcon) { } else if ( PlayerIcon.getIcon() == aiPlayerHardIcon) {
frame.showPanelSMG("JoinGame",1,3, PlayerNickname); frame.showPanelSMG("JoinGame",1,3, PlayerNickname, semesterCounter);
} }
} }
}); });
@ -167,13 +171,13 @@ public class startMultiplayerGame extends JPanel {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
//Parameter -> panelName, Spiel erstellen oder beitreten (int), Spielertyp(int 0-3), Spielername //Parameter -> panelName, Spiel erstellen oder beitreten (int), Spielertyp(int 0-3), Spielername
if (PlayerIcon.getIcon() == humanPlayerIcon) { if (PlayerIcon.getIcon() == humanPlayerIcon) {
frame.showPanelSMG("JoinGame",0,0, PlayerNickname); frame.showPanelSMG("JoinGame",0,0, PlayerNickname, semesterCounter);
} else if ( PlayerIcon.getIcon() == aiPlayerEasyIcon) { } else if ( PlayerIcon.getIcon() == aiPlayerEasyIcon) {
frame.showPanelSMG("JoinGame",0,1, PlayerNickname); frame.showPanelSMG("JoinGame",0,1, PlayerNickname, semesterCounter);
} else if ( PlayerIcon.getIcon() == aiPlayerNormalIcon) { } else if ( PlayerIcon.getIcon() == aiPlayerNormalIcon) {
frame.showPanelSMG("JoinGame",0,2, PlayerNickname); frame.showPanelSMG("JoinGame",0,2, PlayerNickname, semesterCounter);
} else if ( PlayerIcon.getIcon() == aiPlayerHardIcon) { } else if ( PlayerIcon.getIcon() == aiPlayerHardIcon) {
frame.showPanelSMG("JoinGame",0,3, PlayerNickname); frame.showPanelSMG("JoinGame",0,3, PlayerNickname, semesterCounter);
} }
} }
}); });
@ -188,10 +192,13 @@ public class startMultiplayerGame extends JPanel {
private void togglePlayerIconLeft() { private void togglePlayerIconLeft() {
if (PlayerIcon.getIcon() == humanPlayerIcon) { if (PlayerIcon.getIcon() == humanPlayerIcon) {
PlayerIcon.setIcon(aiPlayerHardIcon); PlayerIcon.setIcon(aiPlayerHardIcon);
} else if (PlayerIcon.getIcon() == aiPlayerEasyIcon){ } else if (PlayerIcon.getIcon() == aiPlayerEasyIcon){
PlayerIcon.setIcon(humanPlayerIcon); PlayerIcon.setIcon(humanPlayerIcon);
} else if (PlayerIcon.getIcon() == aiPlayerNormalIcon) { } else if (PlayerIcon.getIcon() == aiPlayerNormalIcon) {
PlayerIcon.setIcon(aiPlayerEasyIcon); PlayerIcon.setIcon(aiPlayerEasyIcon);
} else if (PlayerIcon.getIcon() == aiPlayerHardIcon) { } else if (PlayerIcon.getIcon() == aiPlayerHardIcon) {
PlayerIcon.setIcon(aiPlayerNormalIcon); PlayerIcon.setIcon(aiPlayerNormalIcon);
} }
@ -204,10 +211,13 @@ public class startMultiplayerGame extends JPanel {
private void togglePlayerIconRight() { private void togglePlayerIconRight() {
if (PlayerIcon.getIcon() == humanPlayerIcon) { if (PlayerIcon.getIcon() == humanPlayerIcon) {
PlayerIcon.setIcon(aiPlayerEasyIcon); PlayerIcon.setIcon(aiPlayerEasyIcon);
} else if (PlayerIcon.getIcon() == aiPlayerEasyIcon){ } else if (PlayerIcon.getIcon() == aiPlayerEasyIcon){
PlayerIcon.setIcon(aiPlayerNormalIcon); PlayerIcon.setIcon(aiPlayerNormalIcon);
} else if (PlayerIcon.getIcon() == aiPlayerNormalIcon) { } else if (PlayerIcon.getIcon() == aiPlayerNormalIcon) {
PlayerIcon.setIcon(aiPlayerHardIcon); PlayerIcon.setIcon(aiPlayerHardIcon);
} else if (PlayerIcon.getIcon() == aiPlayerHardIcon) { } else if (PlayerIcon.getIcon() == aiPlayerHardIcon) {
PlayerIcon.setIcon(humanPlayerIcon); PlayerIcon.setIcon(humanPlayerIcon);
} }
@ -220,10 +230,13 @@ public class startMultiplayerGame extends JPanel {
private void updateTextFields() { private void updateTextFields() {
if (PlayerIcon.getIcon() == humanPlayerIcon) { if (PlayerIcon.getIcon() == humanPlayerIcon) {
PlayerTextField.setText(PlayerNickname); PlayerTextField.setText(PlayerNickname);
} else if (PlayerIcon.getIcon() == aiPlayerEasyIcon){ } else if (PlayerIcon.getIcon() == aiPlayerEasyIcon){
PlayerTextField.setText("Einfach"); PlayerTextField.setText("Einfach");
} else if (PlayerIcon.getIcon() == aiPlayerNormalIcon) { } else if (PlayerIcon.getIcon() == aiPlayerNormalIcon) {
PlayerTextField.setText("Mittel"); PlayerTextField.setText("Mittel");
} else if (PlayerIcon.getIcon() == aiPlayerHardIcon) { } else if (PlayerIcon.getIcon() == aiPlayerHardIcon) {
PlayerTextField.setText("Schwer"); PlayerTextField.setText("Schwer");
} }