Compare commits
10 Commits
e27b852c14
...
4dd1c9b39b
Author | SHA1 | Date |
---|---|---|
|
4dd1c9b39b | |
|
bfb25dfe2c | |
|
3370975e57 | |
|
f4cf28f4bf | |
|
7ef04711c3 | |
|
fdd2e6d2f1 | |
|
31e4d91baf | |
|
3c03e63899 | |
|
f7d2e14196 | |
|
8e4a516e2c |
|
@ -1,9 +1,16 @@
|
|||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class AiPlayer extends LocalPlayer {
|
||||
|
||||
public abstract class AiPlayer extends LocalPlayer implements Runnable {
|
||||
|
||||
List<Thread> shootThreads;
|
||||
|
||||
public AiPlayer() {
|
||||
this.setName("AI Player");
|
||||
this.shootThreads = new ArrayList<>();
|
||||
}
|
||||
public Point RandomPoint() {
|
||||
Random random = new Random(); // Pseudo Random für zufallszahlen
|
||||
|
@ -12,7 +19,14 @@ public abstract class AiPlayer extends LocalPlayer {
|
|||
return new Point(posx,posy);
|
||||
}
|
||||
|
||||
public void AiSetShips() {
|
||||
@Override
|
||||
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
|
||||
//TODO: set horizontal
|
||||
while(!super.board.getShips().get(i).setPosition(RandomPoint(), true, super.board.getShips(), super.board.getSize())) {}
|
||||
|
@ -20,8 +34,63 @@ public abstract class AiPlayer extends LocalPlayer {
|
|||
return;
|
||||
}
|
||||
|
||||
public void AiShoot() {
|
||||
super.board.hit(RandomPoint());
|
||||
public void aiShoot() {
|
||||
this.enemy.receiveShoot(RandomPoint());
|
||||
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,6 +40,7 @@ public class GameBoard extends JPanel {
|
|||
// Buttons
|
||||
JButton giveUpButton = new JButton("Aufgeben");
|
||||
|
||||
|
||||
/**
|
||||
* Konstruktor von GameBoard.
|
||||
* @param frame Der Mainframe der Anwendung über den alle Panels angezeigt werden.
|
||||
|
@ -136,7 +137,6 @@ public class GameBoard extends JPanel {
|
|||
opponentBoardPanel.addShipButton(shipButton);
|
||||
shipButton.setEnabled(false);
|
||||
}
|
||||
|
||||
JToggleButton readyButton = new JToggleButton("Bereit");
|
||||
readyButton.setBackground(Color.GREEN);
|
||||
rightButtonsPanel.add(readyButton);
|
||||
|
@ -159,6 +159,10 @@ public class GameBoard extends JPanel {
|
|||
kontextText.setText(kT2);
|
||||
p1.ready();
|
||||
if(true) {
|
||||
remove(readyButton);
|
||||
remove(resetButton);
|
||||
remove(rightButtonsPanel);
|
||||
remove(leftButtonsPanel);
|
||||
readyButton.setEnabled(false);
|
||||
resetButton.setEnabled(false);
|
||||
}
|
||||
|
@ -212,4 +216,14 @@ public class GameBoard extends JPanel {
|
|||
this.ownBoardPanel.refresh();
|
||||
this.opponentBoardPanel.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter für Player1
|
||||
* @return Player 1
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public Player getP1() {
|
||||
return p1;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -160,12 +160,16 @@ public class GameController {
|
|||
throw new RuntimeException("Unable to instantiate players");
|
||||
}
|
||||
|
||||
localPlayer.createBoard(size);
|
||||
aiPlayer.createBoard(size);
|
||||
localPlayer.isServer = true;
|
||||
aiPlayer.isServer = false;
|
||||
|
||||
|
||||
localPlayer.setEnemy(aiPlayer);
|
||||
aiPlayer.setEnemy(localPlayer);
|
||||
|
||||
localPlayer.createBoard(size);
|
||||
aiPlayer.createBoard(size);
|
||||
|
||||
localPlayer.setName(localPlayerName);
|
||||
|
||||
startGameWithInstancedPlayers(localPlayer, aiPlayer, size);
|
||||
|
|
|
@ -22,7 +22,7 @@ public class LocalPlayer extends Player {
|
|||
switch (hitResponse.getType()) {
|
||||
case HIT, SUNK -> this.myTurn = false;
|
||||
case MISS -> this.myTurn = true;
|
||||
case VICTORY -> System.out.println("Game Over"); //TODO Was halt bei victory passiert ist hier wurder verloheren
|
||||
case VICTORY -> GameController.getMainFrame().showPanelLose("", this); //TODO Was halt bei victory passiert ist hier wurder verloheren
|
||||
}
|
||||
GameController.getMainFrame().refreshGameBoard();
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public class LocalPlayer extends Player {
|
|||
switch (hitResponse.getType()) {
|
||||
case HIT, SUNK -> this.myTurn = true;
|
||||
case MISS -> this.myTurn = false;
|
||||
case VICTORY -> System.out.println("Win"); // TODO was halt beim victory passier ist hier wurde gewonnen
|
||||
case VICTORY -> GameController.getMainFrame().showPanelWin("", this); // TODO was halt beim victory passier ist hier wurde gewonnen
|
||||
}
|
||||
GameController.getMainFrame().refreshGameBoard();
|
||||
}
|
||||
|
|
|
@ -1,22 +1,24 @@
|
|||
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
|
||||
*/
|
||||
public class LooseScreen extends JPanel {
|
||||
JLabel looseLabel = new JLabel("Du hast Verloren");
|
||||
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 LooseScreen Klasse
|
||||
* Konstruktor der LoseScreen Klasse
|
||||
* @param frame Der Mainframe der Anwendung über den alle Panels angezeigt werden.
|
||||
* @author Lucas Bronson
|
||||
*/
|
||||
public LooseScreen(MainFrame frame) {
|
||||
setLayout(new BorderLayout());
|
||||
public LoseScreen(MainFrame frame) {
|
||||
setLayout(null);
|
||||
buildPanel(frame);
|
||||
}
|
||||
|
||||
|
@ -26,9 +28,17 @@ public class LooseScreen extends JPanel {
|
|||
* @author Lucas Bronson
|
||||
*/
|
||||
public void buildPanel(MainFrame frame) {
|
||||
add(looseLabel);
|
||||
add(loseLabel);
|
||||
okButton.setBounds(650,525,200,50);
|
||||
looseLabel.setBounds(500,450,500,50);
|
||||
looseLabel.setFont(robotoFont);
|
||||
loseLabel.setBounds(550,450,500,50);
|
||||
loseLabel.setFont(robotoFont);
|
||||
okButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
frame.showPanel("MainMenu");
|
||||
}
|
||||
});
|
||||
add(loseLabel);
|
||||
add(okButton);
|
||||
}
|
||||
}
|
|
@ -127,9 +127,13 @@ public class MainFrame extends JFrame {
|
|||
/**
|
||||
* Spezifische ShowPanel für WinScreen Klasse
|
||||
* @param panelName Name des anzuzeigenden Panels
|
||||
* @author Lucas Bronson
|
||||
* @param player Player von dem die funktion aufgerufen worden ist
|
||||
* @author Lucas Bronson, Peer Ole Wachtel
|
||||
*/
|
||||
public void showPanelWin(String panelName){
|
||||
public void showPanelWin(String panelName, Player player){
|
||||
if(player != gameBoard.getP1()){
|
||||
return;
|
||||
}
|
||||
WinScreen winScreen = new WinScreen(this);
|
||||
mainPanel.add(winScreen, panelName);
|
||||
mainPanel.revalidate();
|
||||
|
@ -140,10 +144,14 @@ public class MainFrame extends JFrame {
|
|||
/**
|
||||
* Spezifische ShowPanel für LooseScreen Klasse
|
||||
* @param panelName Name des anzuzeigenden Panels
|
||||
* @author Lucas Bronson
|
||||
* @param player Player von dem die funktion aufgerufen worden ist
|
||||
* @author Lucas Bronson, Peer Ole Wachtel
|
||||
*/
|
||||
public void showPanelLoose(String panelName){
|
||||
LooseScreen looseScreen = new LooseScreen(this);
|
||||
public void showPanelLose(String panelName, Player player){
|
||||
if(player != gameBoard.getP1()){
|
||||
return;
|
||||
}
|
||||
LoseScreen looseScreen = new LoseScreen(this);
|
||||
mainPanel.add(looseScreen,panelName);
|
||||
mainPanel.revalidate();
|
||||
mainPanel.repaint();
|
||||
|
@ -155,6 +163,9 @@ public class MainFrame extends JFrame {
|
|||
* @author Luca Conte
|
||||
*/
|
||||
public void refreshGameBoard() {
|
||||
if(this.gameBoard == null) {
|
||||
return;
|
||||
}
|
||||
this.gameBoard.refresh();
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ import java.io.FileInputStream;
|
|||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
@ -48,12 +49,14 @@ public class SoundHandler {
|
|||
thread.start();
|
||||
runningThreads.add(thread);
|
||||
}
|
||||
for (Thread oldThread : runningThreads) {
|
||||
Iterator<Thread> i = runningThreads.iterator();
|
||||
while (i.hasNext()) {
|
||||
Thread oldThread = i.next();
|
||||
if (!oldThread.isAlive()) {
|
||||
|
||||
try {
|
||||
oldThread.join();
|
||||
runningThreads.remove(oldThread);
|
||||
i.remove();
|
||||
System.out.println("cleared thread");
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
|
||||
public class SpecificAiPlayerEasy extends AiPlayer{
|
||||
|
||||
public SpecificAiPlayerEasy() {
|
||||
super();
|
||||
this.setName("AI Player Easy");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,3 +1,125 @@
|
|||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
public class SpecificAiPlayerHard extends AiPlayer{
|
||||
|
||||
private int gridSize;
|
||||
private boolean[][] shotsFired;
|
||||
private final ArrayList<Point> hitQueue;
|
||||
private final Random random;
|
||||
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,19 +6,23 @@ public class SpecificAiPlayerMedium extends AiPlayer{
|
|||
private List<Point> hitsQueue = new ArrayList<>();
|
||||
|
||||
public SpecificAiPlayerMedium() {
|
||||
super();
|
||||
this.setName("AI Player Medium");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void AiShoot() {
|
||||
public void aiShoot() {
|
||||
Point nextShot = ComputeNextShot();
|
||||
// Shoot at the enemy and receive the hit response
|
||||
enemy.receiveShoot(nextShot);
|
||||
}
|
||||
|
||||
HitResponse hitResponse = enemy.board.getHitResponseOnPoint(nextShot);
|
||||
@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(nextShot);
|
||||
addAdjacentPoints(hitResponse.getPoint());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,8 +65,9 @@ public class SpecificAiPlayerMedium extends AiPlayer{
|
|||
}
|
||||
|
||||
private boolean alreadyShot(Point p) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'alreadyShot'");
|
||||
|
||||
return this.enemy.board.getHitResponseOnPoint(p) != null;
|
||||
|
||||
}
|
||||
|
||||
private boolean isValidPoint(Point point) {
|
||||
|
|
|
@ -7,7 +7,7 @@ import java.awt.*;
|
|||
*/
|
||||
public class Verbinden extends JPanel{
|
||||
|
||||
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
|
||||
//ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
|
||||
|
||||
JLabel verbindenLabel = new JLabel("Verbinde . . .",SwingConstants.CENTER);
|
||||
|
||||
|
|
|
@ -56,7 +56,6 @@ public class WinScreen extends JPanel {
|
|||
public void actionPerformed(ActionEvent e) {
|
||||
frame.showPanel("MainMenu");
|
||||
}
|
||||
|
||||
});
|
||||
add(winLabel);
|
||||
add(okButton);
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Das startLocalGame Panel dient dem Erstellen eines lokalen Spiels.
|
||||
|
@ -43,12 +45,12 @@ public class startLocalGame extends JPanel {
|
|||
JButton rightPlayerLeftButton = new JButton("<-");
|
||||
JButton rightPlayerRightButton = new JButton("->");
|
||||
JButton startButton = new JButton("Start!");
|
||||
JButton testButton = new JButton("Test");
|
||||
|
||||
// Textfelder
|
||||
JTextField leftPlayerTextField = new JTextField(20);
|
||||
JTextField rightPlayerTextField = new JTextField(20);
|
||||
|
||||
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
|
||||
/**
|
||||
* Konstruktor der startLocalGame.
|
||||
* Fügt Buttons, Textfelder und Label hinzu.
|
||||
|
@ -62,7 +64,8 @@ public class startLocalGame extends JPanel {
|
|||
setLayout(null);
|
||||
|
||||
// Setze Komponentenpositionen
|
||||
frameTitle.setBounds(20, 20, 200, 30);
|
||||
frameTitle.setBounds(20, 20, 500, 60);
|
||||
frameTitle.setFont(robotoFont.deriveFont(50f));
|
||||
add(frameTitle);
|
||||
|
||||
semesterLabel.setBounds(700, 300, 200, 30);
|
||||
|
@ -84,9 +87,6 @@ public class startLocalGame extends JPanel {
|
|||
semesterCounterLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
add(semesterCounterLabel);
|
||||
|
||||
testButton.setBounds(500,800,50,50);
|
||||
add(testButton);
|
||||
|
||||
backButton.setBounds(1380, 20, 80, 80);
|
||||
add(backButton);
|
||||
|
||||
|
@ -195,52 +195,61 @@ public class startLocalGame extends JPanel {
|
|||
}
|
||||
});
|
||||
|
||||
// Um zum Gameboard zu wechseln.
|
||||
testButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
frame.showPanelWin("WinPanel");
|
||||
}
|
||||
});
|
||||
|
||||
// Um zum startLocalGameLoadingScreen zu wechseln und Daten an Backend weiterzureichen.
|
||||
startButton.addActionListener(new ActionListener() {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
HashMap<ImageIcon, Class<? extends LocalPlayer>> playerClassMap = new HashMap<>();
|
||||
playerClassMap.put(humanPlayerIcon, HumanPlayer.class);
|
||||
playerClassMap.put(aiPlayerEasyIcon, SpecificAiPlayerEasy.class);
|
||||
playerClassMap.put(aiPlayerNormalIcon, SpecificAiPlayerMedium.class);
|
||||
playerClassMap.put(aiPlayerHardIcon, SpecificAiPlayerHard.class);
|
||||
|
||||
|
||||
frame.showPanelSLGLS("startLocalGameLoadingScreen", semesterCounter); //TODO
|
||||
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(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 (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||
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 (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
Class<? extends LocalPlayer> leftPlayerClass = playerClassMap.get(leftPlayerIcon.getIcon());
|
||||
Class<? extends AiPlayer> rightPlayerClass = (Class<? extends AiPlayer>) playerClassMap.get(rightPlayerIcon.getIcon());
|
||||
GameController.startLocalGame(
|
||||
leftPlayerClass, leftPlayerNickname,
|
||||
rightPlayerClass,
|
||||
GameController.semesterToBoardSize(semesterCounter)
|
||||
);
|
||||
|
||||
// if (leftPlayerIcon.getIcon() == humanPlayerIcon) {// TODO Wird name wirklich weitergegeben?
|
||||
// if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||
// GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerEasy.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||
// GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerMedium.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||
// GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerHard.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
// }
|
||||
// } else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||
// if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||
// GameController.startLocalGame(SpecificAiPlayerEasy.class, leftPlayerNickname, SpecificAiPlayerEasy.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||
// GameController.startLocalGame(SpecificAiPlayerEasy.class, leftPlayerNickname, SpecificAiPlayerMedium.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||
// GameController.startLocalGame(SpecificAiPlayerEasy.class, leftPlayerNickname, SpecificAiPlayerHard.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
// }
|
||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||
// if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||
// GameController.startLocalGame(SpecificAiPlayerMedium.class, leftPlayerNickname, SpecificAiPlayerEasy.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||
// GameController.startLocalGame(SpecificAiPlayerMedium.class, leftPlayerNickname, SpecificAiPlayerMedium.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||
// GameController.startLocalGame(SpecificAiPlayerMedium.class, leftPlayerNickname, SpecificAiPlayerHard.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
// }
|
||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||
// if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||
// GameController.startLocalGame(SpecificAiPlayerHard.class, leftPlayerNickname, SpecificAiPlayerEasy.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||
// GameController.startLocalGame(SpecificAiPlayerHard.class, leftPlayerNickname, SpecificAiPlayerMedium.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
// } else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||
// GameController.startLocalGame(SpecificAiPlayerHard.class, leftPlayerNickname, SpecificAiPlayerHard.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
|
@ -39,12 +40,14 @@ public class startMultiplayerGame extends JPanel {
|
|||
// Textfelder
|
||||
JTextField PlayerTextField = new JTextField(20);
|
||||
|
||||
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
|
||||
|
||||
/**
|
||||
* Konstruktor der startLocalGame.
|
||||
* Fügt Buttons, Textfelder und Label hinzu.
|
||||
* Fügt ebenfalls ActionListeners hinzu, damit Buttons etc. ihre gewünschte Funktion haben
|
||||
* @param frame Der Mainframe der Anwendung über den alle Panels angezeigt werden.
|
||||
* @author Joshua Kuklok
|
||||
* @author Joshua Kuklok, Lucas Bronson
|
||||
*/
|
||||
startMultiplayerGame(MainFrame frame) {
|
||||
|
||||
|
@ -52,7 +55,8 @@ public class startMultiplayerGame extends JPanel {
|
|||
setLayout(null);
|
||||
|
||||
// Setze Komponentenpositionen
|
||||
frameTitle.setBounds(20, 20, 200, 30);
|
||||
frameTitle.setBounds(20, 20, 500, 60);
|
||||
frameTitle.setFont(robotoFont.deriveFont(50f));
|
||||
add(frameTitle);
|
||||
|
||||
semesterLabel.setBounds(700, 300, 200, 30);
|
||||
|
|
Loading…
Reference in New Issue