Added Comments to MainFrame,

Fixed functionality of left/right buttons after adding more difficulties in startLocalGame and startMultiplayerGame
This commit is contained in:
Joshua 2024-12-04 11:51:00 +01:00
parent 7ee0f9c097
commit 15ff3034d3
3 changed files with 69 additions and 18 deletions

View File

@ -11,7 +11,8 @@ public class MainFrame extends JFrame {
// Von startMultiplayerGame an JoinGame
int localMult;
// Von startLocalGame an GameBoard
// Von startLocalGame an startLocalGameLoadingScreen
// Von startLocalGameLoadingScreen an GameBoard
int semesterCounter;
// ---------- //

View File

@ -2,6 +2,10 @@ import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
// TODO
// Evtl. ist Namen selber setzten noch unmöglich
//
public class startLocalGame extends JPanel {
// Player
//Player p1;
@ -118,7 +122,7 @@ public class startLocalGame extends JPanel {
leftPlayerLeftButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
toggleLeftPlayerIcon();
toggleLeftPlayerIconLeft();
updateTextFields();
}
});
@ -126,7 +130,7 @@ public class startLocalGame extends JPanel {
leftPlayerRightButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
toggleLeftPlayerIcon();
toggleLeftPlayerIconRight();
updateTextFields();
}
});
@ -134,7 +138,7 @@ public class startLocalGame extends JPanel {
rightPlayerLeftButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
toggleRightPlayerIcon();
toggleRightPlayerIconLeft();
updateTextFields();
}
});
@ -142,7 +146,7 @@ public class startLocalGame extends JPanel {
rightPlayerRightButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
toggleRightPlayerIcon();
toggleRightPlayerIconRight();
updateTextFields();
}
});
@ -193,7 +197,19 @@ public class startLocalGame extends JPanel {
}
private void toggleLeftPlayerIcon() {
private void toggleLeftPlayerIconLeft() {
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
leftPlayerIcon.setIcon(aiPlayerHardIcon);
} else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon){
leftPlayerIcon.setIcon(humanPlayerIcon);
} else if (leftPlayerIcon.getIcon() == aiPlayerNormalIcon) {
leftPlayerIcon.setIcon(aiPlayerEasyIcon);
} else if (leftPlayerIcon.getIcon() == aiPlayerHardIcon) {
leftPlayerIcon.setIcon(aiPlayerNormalIcon);
}
}
private void toggleLeftPlayerIconRight() {
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
leftPlayerIcon.setIcon(aiPlayerEasyIcon);
} else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon){
@ -205,7 +221,17 @@ public class startLocalGame extends JPanel {
}
}
private void toggleRightPlayerIcon() {
private void toggleRightPlayerIconLeft() {
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
rightPlayerIcon.setIcon(aiPlayerHardIcon);
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon){
rightPlayerIcon.setIcon(aiPlayerEasyIcon);
} else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
rightPlayerIcon.setIcon(aiPlayerNormalIcon);
}
}
private void toggleRightPlayerIconRight() {
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
rightPlayerIcon.setIcon(aiPlayerNormalIcon);
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon){

View File

@ -1,6 +1,8 @@
import javax.swing.*;
import java.io.IOException;
import java.net.InetSocketAddress;
// TODO
// Evtl. ist Namen selber setzten noch unmöglich
//
public class startMultiplayerGame extends JPanel {
// Funktionshilfen
@ -9,7 +11,9 @@ public class startMultiplayerGame extends JPanel {
// Grafiken
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
ImageIcon humanPlayerIcon = new ImageIcon("graphics/humanPlayer.png");
ImageIcon aiPlayerIcon = new ImageIcon("graphics/aiPlayer.png");
ImageIcon aiPlayerEasyIcon = new ImageIcon("graphics/botPlayerEasy.png");
ImageIcon aiPlayerNormalIcon = new ImageIcon("graphics/botPlayerNormal.png");
ImageIcon aiPlayerHardIcon = new ImageIcon("graphics/botPlayerHard.png");
// Labels
JLabel frameTitle = new JLabel("Multiplayer Spiel");
@ -105,12 +109,12 @@ public class startMultiplayerGame extends JPanel {
// PLAYERTOGGLEBUTTONS
PlayerLeftButton.addActionListener(e -> {
toggleLeftPlayerIcon();
togglePlayerIconLeft();
updateTextFields();
});
PlayerRightButton.addActionListener(e -> {
toggleLeftPlayerIcon();
togglePlayerIconRight();
updateTextFields();
});
@ -122,19 +126,39 @@ public class startMultiplayerGame extends JPanel {
}
// TOGGLE METHODEN
private void toggleLeftPlayerIcon() {
private void togglePlayerIconLeft() {
if (PlayerIcon.getIcon() == humanPlayerIcon) {
PlayerIcon.setIcon(aiPlayerIcon);
} else {
PlayerIcon.setIcon(aiPlayerHardIcon);
} else if (PlayerIcon.getIcon() == aiPlayerEasyIcon){
PlayerIcon.setIcon(humanPlayerIcon);
} else if (PlayerIcon.getIcon() == aiPlayerNormalIcon) {
PlayerIcon.setIcon(aiPlayerEasyIcon);
} else if (PlayerIcon.getIcon() == aiPlayerHardIcon) {
PlayerIcon.setIcon(aiPlayerNormalIcon);
}
}
private void togglePlayerIconRight() {
if (PlayerIcon.getIcon() == humanPlayerIcon) {
PlayerIcon.setIcon(aiPlayerEasyIcon);
} else if (PlayerIcon.getIcon() == aiPlayerEasyIcon){
PlayerIcon.setIcon(aiPlayerNormalIcon);
} else if (PlayerIcon.getIcon() == aiPlayerNormalIcon) {
PlayerIcon.setIcon(aiPlayerHardIcon);
} else if (PlayerIcon.getIcon() == aiPlayerHardIcon) {
PlayerIcon.setIcon(humanPlayerIcon);
}
}
private void updateTextFields() {
if (PlayerIcon.getIcon() == humanPlayerIcon) {
PlayerTextField.setText(PlayerNickname);
} else {
PlayerTextField.setText("Leicht");
PlayerTextField.setText("Spieler 1");
} else if (PlayerIcon.getIcon() == aiPlayerEasyIcon){
PlayerTextField.setText("Einfach");
} else if (PlayerIcon.getIcon() == aiPlayerNormalIcon) {
PlayerTextField.setText("Mittel");
} else if (PlayerIcon.getIcon() == aiPlayerHardIcon) {
PlayerTextField.setText("Schwer");
}
}
}