From 15ff3034d377f23ccc0823b1a993b9dde86ea04c Mon Sep 17 00:00:00 2001 From: Joshua Date: Wed, 4 Dec 2024 11:51:00 +0100 Subject: [PATCH] Added Comments to MainFrame, Fixed functionality of left/right buttons after adding more difficulties in startLocalGame and startMultiplayerGame --- src/MainFrame.java | 3 ++- src/startLocalGame.java | 38 ++++++++++++++++++++++++----- src/startMultiplayerGame.java | 46 ++++++++++++++++++++++++++--------- 3 files changed, 69 insertions(+), 18 deletions(-) diff --git a/src/MainFrame.java b/src/MainFrame.java index eb308ce..9afa7d2 100644 --- a/src/MainFrame.java +++ b/src/MainFrame.java @@ -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; // ---------- // diff --git a/src/startLocalGame.java b/src/startLocalGame.java index 5258499..9b263de 100644 --- a/src/startLocalGame.java +++ b/src/startLocalGame.java @@ -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){ diff --git a/src/startMultiplayerGame.java b/src/startMultiplayerGame.java index 44788ab..e536744 100644 --- a/src/startMultiplayerGame.java +++ b/src/startMultiplayerGame.java @@ -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"); } } }