From 8ae51f6316034fef380d2335c6cf75094ad8199c Mon Sep 17 00:00:00 2001 From: eyFlorian <45431375+eyFlorian@users.noreply.github.com> Date: Sun, 3 Nov 2024 12:39:19 +0100 Subject: [PATCH] Locales Spiel Initialisierung MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Florian und Florian Haben 3 Stunden an diesem kack gearbeitet. Player, AiPlayer und jeweils die Boards wurden erstellt und Initialisiert. Erweiterung zu Hitresponse /- type für die Board. --- src/AiPlayer.java | 7 ++++++ src/Board.java | 43 +++++++++++++++++++++++++++++++++- src/GameController.java | 31 ++++++++++++++++++++++++ src/HalloSchiffeVersenken.java | 12 +++++++--- src/HitResponse.java | 14 +++++++++++ src/HitResponseType.java | 2 +- src/HumanPlayer.java | 34 +++++++++++++++++++++++++++ src/LocalPlayer.java | 4 ++++ src/Ship.java | 24 +++++++++++++++++++ src/SpecificAiPlayer1.java | 21 +++++++++++++++++ 10 files changed, 187 insertions(+), 5 deletions(-) create mode 100644 src/AiPlayer.java create mode 100644 src/GameController.java create mode 100644 src/HumanPlayer.java create mode 100644 src/LocalPlayer.java create mode 100644 src/Ship.java create mode 100644 src/SpecificAiPlayer1.java diff --git a/src/AiPlayer.java b/src/AiPlayer.java new file mode 100644 index 0000000..f95b6d1 --- /dev/null +++ b/src/AiPlayer.java @@ -0,0 +1,7 @@ + +public abstract class AiPlayer { + + public void setBoardSize(int s) { + // raum für schmerzen + } +} diff --git a/src/Board.java b/src/Board.java index edb598b..73564c9 100644 --- a/src/Board.java +++ b/src/Board.java @@ -1,2 +1,43 @@ +import java.util.List; + public class Board { -} +/* + - hits : List + - ships : List + - size : int + - display : BoardDisplay +*/ + /* + * + hit(HitResponse) + * + click(Point) : void + */ + + List hits; + List ships; + int size; + + public Board() { + // MISS,SHIP, HIT + // MISS bedeutet nichts auf der Position vorhanden + // SHIP bedeutet ungetroffenes Schiff auf der Position vorhanden + // HIT bedeutet getroffenes Schiff auf der Position vorhanden + + + } + + public void setSize(int s) { + this.size = s; + } + + public void initBoard() { + + for (int i=0;size>i;i++) { + for (int j=0;size>j;j++) { + HitResponse missPos = new HitResponse(); + missPos.setHitResponse(HitResponseType.MISS); + missPos.setPoint(i,j); + hits.add(missPos); + } + } + } +} \ No newline at end of file diff --git a/src/GameController.java b/src/GameController.java new file mode 100644 index 0000000..a452755 --- /dev/null +++ b/src/GameController.java @@ -0,0 +1,31 @@ +public class GameController { + + + public void startOnlineGame() { + // fuck you Luca and Ole von Florian und nicht von Florian + } + + public void startLocalGame(HumanPlayer player, AiPlayer enemy, int size) { + //Player initialisieren Board + player.setBoardSize(size); + enemy.setBoardSize(size); + + // Schiffe setzen + // für player durch UI + + /* + * Todo + * enemy.setships(); + */ + + boolean condition = true; + while(condition) { + //Gameloop bis Sieger + //WIP + break; + + } + + } + +} \ No newline at end of file diff --git a/src/HalloSchiffeVersenken.java b/src/HalloSchiffeVersenken.java index b84600f..6d8f05e 100644 --- a/src/HalloSchiffeVersenken.java +++ b/src/HalloSchiffeVersenken.java @@ -1,10 +1,16 @@ public class HalloSchiffeVersenken { public static void main(String[] args) throws InterruptedException { + int default_size = 14; + + HumanPlayer player = new HumanPlayer(); + AiPlayer enemy = new SpecificAiPlayer1(); // auswählen hehe. mal gucken und viel spaßßß + GameController game_controller = new GameController(); + game_controller.startLocalGame(player, enemy, default_size); // default_size oder auswählen, viel spaß + + /* System.out.println("HelloSchiffeVersenekn"); - - System.out.println("sound"); SoundHandler.playSound("hit"); Thread.sleep(3000); @@ -13,7 +19,7 @@ public class HalloSchiffeVersenken { SoundHandler.setSoundOn(false); System.out.println("sound off"); SoundHandler.playSound("hit"); - + */ } } diff --git a/src/HitResponse.java b/src/HitResponse.java index f5c3913..b913c3c 100644 --- a/src/HitResponse.java +++ b/src/HitResponse.java @@ -3,4 +3,18 @@ import java.awt.*; public class HitResponse { private HitResponseType type; private Point point; + + public HitResponseType getHitResponse() { + return this.type; + } + public void setHitResponse(HitResponseType a) { + this.type = a; + } + + public Point getPoint() { + return this.point; + } + public void setPoint(int x, int y) { + this.point = new Point(x,y); + } } diff --git a/src/HitResponseType.java b/src/HitResponseType.java index 4b1237c..51c82a4 100644 --- a/src/HitResponseType.java +++ b/src/HitResponseType.java @@ -1,3 +1,3 @@ public enum HitResponseType { - MISS, HIT, SUNK, VICTORY + MISS, SHIP, HIT, SUNK, VICTORY } diff --git a/src/HumanPlayer.java b/src/HumanPlayer.java new file mode 100644 index 0000000..582d864 --- /dev/null +++ b/src/HumanPlayer.java @@ -0,0 +1,34 @@ + +public class HumanPlayer extends LocalPlayer { + /* + - myTurn : bool + - isServer : bool + - waitingForResponse : bool + - enemy : Player + - name : String + - board : Board + + receiveShoot(Point) : void + + receiveHit(HitResponse) : void + + click(Point) : void + + beginTurn() : void + + */ + + private boolean myTurn; + private boolean isServer; + private boolean waitingForResponse; + private Player enemy; + private String name; + private Board board; + + + public HumanPlayer() { + Board board = new Board(); + this.board = board; + } + + public void setBoardSize(int s) { + this.board.setSize(s); + this.board.initBoard(); + } +} diff --git a/src/LocalPlayer.java b/src/LocalPlayer.java new file mode 100644 index 0000000..686b874 --- /dev/null +++ b/src/LocalPlayer.java @@ -0,0 +1,4 @@ +public class LocalPlayer extends Player { + + +} \ No newline at end of file diff --git a/src/Ship.java b/src/Ship.java new file mode 100644 index 0000000..2a5155a --- /dev/null +++ b/src/Ship.java @@ -0,0 +1,24 @@ +import java.awt.Point; + +public class Ship { + /* + - size : int + - horizontal : bool + - position : Point + - name : String + - button : ShipButton + + + + setPosition(Point) : void + + */ + int size; + boolean horizontal; + Point position; + String name; + + public void setPosition(Point pos) { + // raum für gedanken und die Methode + } + +} diff --git a/src/SpecificAiPlayer1.java b/src/SpecificAiPlayer1.java new file mode 100644 index 0000000..7a85970 --- /dev/null +++ b/src/SpecificAiPlayer1.java @@ -0,0 +1,21 @@ + +public class SpecificAiPlayer1 extends AiPlayer{ + + private boolean myTurn; + private boolean isServer; + private boolean waitingForResponse; + private Player enemy; + private String name; + private Board board; + + + public SpecificAiPlayer1() { + Board board = new Board(); + this.board = board; + } + + public void setBoardSize(int s) { + this.board.setSize(s); + this.board.initBoard(); + } +}