Compare commits
No commits in common. "4dd1c9b39bdfbb305f89cc241870b2a01c66697b" and "e27b852c14ad1ddf9a02f14ef942acee83cbd4e5" have entirely different histories.
4dd1c9b39b
...
e27b852c14
|
@ -1,16 +1,9 @@
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
public abstract class AiPlayer extends LocalPlayer {
|
||||||
public abstract class AiPlayer extends LocalPlayer implements Runnable {
|
|
||||||
|
|
||||||
List<Thread> shootThreads;
|
|
||||||
|
|
||||||
public AiPlayer() {
|
public AiPlayer() {
|
||||||
this.setName("AI Player");
|
this.setName("AI Player");
|
||||||
this.shootThreads = new ArrayList<>();
|
|
||||||
}
|
}
|
||||||
public Point RandomPoint() {
|
public Point RandomPoint() {
|
||||||
Random random = new Random(); // Pseudo Random für zufallszahlen
|
Random random = new Random(); // Pseudo Random für zufallszahlen
|
||||||
|
@ -19,14 +12,7 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable {
|
||||||
return new Point(posx,posy);
|
return new Point(posx,posy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void AiSetShips() {
|
||||||
public void createBoard(int size) {
|
|
||||||
super.createBoard(size);
|
|
||||||
this.aiSetShips();
|
|
||||||
this.ready();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void aiSetShips() {
|
|
||||||
for(int i = 0; i < super.board.getShips().size(); i++) { // Interiert durch alle Shiffe
|
for(int i = 0; i < super.board.getShips().size(); i++) { // Interiert durch alle Shiffe
|
||||||
//TODO: set horizontal
|
//TODO: set horizontal
|
||||||
while(!super.board.getShips().get(i).setPosition(RandomPoint(), true, super.board.getShips(), super.board.getSize())) {}
|
while(!super.board.getShips().get(i).setPosition(RandomPoint(), true, super.board.getShips(), super.board.getSize())) {}
|
||||||
|
@ -34,63 +20,8 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void aiShoot() {
|
public void AiShoot() {
|
||||||
this.enemy.receiveShoot(RandomPoint());
|
super.board.hit(RandomPoint());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void receiveHit(HitResponse hitResponse) {
|
|
||||||
super.receiveHit(hitResponse);
|
|
||||||
if (this.myTurn) {
|
|
||||||
Thread t = new Thread(this);
|
|
||||||
t.start();
|
|
||||||
this.shootThreads.add(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void receiveShoot(Point point) {
|
|
||||||
super.receiveShoot(point);
|
|
||||||
if (this.myTurn) {
|
|
||||||
Thread t = new Thread(this);
|
|
||||||
t.start();
|
|
||||||
this.shootThreads.add(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void beginTurn() {
|
|
||||||
Thread t = new Thread(this);
|
|
||||||
t.start();
|
|
||||||
this.shootThreads.add(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run() {
|
|
||||||
Iterator<Thread> i = this.shootThreads.iterator();
|
|
||||||
while(i.hasNext()) {
|
|
||||||
Thread thread = i.next();
|
|
||||||
if (!thread.isAlive()) {
|
|
||||||
try {
|
|
||||||
thread.join();
|
|
||||||
i.remove();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
Thread.sleep(300);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.aiShoot();
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -40,7 +40,6 @@ 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.
|
||||||
|
@ -137,6 +136,7 @@ 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);
|
||||||
|
@ -159,10 +159,6 @@ public class GameBoard extends JPanel {
|
||||||
kontextText.setText(kT2);
|
kontextText.setText(kT2);
|
||||||
p1.ready();
|
p1.ready();
|
||||||
if(true) {
|
if(true) {
|
||||||
remove(readyButton);
|
|
||||||
remove(resetButton);
|
|
||||||
remove(rightButtonsPanel);
|
|
||||||
remove(leftButtonsPanel);
|
|
||||||
readyButton.setEnabled(false);
|
readyButton.setEnabled(false);
|
||||||
resetButton.setEnabled(false);
|
resetButton.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
@ -216,14 +212,4 @@ public class GameBoard extends JPanel {
|
||||||
this.ownBoardPanel.refresh();
|
this.ownBoardPanel.refresh();
|
||||||
this.opponentBoardPanel.refresh();
|
this.opponentBoardPanel.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Getter für Player1
|
|
||||||
* @return Player 1
|
|
||||||
* @author Peer Ole Wachtel
|
|
||||||
*/
|
|
||||||
public Player getP1() {
|
|
||||||
return p1;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,16 +160,12 @@ public class GameController {
|
||||||
throw new RuntimeException("Unable to instantiate players");
|
throw new RuntimeException("Unable to instantiate players");
|
||||||
}
|
}
|
||||||
|
|
||||||
localPlayer.isServer = true;
|
localPlayer.createBoard(size);
|
||||||
aiPlayer.isServer = false;
|
aiPlayer.createBoard(size);
|
||||||
|
|
||||||
|
|
||||||
localPlayer.setEnemy(aiPlayer);
|
localPlayer.setEnemy(aiPlayer);
|
||||||
aiPlayer.setEnemy(localPlayer);
|
aiPlayer.setEnemy(localPlayer);
|
||||||
|
|
||||||
localPlayer.createBoard(size);
|
|
||||||
aiPlayer.createBoard(size);
|
|
||||||
|
|
||||||
localPlayer.setName(localPlayerName);
|
localPlayer.setName(localPlayerName);
|
||||||
|
|
||||||
startGameWithInstancedPlayers(localPlayer, aiPlayer, size);
|
startGameWithInstancedPlayers(localPlayer, aiPlayer, size);
|
||||||
|
|
|
@ -22,7 +22,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().showPanelLose("", this); //TODO Was halt bei victory passiert ist hier wurder verloheren
|
case VICTORY -> System.out.println("Game Over"); //TODO Was halt bei victory passiert ist hier wurder verloheren
|
||||||
}
|
}
|
||||||
GameController.getMainFrame().refreshGameBoard();
|
GameController.getMainFrame().refreshGameBoard();
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,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 -> System.out.println("Win"); // TODO was halt beim victory passier ist hier wurde gewonnen
|
||||||
}
|
}
|
||||||
GameController.getMainFrame().refreshGameBoard();
|
GameController.getMainFrame().refreshGameBoard();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,22 @@
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Klasse für Erstellung von looseScreen Objekten
|
* Klasse für Erstellung von looseScreen Objekten
|
||||||
* Dient zur Anzeige das ein Spiel verloren wurde
|
* Dient zur Anzeige das ein Spiel verloren wurde
|
||||||
*/
|
*/
|
||||||
public class LoseScreen extends JPanel {
|
public class LooseScreen extends JPanel {
|
||||||
JLabel loseLabel = new JLabel("Du hast Verloren");
|
JLabel looseLabel = new JLabel("Du hast Verloren");
|
||||||
JButton okButton = new JButton("Zurück zum Hauptmenü");
|
JButton okButton = new JButton("Zurück zum Hauptmenü");
|
||||||
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
|
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Konstruktor der LoseScreen Klasse
|
* Konstruktor der LooseScreen Klasse
|
||||||
* @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
|
||||||
*/
|
*/
|
||||||
public LoseScreen(MainFrame frame) {
|
public LooseScreen(MainFrame frame) {
|
||||||
setLayout(null);
|
setLayout(new BorderLayout());
|
||||||
buildPanel(frame);
|
buildPanel(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,17 +26,9 @@ public class LoseScreen extends JPanel {
|
||||||
* @author Lucas Bronson
|
* @author Lucas Bronson
|
||||||
*/
|
*/
|
||||||
public void buildPanel(MainFrame frame) {
|
public void buildPanel(MainFrame frame) {
|
||||||
add(loseLabel);
|
add(looseLabel);
|
||||||
okButton.setBounds(650,525,200,50);
|
okButton.setBounds(650,525,200,50);
|
||||||
loseLabel.setBounds(550,450,500,50);
|
looseLabel.setBounds(500,450,500,50);
|
||||||
loseLabel.setFont(robotoFont);
|
looseLabel.setFont(robotoFont);
|
||||||
okButton.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
frame.showPanel("MainMenu");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
add(loseLabel);
|
|
||||||
add(okButton);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -127,13 +127,9 @@ 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
|
* @author Lucas Bronson
|
||||||
* @author Lucas Bronson, Peer Ole Wachtel
|
|
||||||
*/
|
*/
|
||||||
public void showPanelWin(String panelName, Player player){
|
public void showPanelWin(String panelName){
|
||||||
if(player != gameBoard.getP1()){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
WinScreen winScreen = new WinScreen(this);
|
WinScreen winScreen = new WinScreen(this);
|
||||||
mainPanel.add(winScreen, panelName);
|
mainPanel.add(winScreen, panelName);
|
||||||
mainPanel.revalidate();
|
mainPanel.revalidate();
|
||||||
|
@ -144,14 +140,10 @@ 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
|
* @author Lucas Bronson
|
||||||
* @author Lucas Bronson, Peer Ole Wachtel
|
|
||||||
*/
|
*/
|
||||||
public void showPanelLose(String panelName, Player player){
|
public void showPanelLoose(String panelName){
|
||||||
if(player != gameBoard.getP1()){
|
LooseScreen looseScreen = new LooseScreen(this);
|
||||||
return;
|
|
||||||
}
|
|
||||||
LoseScreen looseScreen = new LoseScreen(this);
|
|
||||||
mainPanel.add(looseScreen,panelName);
|
mainPanel.add(looseScreen,panelName);
|
||||||
mainPanel.revalidate();
|
mainPanel.revalidate();
|
||||||
mainPanel.repaint();
|
mainPanel.repaint();
|
||||||
|
@ -163,9 +155,6 @@ public class MainFrame extends JFrame {
|
||||||
* @author Luca Conte
|
* @author Luca Conte
|
||||||
*/
|
*/
|
||||||
public void refreshGameBoard() {
|
public void refreshGameBoard() {
|
||||||
if(this.gameBoard == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.gameBoard.refresh();
|
this.gameBoard.refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,7 +6,6 @@ import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,14 +48,12 @@ public class SoundHandler {
|
||||||
thread.start();
|
thread.start();
|
||||||
runningThreads.add(thread);
|
runningThreads.add(thread);
|
||||||
}
|
}
|
||||||
Iterator<Thread> i = runningThreads.iterator();
|
for (Thread oldThread : runningThreads) {
|
||||||
while (i.hasNext()) {
|
|
||||||
Thread oldThread = i.next();
|
|
||||||
if (!oldThread.isAlive()) {
|
if (!oldThread.isAlive()) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
oldThread.join();
|
oldThread.join();
|
||||||
i.remove();
|
runningThreads.remove(oldThread);
|
||||||
System.out.println("cleared thread");
|
System.out.println("cleared thread");
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -1,9 +1,3 @@
|
||||||
|
|
||||||
public class SpecificAiPlayerEasy extends AiPlayer{
|
public class SpecificAiPlayerEasy extends AiPlayer{
|
||||||
|
|
||||||
public SpecificAiPlayerEasy() {
|
|
||||||
super();
|
|
||||||
this.setName("AI Player Easy");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,125 +1,3 @@
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class SpecificAiPlayerHard extends AiPlayer{
|
public class SpecificAiPlayerHard extends AiPlayer{
|
||||||
|
|
||||||
private int gridSize;
|
|
||||||
private boolean[][] shotsFired;
|
|
||||||
private final ArrayList<Point> hitQueue;
|
|
||||||
private final Random random;
|
|
||||||
private int nextChessRow;
|
|
||||||
private int nextChessCol;
|
|
||||||
|
|
||||||
public SpecificAiPlayerHard() {
|
|
||||||
super();
|
|
||||||
this.setName("AI Player Hard");
|
|
||||||
/*this.gridSize = super.board.getSize();
|
|
||||||
this.shotsFired = new boolean[gridSize][gridSize];*/
|
|
||||||
this.gridSize = 0;
|
|
||||||
this.hitQueue = new ArrayList<>();
|
|
||||||
this.random = new Random();
|
|
||||||
this.nextChessRow = 0;
|
|
||||||
this.nextChessCol = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Checks if a position has already been shot at
|
|
||||||
public boolean alreadyShot(Point p) {
|
|
||||||
return shotsFired[p.getX()][p.getY()];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generates the next move for the AI
|
|
||||||
public Point getNextMove() {
|
|
||||||
if(gridSize == 0) {
|
|
||||||
this.gridSize = super.board.getSize();
|
|
||||||
this.shotsFired = new boolean[gridSize][gridSize];
|
|
||||||
}
|
|
||||||
// If there are hits to process, prioritize those
|
|
||||||
while (!hitQueue.isEmpty()) {
|
|
||||||
Point target = hitQueue.remove(0);
|
|
||||||
|
|
||||||
if (!alreadyShot(target)) {
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, use chess pattern targeting
|
|
||||||
int row = nextChessRow;
|
|
||||||
int col = nextChessCol;
|
|
||||||
while (alreadyShot(new Point(row, col))) {
|
|
||||||
advanceChessPattern();
|
|
||||||
row = nextChessRow;
|
|
||||||
col = nextChessCol;
|
|
||||||
}
|
|
||||||
|
|
||||||
shotsFired[row][col] = true;
|
|
||||||
advanceChessPattern();
|
|
||||||
return new Point(row, col);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void receiveHit(HitResponse hitResponse) {
|
|
||||||
super.receiveHit(hitResponse);
|
|
||||||
// If it's a hit or sunk, add adjacent cells to the hitsQueue
|
|
||||||
if (hitResponse.getHitResponse() == HitResponseType.HIT) {
|
|
||||||
addAdjacentPoints(hitResponse.getPoint());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addAdjacentPoints(Point point) {
|
|
||||||
int x = point.getX();
|
|
||||||
int y = point.getY();
|
|
||||||
|
|
||||||
// Possible adjacent positions (up, down, left, right)
|
|
||||||
Point[] adjacentPoints = {
|
|
||||||
new Point(x, y - 1),
|
|
||||||
new Point(x, y + 1),
|
|
||||||
new Point(x - 1, y),
|
|
||||||
new Point(x + 1, y)
|
|
||||||
};
|
|
||||||
|
|
||||||
for (Point p : adjacentPoints) {
|
|
||||||
if (isValidPoint(p) && !alreadyShot(p) && !hitQueue.contains(p)) {
|
|
||||||
hitQueue.add(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isValidPoint(Point point) {
|
|
||||||
return point.getX() >= 0 && point.getX() < gridSize &&
|
|
||||||
point.getY() >= 0 && point.getY() < gridSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void aiShoot() {
|
|
||||||
this.enemy.receiveShoot(getNextMove());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Advances the chess pattern to the next cell
|
|
||||||
private void advanceChessPattern() {
|
|
||||||
nextChessCol += 2;
|
|
||||||
if (nextChessCol >= gridSize) {
|
|
||||||
nextChessRow += 1;
|
|
||||||
nextChessCol = (nextChessRow % 2 == 0) ? 0 : 1; // Alternate starting points for chess pattern
|
|
||||||
}
|
|
||||||
if (nextChessRow >= gridSize) {
|
|
||||||
nextChessRow = 0;
|
|
||||||
nextChessCol = 0; // Reset if pattern wraps around
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adds adjacent cells to the hit queue
|
|
||||||
/* public void processHit(int row, int col) {
|
|
||||||
if (row > 0 && !alreadyShot(row - 1, col)) {
|
|
||||||
hitQueue.add(new int[]{row - 1, col});
|
|
||||||
}
|
|
||||||
if (row < gridSize - 1 && !alreadyShot(row + 1, col)) {
|
|
||||||
hitQueue.add(new int[]{row + 1, col});
|
|
||||||
}
|
|
||||||
if (col > 0 && !alreadyShot(row, col - 1)) {
|
|
||||||
hitQueue.add(new int[]{row, col - 1});
|
|
||||||
}
|
|
||||||
if (col < gridSize - 1 && !alreadyShot(row, col + 1)) {
|
|
||||||
hitQueue.add(new int[]{row, col + 1});
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
}
|
|
@ -6,23 +6,19 @@ public class SpecificAiPlayerMedium extends AiPlayer{
|
||||||
private List<Point> hitsQueue = new ArrayList<>();
|
private List<Point> hitsQueue = new ArrayList<>();
|
||||||
|
|
||||||
public SpecificAiPlayerMedium() {
|
public SpecificAiPlayerMedium() {
|
||||||
super();
|
|
||||||
this.setName("AI Player Medium");
|
this.setName("AI Player Medium");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void aiShoot() {
|
public void AiShoot() {
|
||||||
Point nextShot = ComputeNextShot();
|
Point nextShot = ComputeNextShot();
|
||||||
// Shoot at the enemy and receive the hit response
|
// Shoot at the enemy and receive the hit response
|
||||||
enemy.receiveShoot(nextShot);
|
enemy.receiveShoot(nextShot);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
HitResponse hitResponse = enemy.board.getHitResponseOnPoint(nextShot);
|
||||||
public synchronized void receiveHit(HitResponse hitResponse) {
|
|
||||||
super.receiveHit(hitResponse);
|
|
||||||
// If it's a hit or sunk, add adjacent cells to the hitsQueue
|
// If it's a hit or sunk, add adjacent cells to the hitsQueue
|
||||||
if (hitResponse.getHitResponse() == HitResponseType.HIT) {
|
if (hitResponse.getHitResponse() == HitResponseType.HIT) {
|
||||||
addAdjacentPoints(hitResponse.getPoint());
|
addAdjacentPoints(nextShot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,9 +61,8 @@ public class SpecificAiPlayerMedium extends AiPlayer{
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean alreadyShot(Point p) {
|
private boolean alreadyShot(Point p) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
return this.enemy.board.getHitResponseOnPoint(p) != null;
|
throw new UnsupportedOperationException("Unimplemented method 'alreadyShot'");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isValidPoint(Point point) {
|
private boolean isValidPoint(Point point) {
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,7 @@ public class WinScreen extends JPanel {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
frame.showPanel("MainMenu");
|
frame.showPanel("MainMenu");
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
add(winLabel);
|
add(winLabel);
|
||||||
add(okButton);
|
add(okButton);
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Das startLocalGame Panel dient dem Erstellen eines lokalen Spiels.
|
* Das startLocalGame Panel dient dem Erstellen eines lokalen Spiels.
|
||||||
|
@ -45,12 +43,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.
|
||||||
|
@ -64,8 +62,7 @@ public class startLocalGame extends JPanel {
|
||||||
setLayout(null);
|
setLayout(null);
|
||||||
|
|
||||||
// Setze Komponentenpositionen
|
// Setze Komponentenpositionen
|
||||||
frameTitle.setBounds(20, 20, 500, 60);
|
frameTitle.setBounds(20, 20, 200, 30);
|
||||||
frameTitle.setFont(robotoFont.deriveFont(50f));
|
|
||||||
add(frameTitle);
|
add(frameTitle);
|
||||||
|
|
||||||
semesterLabel.setBounds(700, 300, 200, 30);
|
semesterLabel.setBounds(700, 300, 200, 30);
|
||||||
|
@ -87,6 +84,9 @@ public class startLocalGame extends JPanel {
|
||||||
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);
|
||||||
|
|
||||||
|
@ -195,61 +195,52 @@ public class startLocalGame extends JPanel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Um zum startLocalGameLoadingScreen zu wechseln und Daten an Backend weiterzureichen.
|
// Um zum Gameboard zu wechseln.
|
||||||
startButton.addActionListener(new ActionListener() {
|
testButton.addActionListener(new ActionListener() {
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
HashMap<ImageIcon, Class<? extends LocalPlayer>> playerClassMap = new HashMap<>();
|
frame.showPanelWin("WinPanel");
|
||||||
playerClassMap.put(humanPlayerIcon, HumanPlayer.class);
|
}
|
||||||
playerClassMap.put(aiPlayerEasyIcon, SpecificAiPlayerEasy.class);
|
});
|
||||||
playerClassMap.put(aiPlayerNormalIcon, SpecificAiPlayerMedium.class);
|
|
||||||
playerClassMap.put(aiPlayerHardIcon, SpecificAiPlayerHard.class);
|
|
||||||
|
|
||||||
|
|
||||||
|
// Um zum startLocalGameLoadingScreen zu wechseln und Daten an Backend weiterzureichen.
|
||||||
|
startButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
frame.showPanelSLGLS("startLocalGameLoadingScreen", semesterCounter); //TODO
|
frame.showPanelSLGLS("startLocalGameLoadingScreen", semesterCounter); //TODO
|
||||||
|
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {// TODO Wird name wirklich weitergegeben?
|
||||||
Class<? extends LocalPlayer> leftPlayerClass = playerClassMap.get(leftPlayerIcon.getIcon());
|
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||||
Class<? extends AiPlayer> rightPlayerClass = (Class<? extends AiPlayer>) playerClassMap.get(rightPlayerIcon.getIcon());
|
GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerEasy.class, GameController.semesterToBoardSize(semesterCounter));
|
||||||
GameController.startLocalGame(
|
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||||
leftPlayerClass, leftPlayerNickname,
|
GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerMedium.class, GameController.semesterToBoardSize(semesterCounter));
|
||||||
rightPlayerClass,
|
} else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||||
GameController.semesterToBoardSize(semesterCounter)
|
GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerHard.class, GameController.semesterToBoardSize(semesterCounter));
|
||||||
);
|
}
|
||||||
|
} else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||||
// if (leftPlayerIcon.getIcon() == humanPlayerIcon) {// TODO Wird name wirklich weitergegeben?
|
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||||
// if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerEasy.class, GameController.semesterToBoardSize(semesterCounter));
|
||||||
// GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerEasy.class, GameController.semesterToBoardSize(semesterCounter));
|
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerMedium.class, GameController.semesterToBoardSize(semesterCounter));
|
||||||
// GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerMedium.class, GameController.semesterToBoardSize(semesterCounter));
|
} else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerHard.class, GameController.semesterToBoardSize(semesterCounter));
|
||||||
// GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerHard.class, GameController.semesterToBoardSize(semesterCounter));
|
}
|
||||||
// }
|
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||||
// } else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||||
// if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerEasy.class, GameController.semesterToBoardSize(semesterCounter));
|
||||||
// GameController.startLocalGame(SpecificAiPlayerEasy.class, leftPlayerNickname, SpecificAiPlayerEasy.class, GameController.semesterToBoardSize(semesterCounter));
|
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerMedium.class, GameController.semesterToBoardSize(semesterCounter));
|
||||||
// GameController.startLocalGame(SpecificAiPlayerEasy.class, leftPlayerNickname, SpecificAiPlayerMedium.class, GameController.semesterToBoardSize(semesterCounter));
|
} else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerHard.class, GameController.semesterToBoardSize(semesterCounter));
|
||||||
// GameController.startLocalGame(SpecificAiPlayerEasy.class, leftPlayerNickname, SpecificAiPlayerHard.class, GameController.semesterToBoardSize(semesterCounter));
|
}
|
||||||
// }
|
} else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||||
// if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerEasy.class, GameController.semesterToBoardSize(semesterCounter));
|
||||||
// GameController.startLocalGame(SpecificAiPlayerMedium.class, leftPlayerNickname, SpecificAiPlayerEasy.class, GameController.semesterToBoardSize(semesterCounter));
|
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerMedium.class, GameController.semesterToBoardSize(semesterCounter));
|
||||||
// GameController.startLocalGame(SpecificAiPlayerMedium.class, leftPlayerNickname, SpecificAiPlayerMedium.class, GameController.semesterToBoardSize(semesterCounter));
|
} else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerHard.class, GameController.semesterToBoardSize(semesterCounter));
|
||||||
// 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));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
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;
|
||||||
|
|
||||||
|
@ -40,14 +39,12 @@ 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, Lucas Bronson
|
* @author Joshua Kuklok
|
||||||
*/
|
*/
|
||||||
startMultiplayerGame(MainFrame frame) {
|
startMultiplayerGame(MainFrame frame) {
|
||||||
|
|
||||||
|
@ -55,8 +52,7 @@ public class startMultiplayerGame extends JPanel {
|
||||||
setLayout(null);
|
setLayout(null);
|
||||||
|
|
||||||
// Setze Komponentenpositionen
|
// Setze Komponentenpositionen
|
||||||
frameTitle.setBounds(20, 20, 500, 60);
|
frameTitle.setBounds(20, 20, 200, 30);
|
||||||
frameTitle.setFont(robotoFont.deriveFont(50f));
|
|
||||||
add(frameTitle);
|
add(frameTitle);
|
||||||
|
|
||||||
semesterLabel.setBounds(700, 300, 200, 30);
|
semesterLabel.setBounds(700, 300, 200, 30);
|
||||||
|
|
Loading…
Reference in New Issue