Compare commits
2 Commits
016ef2a317
...
fe942ab660
Author | SHA1 | Date |
---|---|---|
|
fe942ab660 | |
|
15d5a67c38 |
|
@ -2,10 +2,11 @@ public class HalloSchiffeVersenken {
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) throws InterruptedException {
|
||||||
//LUCAS CODE
|
//LUCAS CODE
|
||||||
|
/*
|
||||||
MainMenuModel model = new MainMenuModel();
|
MainMenuModel model = new MainMenuModel();
|
||||||
MainMenuView view = new MainMenuView();
|
MainMenuView view = new MainMenuView();
|
||||||
MainMenuController controller = new MainMenuController(model, view);
|
MainMenuController controller = new MainMenuController(model, view);
|
||||||
|
*/
|
||||||
|
|
||||||
//System.out.println("HelloSchiffeVersenekn");
|
//System.out.println("HelloSchiffeVersenekn");
|
||||||
|
|
||||||
|
@ -21,6 +22,7 @@ public class HalloSchiffeVersenken {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//JOSHUA CODE
|
//JOSHUA CODE
|
||||||
startLocalGame huso = new startLocalGame();
|
//startLocalGame localTest = new startLocalGame();
|
||||||
|
//startMultiplayerGame multiplayerTest = new startMultiplayerGame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,24 @@ import javax.swing.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
/*
|
||||||
|
TODO:
|
||||||
|
Back Button führt ins vorherige Fenster
|
||||||
|
Start geht ins nächste Fenster
|
||||||
|
Gebrauchte Attribute werden übergeben (Semester Spielername etc.)
|
||||||
|
Klasse mit Controller aufteilen
|
||||||
|
*/
|
||||||
|
|
||||||
public class startLocalGame {
|
public class startLocalGame {
|
||||||
// Funktionshilfen
|
// Funktionshilfen
|
||||||
int semesterCounter = 1; // Semester Counter Label
|
int semesterCounter = 1; // Semester Counter Label
|
||||||
|
String leftPlayerNickname = "Spieler 1";
|
||||||
|
String rightPlayerNickname = "Spieler 2";
|
||||||
|
|
||||||
// Grafiken
|
// Grafiken
|
||||||
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
|
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
|
||||||
ImageIcon humanPlayerIcon = new ImageIcon("graphics/humanPlayer.png");
|
ImageIcon humanPlayerIcon = new ImageIcon("graphics/humanPlayer.png");
|
||||||
ImageIcon aiPlayerIcon = new ImageIcon("graphics/aiPlayer.png");
|
ImageIcon aiPlayerIcon = new ImageIcon("graphics/aiPlayer.png");
|
||||||
//Lustiger Test
|
|
||||||
//System.out.println("!");
|
|
||||||
|
|
||||||
// Frame
|
// Frame
|
||||||
JFrame frame = new JFrame("Lokales Spiel");
|
JFrame frame = new JFrame("Lokales Spiel");
|
||||||
|
@ -38,6 +46,7 @@ public class startLocalGame {
|
||||||
// Textfelder
|
// Textfelder
|
||||||
JTextField leftPlayerTextField = new JTextField(20);
|
JTextField leftPlayerTextField = new JTextField(20);
|
||||||
JTextField rightPlayerTextField = new JTextField(20);
|
JTextField rightPlayerTextField = new JTextField(20);
|
||||||
|
|
||||||
startLocalGame() {
|
startLocalGame() {
|
||||||
// Erstelle Frame
|
// Erstelle Frame
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
@ -102,6 +111,20 @@ public class startLocalGame {
|
||||||
frame.add(rightPlayerTextField);
|
frame.add(rightPlayerTextField);
|
||||||
|
|
||||||
// ActionListener für die Buttons
|
// ActionListener für die Buttons
|
||||||
|
|
||||||
|
//ZUSATZ
|
||||||
|
leftPlayerTextField.setText(leftPlayerNickname);
|
||||||
|
rightPlayerTextField.setText(rightPlayerNickname);
|
||||||
|
|
||||||
|
// STARTBUTTON
|
||||||
|
startButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
startMultiplayerGame huso = new startMultiplayerGame();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// SEMESTERBUTTONS
|
||||||
semesterUpButton.addActionListener(new ActionListener() {
|
semesterUpButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
@ -122,6 +145,80 @@ public class startLocalGame {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// PLAYERTOGGLEBUTTONS
|
||||||
|
|
||||||
|
leftPlayerLeftButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
toggleLeftPlayerIcon();
|
||||||
|
updateTextFields();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
leftPlayerRightButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
toggleLeftPlayerIcon();
|
||||||
|
updateTextFields();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
rightPlayerLeftButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
toggleRightPlayerIcon();
|
||||||
|
updateTextFields();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
rightPlayerRightButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
toggleRightPlayerIcon();
|
||||||
|
updateTextFields();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
frame.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TOGGLE METHODEN
|
||||||
|
// TODO Müssen evtl vergrößert werden je nach schwierigkeitsgraden
|
||||||
|
// dazu evt. übergabeparameter für links rechts gedrückt
|
||||||
|
private void toggleLeftPlayerIcon() {
|
||||||
|
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
|
||||||
|
leftPlayerIcon.setIcon(aiPlayerIcon);
|
||||||
|
} else {
|
||||||
|
leftPlayerIcon.setIcon(humanPlayerIcon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void toggleRightPlayerIcon() {
|
||||||
|
if (rightPlayerIcon.getIcon() == humanPlayerIcon) {
|
||||||
|
rightPlayerIcon.setIcon(aiPlayerIcon);
|
||||||
|
} else {
|
||||||
|
rightPlayerIcon.setIcon(humanPlayerIcon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Methode zum Aktualisieren der Textfelder basierend auf den ausgewählten Icons
|
||||||
|
private void updateTextFields() {
|
||||||
|
// Linker Spieler
|
||||||
|
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
|
||||||
|
leftPlayerTextField.setText(leftPlayerNickname);
|
||||||
|
} else {
|
||||||
|
leftPlayerTextField.setText("Leicht");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rechter Spieler
|
||||||
|
if (rightPlayerIcon.getIcon() == humanPlayerIcon) {
|
||||||
|
rightPlayerTextField.setText(rightPlayerNickname);
|
||||||
|
} else {
|
||||||
|
rightPlayerTextField.setText("Leicht");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* POTENTIELL VERALTET
|
||||||
leftPlayerLeftButton.addActionListener(new ActionListener() {
|
leftPlayerLeftButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
@ -171,5 +268,6 @@ public class startLocalGame {
|
||||||
});
|
});
|
||||||
|
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,215 @@
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
/*
|
||||||
|
TODO:
|
||||||
|
Back Button führt ins vorherige Fenster
|
||||||
|
Spiel erstellen/beitreten geht ins nächste Fenster
|
||||||
|
Gebrauchte Attribute werden übergeben (Semester Spielername etc.)
|
||||||
|
Klasse mit Controller aufteilen
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class startMultiplayerGame {
|
||||||
|
// Funktionshilfen
|
||||||
|
int semesterCounter = 1; // Semester Counter Label
|
||||||
|
String PlayerNickname = "Spieler 1";
|
||||||
|
|
||||||
|
// Grafiken
|
||||||
|
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
|
||||||
|
ImageIcon humanPlayerIcon = new ImageIcon("graphics/humanPlayer.png");
|
||||||
|
ImageIcon aiPlayerIcon = new ImageIcon("graphics/aiPlayer.png");
|
||||||
|
|
||||||
|
// Frame
|
||||||
|
JFrame frame = new JFrame("Multiplayer Spiel");
|
||||||
|
|
||||||
|
// Labels
|
||||||
|
JLabel frameTitle = new JLabel("Multiplayer Spiel");
|
||||||
|
JLabel semesterlable = new JLabel("Semester");
|
||||||
|
JLabel PlayerName = new JLabel("Name");
|
||||||
|
JLabel PlayerIcon = new JLabel(humanPlayerIcon);
|
||||||
|
JLabel semesterCounterLabel = new JLabel(String.valueOf(semesterCounter));
|
||||||
|
|
||||||
|
// Buttons
|
||||||
|
JButton backButton = new JButton(backButtonIcon);
|
||||||
|
JButton PlayerLeftButton = new JButton("<-");
|
||||||
|
JButton PlayerRightButton = new JButton("->");
|
||||||
|
JButton semesterUpButton = new JButton("^");
|
||||||
|
JButton semesterDownButton = new JButton("v");
|
||||||
|
JButton createGameButton = new JButton("Spiel erstellen");
|
||||||
|
JButton joinGameButton = new JButton("Spiel beitreten");
|
||||||
|
|
||||||
|
// Textfelder
|
||||||
|
JTextField PlayerTextField = new JTextField(20);
|
||||||
|
|
||||||
|
startMultiplayerGame() {
|
||||||
|
// Erstelle Frame
|
||||||
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
frame.setSize(1500, 1000);
|
||||||
|
|
||||||
|
// Layout Manager (absolute ositionierung)
|
||||||
|
frame.setLayout(null);
|
||||||
|
|
||||||
|
// Erstelle Label
|
||||||
|
frameTitle.setBounds(20, 20, 200, 30);
|
||||||
|
frame.add(frameTitle);
|
||||||
|
|
||||||
|
semesterlable.setBounds(700, 300, 200, 30);
|
||||||
|
frame.add(semesterlable);
|
||||||
|
|
||||||
|
PlayerName.setBounds(50, 625, 200, 30);
|
||||||
|
frame.add(PlayerName);
|
||||||
|
|
||||||
|
PlayerIcon.setBounds(75, 400, 200, 128);
|
||||||
|
frame.add(PlayerIcon);
|
||||||
|
|
||||||
|
semesterCounterLabel.setBounds(725, 475, 50, 50); // zwischen den Up/Down-Buttons
|
||||||
|
semesterCounterLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
|
frame.add(semesterCounterLabel);
|
||||||
|
|
||||||
|
// Erstellt Buttons
|
||||||
|
backButton.setBounds(1380, 20, 80, 80);
|
||||||
|
frame.add(backButton);
|
||||||
|
|
||||||
|
PlayerLeftButton.setBounds(50, 450, 50, 50);
|
||||||
|
frame.add(PlayerLeftButton);
|
||||||
|
|
||||||
|
PlayerRightButton.setBounds(250, 450, 50, 50);
|
||||||
|
frame.add(PlayerRightButton);
|
||||||
|
|
||||||
|
semesterUpButton.setBounds(725, 400, 50, 50);
|
||||||
|
frame.add(semesterUpButton);
|
||||||
|
|
||||||
|
semesterDownButton.setBounds(725, 550, 50, 50);
|
||||||
|
frame.add(semesterDownButton);
|
||||||
|
|
||||||
|
joinGameButton.setBounds(1100, 350, 200, 50);
|
||||||
|
frame.add(joinGameButton);
|
||||||
|
|
||||||
|
createGameButton.setBounds(1100, 550, 200, 50);
|
||||||
|
frame.add(createGameButton);
|
||||||
|
|
||||||
|
// Erstellt Textfelder
|
||||||
|
PlayerTextField.setBounds(50, 650, 250, 50);
|
||||||
|
frame.add(PlayerTextField);
|
||||||
|
|
||||||
|
//ZUSATZ
|
||||||
|
PlayerTextField.setText(PlayerNickname);
|
||||||
|
|
||||||
|
// ActionListener für die Buttons
|
||||||
|
// SEMESTERBUTTONS
|
||||||
|
semesterUpButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (semesterCounter < 6) {
|
||||||
|
semesterCounter++;
|
||||||
|
semesterCounterLabel.setText(String.valueOf(semesterCounter));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
semesterDownButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (semesterCounter > 1) { // Verhindert, dass der Wert unter 1 fällt
|
||||||
|
semesterCounter--;
|
||||||
|
semesterCounterLabel.setText(String.valueOf(semesterCounter));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// PLAYERTOGGLEBUTTONS
|
||||||
|
|
||||||
|
PlayerLeftButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
toggleLeftPlayerIcon();
|
||||||
|
updateTextFields();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
PlayerRightButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
toggleLeftPlayerIcon();
|
||||||
|
updateTextFields();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
frame.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TOGGLE METHODEN
|
||||||
|
// TODO Müssen evtl vergrößert werden je nach schwierigkeitsgraden
|
||||||
|
// dazu evt. übergabeparameter für links rechts gedrückt
|
||||||
|
private void toggleLeftPlayerIcon() {
|
||||||
|
if (PlayerIcon.getIcon() == humanPlayerIcon) {
|
||||||
|
PlayerIcon.setIcon(aiPlayerIcon);
|
||||||
|
} else {
|
||||||
|
PlayerIcon.setIcon(humanPlayerIcon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateTextFields() {
|
||||||
|
// Linker Spieler
|
||||||
|
if (PlayerIcon.getIcon() == humanPlayerIcon) {
|
||||||
|
PlayerTextField.setText(PlayerNickname);
|
||||||
|
} else {
|
||||||
|
PlayerTextField.setText("Leicht");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* POTENTIELL VERALTET
|
||||||
|
leftPlayerLeftButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png");
|
||||||
|
if(leftPlayerIcon.getIcon()==humanPlayerIcon) {
|
||||||
|
leftPlayerIcon.setIcon(aiPlayerIcon);
|
||||||
|
}else{
|
||||||
|
leftPlayerIcon.setIcon(humanPlayerIcon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
leftPlayerRightButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png");
|
||||||
|
if(leftPlayerIcon.getIcon()==humanPlayerIcon) {
|
||||||
|
leftPlayerIcon.setIcon(aiPlayerIcon);
|
||||||
|
}else{
|
||||||
|
leftPlayerIcon.setIcon(humanPlayerIcon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
rightPlayerLeftButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png");
|
||||||
|
if(rightPlayerIcon.getIcon()==humanPlayerIcon) {
|
||||||
|
rightPlayerIcon.setIcon(aiPlayerIcon);
|
||||||
|
}else{
|
||||||
|
rightPlayerIcon.setIcon(humanPlayerIcon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
rightPlayerRightButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png");
|
||||||
|
if(rightPlayerIcon.getIcon()==humanPlayerIcon) {
|
||||||
|
rightPlayerIcon.setIcon(aiPlayerIcon);
|
||||||
|
}else{
|
||||||
|
rightPlayerIcon.setIcon(humanPlayerIcon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
frame.setVisible(true);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue