From 33cdb14ff3f04112c3432fbf0655617fa8cad63b Mon Sep 17 00:00:00 2001 From: fdai7431 Date: Wed, 18 Jan 2023 11:21:26 +0100 Subject: [PATCH] [TikTakToeGame Class]: Actionlistener 2 --- .../JavaGamelauncher/TikTakToeGame.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/JavaGamelauncher/src/main/java/de/hs_fulda/gruppenprojekt/JavaGamelauncher/TikTakToeGame.java b/JavaGamelauncher/src/main/java/de/hs_fulda/gruppenprojekt/JavaGamelauncher/TikTakToeGame.java index 6732512..003b78c 100644 --- a/JavaGamelauncher/src/main/java/de/hs_fulda/gruppenprojekt/JavaGamelauncher/TikTakToeGame.java +++ b/JavaGamelauncher/src/main/java/de/hs_fulda/gruppenprojekt/JavaGamelauncher/TikTakToeGame.java @@ -323,6 +323,63 @@ public class TikTakToeGame extends JFrame{ } }); + btnNewButton2.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if(spielerIstDran == 1) { + btnNewButton2.setForeground(new Color(255, 0, 0)); + btnNewButton2.setBackground(new Color(255, 0, 0)); + btn2 = "red"; + + btnNewButton2.setEnabled(false); + if(btn2.equals("red") && btn1.equals("red") && btn3.equals("red") || + btn2.equals("red") && btn5.equals("red") && btn8.equals("red")){ + TextFieldAusgabe1.setText("Spieler 1 Hat gewonnen."); + punkte1 +=1; + + btnNewButton1.setEnabled(false); + btnNewButton3.setEnabled(false); + btnNewButton4.setEnabled(false); + btnNewButton5.setEnabled(false); + btnNewButton6.setEnabled(false); + btnNewButton7.setEnabled(false); + btnNewButton8.setEnabled(false); + btnNewButton9.setEnabled(false); + }//end if + else { + TextFieldAusgabe1.setText("Der Spieler 2 ist dran."); + spielerIstDran = 2; + }//end else + }//end if + else if(spielerIstDran == 2){ + btnNewButton2.setForeground(new Color(0, 0, 255)); + btnNewButton2.setBackground(new Color(0, 0, 255)); + btn2 = "blue"; + + btnNewButton2.setEnabled(false); + if(btn2.equals("blue") && btn1.equals("blue") && btn3.equals("blue") || + btn2.equals("blue") && btn5.equals("blue") && btn8.equals("blue")){ + TextFieldAusgabe1.setText("Spieler 2 Hat gewonnen."); + punkte1 +=1; + + btnNewButton1.setEnabled(false); + btnNewButton3.setEnabled(false); + btnNewButton4.setEnabled(false); + btnNewButton5.setEnabled(false); + btnNewButton6.setEnabled(false); + btnNewButton7.setEnabled(false); + btnNewButton8.setEnabled(false); + btnNewButton9.setEnabled(false); + }//end if + else { + TextFieldAusgabe1.setText("Der Spieler 1 ist dran."); + spielerIstDran = 1; + }//end else + }//end else if + else { + TextFieldAusgabe1.setText("Huiuiuiui, ein Fehler!."); + }//end else + } + }); }//end }