From ece9e99e3442f7bf8087244103f17050c88adb62 Mon Sep 17 00:00:00 2001 From: Ivan Date: Tue, 18 Nov 2014 17:55:50 +0100 Subject: [PATCH] =?UTF-8?q?Keysequence=20eingef=C3=BChrt=20und=20ein=20Bal?= =?UTF-8?q?ken=20f=C3=BCr=20Smashing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HeatUp/src/de/heatup/ui/KeyBindings.java | 65 +++++--- .../heatup/ui/actionPanel/ActionControl.java | 145 +++++++++++++----- .../heatup/ui/actionPanel/ActionWatcher.java | 27 ++-- .../de/heatup/ui/actionPanel/Keysequence.java | 5 +- 4 files changed, 163 insertions(+), 79 deletions(-) diff --git a/HeatUp/src/de/heatup/ui/KeyBindings.java b/HeatUp/src/de/heatup/ui/KeyBindings.java index 3288c41..3da9e8f 100644 --- a/HeatUp/src/de/heatup/ui/KeyBindings.java +++ b/HeatUp/src/de/heatup/ui/KeyBindings.java @@ -73,42 +73,59 @@ public class KeyBindings extends KeyAdapter { } break; case KeyEvent.VK_Q: - if(ActionWatcher.getAction()&&ActionControl.getSmash()=='Q'){ - if(ActionControl.getOption()){ - ActionControl.count++; - }else{ - //ActionControl.setQ(); - //ActionControl.count++; + if(ActionWatcher.getAction()){ + if(ActionControl.getOption()==1){ + if(ActionControl.getSmash()=='Q')ActionControl.incCount(); + }else if(!ActionControl.getKeySequenceFail()){ + if(ActionControl.getSequence()[ActionControl.getCount()]=='Q'){ + ActionControl.incCount(); + }else{ + ActionControl.resetCount(); + ActionControl.setKeySequenceFail(); + } + } } break; case KeyEvent.VK_W: - if(ActionWatcher.getAction()&&ActionControl.getSmash()=='W'){ - if(ActionControl.getOption()){ - ActionControl.count++; - }else{ - //ActionControl.setW(); - //ActionControl.count++; + if(ActionWatcher.getAction()){ + if(ActionControl.getOption()==1){ + if(ActionControl.getSmash()=='W')ActionControl.incCount(); + }else if(!ActionControl.getKeySequenceFail()){ + if(ActionControl.getSequence()[ActionControl.getCount()]=='W'){ + ActionControl.incCount(); + }else{ + ActionControl.resetCount(); + ActionControl.setKeySequenceFail(); + } } } break; case KeyEvent.VK_E: - if(ActionWatcher.getAction()&&ActionControl.getSmash()=='E'){ - if(ActionControl.getOption()){ - ActionControl.count++; - }else{ - //ActionControl.setE(); - //ActionControl.count++; + if(ActionWatcher.getAction()){ + if(ActionControl.getOption()==1){ + if(ActionControl.getSmash()=='E')ActionControl.incCount(); + }else if(!ActionControl.getKeySequenceFail()){ + if(ActionControl.getSequence()[ActionControl.getCount()]=='E'){ + ActionControl.incCount(); + }else{ + ActionControl.resetCount(); + ActionControl.setKeySequenceFail(); + } } } break; case KeyEvent.VK_R: - if(ActionWatcher.getAction()&&ActionControl.getSmash()=='R'){ - if(ActionControl.getOption()){ - ActionControl.count++; - }else{ - //ActionControl.setR(); - //ActionControl.count++; + if(ActionWatcher.getAction()){ + if(ActionControl.getOption()==1){ + if(ActionControl.getSmash()=='R')ActionControl.incCount(); + }else if(!ActionControl.getKeySequenceFail()){ + if(ActionControl.getSequence()[ActionControl.getCount()]=='R'){ + ActionControl.incCount(); + }else{ + ActionControl.resetCount(); + ActionControl.setKeySequenceFail(); + } } } break; diff --git a/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java b/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java index 2493d0c..9fde52d 100644 --- a/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java +++ b/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java @@ -1,5 +1,6 @@ package de.heatup.ui.actionPanel; +import java.awt.BorderLayout; import java.awt.Color; import java.awt.Font; @@ -10,89 +11,120 @@ import de.heatup.mapengine.MapGrid; import de.heatup.testing.GameLoopD; public class ActionControl{ - public static int count =0; - private static long afterTime=0; - static long beforeTime =0; - static boolean time =true; - private static boolean Q=false; - private static boolean W=false; - private static boolean E=false; - private static boolean R=false; - private static boolean option; - private static char chr='0'; + private static int count = 0; + private static long afterTime = 0; + private static long beforeTime = 0; + private static boolean time = true; + private static boolean keySequenceFail=false; + private static int option=0; + private static char chr; private static char arr[]; private static Smashing smashing; private static Keysequence keysequence; private static JPanel panel; - protected static JLabel actionLabel; + private static JProgressBar bar; + private static JLabel actionLabel; + private static JLabel bigActionLabel; public static void setPanel(JPanel newPanel){ panel = newPanel; smashing = new Smashing(); keysequence = new Keysequence(); actionLabel = new JLabel(); + bigActionLabel = 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); + bigActionLabel.setFont(new Font("Arial", Font.LAYOUT_RIGHT_TO_LEFT,40)); + bigActionLabel.setVisible(false); + bar = new JProgressBar(); + bar.setVisible(false); + panel.setLayout(new BorderLayout()); + panel.add(actionLabel, BorderLayout.NORTH); + panel.add(bar,BorderLayout.SOUTH); + panel.add(bigActionLabel,BorderLayout.CENTER); wishPanel(); } public static void setAction(int rd){ - if(true){ - option=true; + if(rd==1){ + option=1; setSmash(smashing.getKey()); String str= "Bitte die Taste "+getSmash()+" so schnell wie moeglich druecken"; actionLabel.setText(str); - /*}else{ - option=false; + }else{ + option=2; setSequence(keysequence.getKeySequence()); String str="Bitte diese Tastenkombination \""; - for(int i=0;i8_000_000_000L){ - actionLabel.setText("Fehlgeschlagen"); + ActionWatcher.setAction(false); + actionLabel.setText("Zu langsam! Fehlgeschlagen!!!"); }else{ + ActionWatcher.setAction(false); actionLabel.setText("Manipulation erfolgreich!"); count=0; time=!time; - ActionWatcher.setAction(false); HardewareManipulate.setHardware(MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).getCorrespondingHardwareToTrigger()); } } + //KeySequence-Tick }else{ - // + if(!getKeySequenceFail()){ + if(count7_000_000_000L){ + ActionWatcher.setAction(false); + actionLabel.setText("Zu langsam! Fehlgeschlagen!!!"); + }else{ + ActionWatcher.setAction(false); + actionLabel.setText("Manipulation erfolgreich!"); + count=0; + time=!time; + HardewareManipulate.setHardware(MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).getCorrespondingHardwareToTrigger()); + } + } + }else{ + bigActionLabel.setVisible(false); + ActionWatcher.setAction(false); + actionLabel.setText("Falsche Taste! Fehlgeschlagen!!!"); + } } } } - public static void setQ(){ - Q=true; - } - public static void setW(){ - W=true; - } - public static void setE(){ - E=true; - } - public static void setR(){ - R=true; - } - - public static boolean getOption(){ + public static int getOption(){ return option; } private static void setSmash(char c){ @@ -104,10 +136,43 @@ public class ActionControl{ public static char getSmash(){ return chr; } - private static char[] getSequence(){ + public static char[] getSequence(){ return arr; } public static void wishPanel(){ + bigActionLabel.setText(""); + bar.setValue(0); + bar.setVisible(false); actionLabel.setText(""); } + public static void resetTime(){ + time=true; + } + public static void resetBeforeTime(){ + beforeTime=0; + } + public static int getCount(){ + return count; + } + public static void incCount(){ + count++; + } + public static void resetCount(){ + count=0; + } + public static boolean getKeySequenceFail(){ + return keySequenceFail; + } + public static void setKeySequenceFail(){ + keySequenceFail=true; + } + public static void resetKeySequenceFail(){ + keySequenceFail=false; + } + public static void setTextforA(){ + actionLabel.setText("Taste A druecken"); + } + public static void setTextforManipulate(){ + actionLabel.setText("Bereits Manipuliert"); + } } diff --git a/HeatUp/src/de/heatup/ui/actionPanel/ActionWatcher.java b/HeatUp/src/de/heatup/ui/actionPanel/ActionWatcher.java index 8a5826c..2a5e6ea 100644 --- a/HeatUp/src/de/heatup/ui/actionPanel/ActionWatcher.java +++ b/HeatUp/src/de/heatup/ui/actionPanel/ActionWatcher.java @@ -15,6 +15,7 @@ import de.heatup.testing.GameLoopD; public class ActionWatcher{ private static boolean action = false; private static boolean setaction = false; + private static boolean infoText =false; private static Random rdm = new Random(); public static void setAction(boolean b){ @@ -26,30 +27,34 @@ public class ActionWatcher{ public static void tick(){ //Taucht auf, falls man in der Näche von einem Hardwareteil steht if(MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).isTrigger() && !action && !setaction){ + infoText=true; if(!HardewareManipulate.getHardware(MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).getCorrespondingHardwareToTrigger())){ - ActionControl.actionLabel.setText("Taste A druecken"); + ActionControl.setTextforA();; }else{ - ActionControl.actionLabel.setText("Bereits Manipuliert"); + ActionControl.setTextforManipulate(); } } - //Entfernt jeglichen Text wenn man sich von dem Hardwarestück entfernt und noch nicht A gedrückt hat - if(!MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).isTrigger() && !action && !setaction){ + //Entfernt "Taste A drücken" + if(!MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).isTrigger() && infoText){ ActionControl.wishPanel(); + infoText=false; } //Nach dem man A gedrueckt hat kommt entweder Smashing oder Keysequence Text. if(action&&!setaction){ - setaction = !setaction; - ActionControl.actionLabel.setText(""); + setaction=true; + ActionControl.wishPanel(); ActionControl.setAction(rdm.nextInt(2)+1); } //Entfernt jeglichen Text wenn man sich von dem Hardwarestück entfernt und setzt Booleans wieder auf ausganssituation if(!MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).isTrigger() && setaction){ ActionControl.wishPanel(); - ActionControl.count=0; - ActionControl.time=true; - ActionControl.beforeTime=0; - setaction = !setaction; - action = !action; + ActionControl.resetCount(); + ActionControl.resetTime(); + ActionControl.resetBeforeTime(); + ActionControl.resetKeySequenceFail(); + infoText=false; + setaction=false; + action=false; } } } diff --git a/HeatUp/src/de/heatup/ui/actionPanel/Keysequence.java b/HeatUp/src/de/heatup/ui/actionPanel/Keysequence.java index c6b890b..7b2baf2 100644 --- a/HeatUp/src/de/heatup/ui/actionPanel/Keysequence.java +++ b/HeatUp/src/de/heatup/ui/actionPanel/Keysequence.java @@ -3,16 +3,13 @@ package de.heatup.ui.actionPanel; import java.util.Random; public class Keysequence { - private int length =8; + private int length =12; private char[] key_sq; private Random rdm; public Keysequence(){ rdm = new Random(); key_sq=new char[length]; } - public int getLength(){ - return length; - } protected char[] getKeySequence(){ for(int i=0;i