Continued work on startLocalGame and started work startMultiplayerGame
This commit is contained in:
parent
15d5a67c38
commit
fe942ab660
|
@ -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