From b64039e8a60fce55b35a0a9bbab3f8c18d51aff1 Mon Sep 17 00:00:00 2001 From: Ivan Date: Tue, 11 Nov 2014 22:35:06 +0100 Subject: [PATCH] =?UTF-8?q?Diverse=20Anpassungen=20f=C3=BCr=20das=20Action?= =?UTF-8?q?Control?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HeatUp/src/de/heatup/testing/GameLoopD.java | 8 ++- HeatUp/src/de/heatup/ui/KeyBindings.java | 5 ++ .../heatup/ui/actionPanel/ActionControl.java | 65 +++++++++---------- .../heatup/ui/actionPanel/ActionWatcher.java | 38 +++++++++++ 4 files changed, 78 insertions(+), 38 deletions(-) create mode 100644 HeatUp/src/de/heatup/ui/actionPanel/ActionWatcher.java diff --git a/HeatUp/src/de/heatup/testing/GameLoopD.java b/HeatUp/src/de/heatup/testing/GameLoopD.java index 64db25f..14587d4 100644 --- a/HeatUp/src/de/heatup/testing/GameLoopD.java +++ b/HeatUp/src/de/heatup/testing/GameLoopD.java @@ -18,6 +18,7 @@ import de.heatup.objects.StaticObject; import de.heatup.ui.KeyBindings; import de.heatup.ui.StatusPanelAdder; import de.heatup.ui.actionPanel.ActionControl; +import de.heatup.ui.actionPanel.ActionWatcher; public class GameLoopD extends JFrame implements Runnable { @@ -78,7 +79,7 @@ public class GameLoopD extends JFrame implements Runnable { actionPanel = new JPanel(); actionPanel.setLayout(new GridLayout(1,1)); actionPanel.setPreferredSize(new Dimension(800,80)); - actionPanel.setFocusable(false); + actionPanel.setFocusable(true); outerPanel.add(statusPanel,BorderLayout.NORTH); outerPanel.add(gamePanel,BorderLayout.CENTER); @@ -93,7 +94,8 @@ public class GameLoopD extends JFrame implements Runnable { StatusPanelAdder.createPanel(); // ActionPanel bauen ActionControl.setPanel(actionPanel); - ActionControl.setAction("foo"); + + player01 = new Player(); // !!! PLAYER IMMER ZUERST INSTANZIIEREN, DANACH OPPONENTS !!! // Query.setPlayer(player01); @@ -130,6 +132,7 @@ public class GameLoopD extends JFrame implements Runnable { kb = new KeyBindings(player01); gamePanel.addKeyListener(kb); + MapEngine me = new MapEngine(1); me.addAllToPanel(gamePanel); @@ -252,6 +255,7 @@ public class GameLoopD extends JFrame implements Runnable { Config.currentTickNr++; } kb.checkKeyActivity(); + ActionWatcher.tick(); player01.tick(); opponent01.tick(); opponent02.tick(); diff --git a/HeatUp/src/de/heatup/ui/KeyBindings.java b/HeatUp/src/de/heatup/ui/KeyBindings.java index d60dbbe..78b2f03 100644 --- a/HeatUp/src/de/heatup/ui/KeyBindings.java +++ b/HeatUp/src/de/heatup/ui/KeyBindings.java @@ -3,9 +3,11 @@ package de.heatup.ui; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; +import sun.awt.resources.awt; import de.heatup.mapengine.CollisionHandler; import de.heatup.testing.GameLoopD; import de.heatup.testing.Player; +import de.heatup.ui.actionPanel.ActionWatcher; public class KeyBindings extends KeyAdapter { @@ -61,6 +63,9 @@ public class KeyBindings extends KeyAdapter { case KeyEvent.VK_ESCAPE: esc = true; break; + case KeyEvent.VK_A: + ActionWatcher.action = true; + break; } } diff --git a/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java b/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java index c6513cd..461e23c 100644 --- a/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java +++ b/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java @@ -3,59 +3,52 @@ package de.heatup.ui.actionPanel; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Font; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; import javax.swing.*; import javax.swing.border.LineBorder; -public class ActionControl { +import de.heatup.testing.Player; + +public class ActionControl{ private static Smashing smashing; private static Keysequence keysequence; private static JPanel panel; - private static JLabel comp; + private static boolean smash=false; + private static char chr; + private static int count=0; + protected static JLabel actionLabel; public static void setPanel(JPanel newPanel){ panel = newPanel; smashing = new Smashing(); keysequence = new Keysequence(); - comp = new JLabel(); - panel.add(comp); + actionLabel = new JLabel(); + actionLabel.setFont(new Font("Arial", Font.CENTER_BASELINE, 16)); + actionLabel.setBorder(new LineBorder(Color.BLACK, 1)); + actionLabel.setSize(100,10); + panel.add(actionLabel); + wishPanel(); } - - public static void setAction(String s){ - System.out.println("prompt"); - if(s.equals("smashing")){ - char tmp = smashing.getKey(); - - - //Hier soll eine Methode rein, sowas wie setTaste() oder setKey(), welche in der Manipulationshändling Klasse - //Implemintiert ist. Damit das Programm weiß welche Tasten Ausgelost wurden. Man übergibt einfach den tmp Char weiter. - - - - String str= "Bitte die Taste "+tmp+" so schnell wie möglich drücken"; - comp.setText(str); - comp.setFont(new Font("Arial", Font.CENTER_BASELINE, 16)); - comp.setBorder(new LineBorder(Color.BLACK, 1)); - comp.setSize(100,10); - panel.setVisible(false); - panel.setVisible(true); + public static void setAction(int rd){ + if(rd==1){ + setSmash(smashing.getKey()); + String str= "Bitte die Taste "+getSmash()+" so schnell wie moeglich druecken"; + actionLabel.setText(str); }else{ char []tmp = keysequence.getKeySequence(); - - - //Das selbe wie oben... - - - String str="Bitte diese Tastenkombination \""+tmp[0]+" "+tmp[1]+" "+tmp[2]+" "+tmp[3]+"\" "+"so schnell wie möglich eingeben"; - comp.setText(str); - comp.setFont(new Font("Arial", Font.CENTER_BASELINE, 16)); - comp.setBorder(new LineBorder(Color.BLACK, 1)); - comp.setSize(100,10); - panel.setVisible(false); - panel.setVisible(true); + String str="Bitte diese Tastenkombination \""+tmp[0]+" "+tmp[1]+" "+tmp[2]+" "+tmp[3]+"\" "+"so schnell wie moeglich eingeben"; + actionLabel.setText(str); } } + private static void setSmash(char c){ + chr=c; + } + private static char getSmash(){ + return chr; + } public static void wishPanel(){ - comp.setText(""); + actionLabel.setText(""); } } diff --git a/HeatUp/src/de/heatup/ui/actionPanel/ActionWatcher.java b/HeatUp/src/de/heatup/ui/actionPanel/ActionWatcher.java new file mode 100644 index 0000000..4a83a84 --- /dev/null +++ b/HeatUp/src/de/heatup/ui/actionPanel/ActionWatcher.java @@ -0,0 +1,38 @@ +package de.heatup.ui.actionPanel; + +import java.awt.Component; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.util.Random; + +import javax.swing.JLabel; + +import de.heatup.mapengine.MapEngine; +import de.heatup.mapengine.MapGrid; +import de.heatup.mapengine.MapGridCell; +import de.heatup.testing.GameLoopD; + +public class ActionWatcher{ + public static boolean action =false; + public static boolean setaction =false; + private static Random rdm =new Random(); + + public static void tick(){ + if(MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).isTrigger() && !action){ + ActionControl.actionLabel.setText("Taste A druecken"); + } + if(!MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).isTrigger() && !action && !setaction){ + ActionControl.wishPanel(); + } + if(action&&!setaction){ + setaction = !setaction; + ActionControl.actionLabel.setText(""); + ActionControl.setAction(rdm.nextInt(2)+1); + } + if(!MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).isTrigger() && setaction){ + ActionControl.wishPanel(); + setaction = !setaction; + action = !action; + } + } +}