From 5f1d9893e12c9d4aa80e14e961d5e1ef72b2c68c Mon Sep 17 00:00:00 2001 From: Ivan Date: Fri, 21 Nov 2014 16:57:37 +0100 Subject: [PATCH] Noch mehr Anpassungen --- HeatUp/src/de/heatup/ui/KeyBindings.java | 22 ++-- .../heatup/ui/actionPanel/ActionControl.java | 115 ++++++++---------- .../heatup/ui/actionPanel/ActionWatcher.java | 10 +- 3 files changed, 61 insertions(+), 86 deletions(-) diff --git a/HeatUp/src/de/heatup/ui/KeyBindings.java b/HeatUp/src/de/heatup/ui/KeyBindings.java index 4a0b687..34f191d 100644 --- a/HeatUp/src/de/heatup/ui/KeyBindings.java +++ b/HeatUp/src/de/heatup/ui/KeyBindings.java @@ -13,7 +13,7 @@ import de.heatup.ui.actionPanel.ActionWatcher; import de.heatup.ui.actionPanel.HardewareManipulate; public class KeyBindings extends KeyAdapter { - + final private static int progressBarTimer = 7; private boolean left = false; private boolean right = false; private boolean up = false; @@ -45,6 +45,9 @@ public class KeyBindings extends KeyAdapter { case KeyEvent.VK_ESCAPE: esc = false; break; + case KeyEvent.VK_A: + key = false; + break; case KeyEvent.VK_Q: key = false; break; @@ -80,22 +83,22 @@ public class KeyBindings extends KeyAdapter { esc = true; break; case KeyEvent.VK_A: - if(MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).isTrigger() - && !HardewareManipulate.getHardware(MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).getCorrespondingHardwareToTrigger())){ + if(((MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).isTrigger() + && !HardewareManipulate.getHardware(MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).getCorrespondingHardwareToTrigger()))&&!key)&&ActionControl.getKeyA()){ ActionWatcher.setAction(true); + key=true; } break; case KeyEvent.VK_Q: if(ActionWatcher.getAction()&&!key){ if(ActionControl.getOption()==1){ if(ActionControl.getSmash()=='Q'){ - ActionControl.getBar().setValue(ActionControl.getBar().getValue()+7); + ActionControl.setProgressBarTimer(progressBarTimer); } }else if(!ActionControl.getKeySequenceFail()){ if(ActionControl.getSequence()[ActionControl.getCount()]=='Q'){ ActionControl.incCount(); }else{ - ActionControl.resetCount(); ActionControl.setKeySequenceFail(); } @@ -107,13 +110,12 @@ public class KeyBindings extends KeyAdapter { if(ActionWatcher.getAction()&&!key){ if(ActionControl.getOption()==1){ if(ActionControl.getSmash()=='W'){; - ActionControl.getBar().setValue(ActionControl.getBar().getValue()+7); + ActionControl.setProgressBarTimer(progressBarTimer); } }else if(!ActionControl.getKeySequenceFail()){ if(ActionControl.getSequence()[ActionControl.getCount()]=='W'){ ActionControl.incCount(); }else{ - ActionControl.resetCount(); ActionControl.setKeySequenceFail(); } } @@ -124,13 +126,12 @@ public class KeyBindings extends KeyAdapter { if(ActionWatcher.getAction()&&!key){ if(ActionControl.getOption()==1){ if(ActionControl.getSmash()=='E'){ - ActionControl.getBar().setValue(ActionControl.getBar().getValue()+7); + ActionControl.setProgressBarTimer(progressBarTimer); } }else if(!ActionControl.getKeySequenceFail()){ if(ActionControl.getSequence()[ActionControl.getCount()]=='E'){ ActionControl.incCount(); }else{ - ActionControl.resetCount(); ActionControl.setKeySequenceFail(); } } @@ -141,13 +142,12 @@ public class KeyBindings extends KeyAdapter { if(ActionWatcher.getAction()&&!key){ if(ActionControl.getOption()==1){ if(ActionControl.getSmash()=='R'){ - ActionControl.getBar().setValue(ActionControl.getBar().getValue()+7); + ActionControl.setProgressBarTimer(progressBarTimer); } }else if(!ActionControl.getKeySequenceFail()){ if(ActionControl.getSequence()[ActionControl.getCount()]=='R'){ ActionControl.incCount(); }else{ - ActionControl.resetCount(); ActionControl.setKeySequenceFail(); } } diff --git a/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java b/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java index 52fc91d..b63b862 100644 --- a/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java +++ b/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java @@ -5,18 +5,14 @@ import java.awt.Color; import java.awt.Font; import javax.swing.*; -import javax.swing.border.LineBorder; import de.heatup.mapengine.MapGrid; import de.heatup.testing.GameLoopD; -import de.heatup.ui.StatusPanelAdder; public class ActionControl{ private static int count = 0; private static long beforTime = 0; - private static boolean time = true; private static boolean keySequenceFail=false; - private static boolean tickTimer =false; private static int option=0; private static char chr; private static char arr[]; @@ -25,6 +21,7 @@ public class ActionControl{ private static JLabel actionLabel; private static JLabel bigActionLabel; private static int tmpCount=0; + private static boolean keyA=true; public static void setPanel(JPanel newPanel){ panel = newPanel; @@ -45,81 +42,57 @@ public class ActionControl{ resetActionPanel(); } public static void setAction(int rd){ + setKeyA(); if(rd==1){ option=1; setSmash(new Smashing().getKey()); String str= "Bitte die Taste "+getSmash()+" so schnell wie moeglich druecken"; actionLabel.setText(str); + setProgressBar(0); + beforTime=System.nanoTime(); }else{ option=2; setSequence(new Keysequence().getKeySequence()); String str="Bitte diese Tastenkombination so schnell wie moeglich eingeben"; actionLabel.setText(str); + setProgressBar(100); } } public static void tick(){ if(ActionWatcher.getAction()){ - //Smashing-Tick - if(option==1){ - setTickTimer(); - if(bar.getValue()<100){ - if(time){ - setProgressBar(0); - time = false; - beforTime=System.nanoTime(); - } - }else{ - tmpCount=0; - bar.setVisible(false); - ActionWatcher.setAction(false); - if(System.nanoTime()-beforTime>8_000_000_000L){ - actionLabel.setText("Zu langsam! Fehlgeschlagen!!!"); - }else{ - actionLabel.setText("Manipulation erfolgreich!"); - HardewareManipulate.setHardware(MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).getCorrespondingHardwareToTrigger()); - } - } - //KeySequence-Tick - }else{ - if(!getTickTimer()){ - setTickTimer(); - setProgressBar(100); + if(option==1){ //Smashing-Tick + if(bar.getValue()>=100){ + setAchiv(8_000_000_000L, System.nanoTime()-beforTime); } + }else{ //KeySequence-Tick if(!getKeySequenceFail()){ if(count0){ bigActionLabel.setVisible(true); - if(time){ - time = false; - beforTime=System.nanoTime(); - } String str=""; for(int i=count;i7_000_000_000L || bar.getValue()<=0){ - actionLabel.setText("Zu langsam! Fehlgeschlagen!!!"); - }else{ - actionLabel.setText("Manipulation erfolgreich!"); - HardewareManipulate.setHardware(MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).getCorrespondingHardwareToTrigger()); - } + setAchiv(bar.getValue(),0); } }else{ - resetTickTimer(); - resetProgressBar(); - bigActionLabel.setVisible(false); - ActionWatcher.setAction(false); - actionLabel.setText("Falsche Taste! Fehlgeschlagen!!!"); + setAchiv(); } } + tickProgressBar(); //ProgressBar-Tick } } - public static void tickTimer(){ + public static boolean getKeyA(){ + return keyA; + } + private static void setKeyA(){ + keyA=false; + } + public static void resetKeyA(){ + keyA=true; + } + private static void tickProgressBar(){ tmpCount++; if(option==1){ if(bar.getValue()>1){ @@ -130,14 +103,21 @@ public class ActionControl{ if(tmpCount%3==0)bar.setValue(bar.getValue()-1); } } - public static boolean getTickTimer(){ - return tickTimer; + private static void setAchiv(double value1, double value2){ + ActionWatcher.setAction(false); + if(value1<=value2){ + resetActionPanel(); + actionLabel.setText("Zu langsam! Fehlgeschlagen!!!"); + }else{ + resetActionPanel(); + actionLabel.setText("Manipulation erfolgreich!"); + HardewareManipulate.setHardware(MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).getCorrespondingHardwareToTrigger()); + } } - public static void resetTickTimer(){ - tickTimer=false; - } - private static void setTickTimer(){ - tickTimer=true; + private static void setAchiv(){ + ActionWatcher.setAction(false); + resetActionPanel(); + actionLabel.setText("Falsche Taste! Fehlgeschlagen!!!"); } public static int getOption(){ return option; @@ -155,19 +135,20 @@ public class ActionControl{ return arr; } public static void resetActionPanel(){ - bigActionLabel.setText(""); - actionLabel.setText(""); + resetBigActionLabel(); + resetActionLabel(); resetProgressBar(); resetCount(); - resetTime(); resetBeforTime(); resetKeySequenceFail(); - resetTickTimer(); } - public static void resetTime(){ - time=true; + private static void resetActionLabel(){ + actionLabel.setText(""); } - public static void resetBeforTime(){ + private static void resetBigActionLabel(){ + bigActionLabel.setText(""); + } + private static void resetBeforTime(){ beforTime=0; } public static int getCount(){ @@ -176,7 +157,7 @@ public class ActionControl{ public static void incCount(){ count++; } - public static void resetCount(){ + private static void resetCount(){ tmpCount=0; count=0; } @@ -186,7 +167,7 @@ public class ActionControl{ public static void setKeySequenceFail(){ keySequenceFail=true; } - public static void resetKeySequenceFail(){ + private static void resetKeySequenceFail(){ keySequenceFail=false; } public static void setTextforA(){ @@ -203,7 +184,7 @@ public class ActionControl{ bar.setValue(0); bar.setVisible(false); } - public static JProgressBar getBar(){ - return bar; + public static void setProgressBarTimer(int value){ + bar.setValue(bar.getValue()+value); } } diff --git a/HeatUp/src/de/heatup/ui/actionPanel/ActionWatcher.java b/HeatUp/src/de/heatup/ui/actionPanel/ActionWatcher.java index c115e10..f878128 100644 --- a/HeatUp/src/de/heatup/ui/actionPanel/ActionWatcher.java +++ b/HeatUp/src/de/heatup/ui/actionPanel/ActionWatcher.java @@ -1,15 +1,8 @@ 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{ @@ -47,6 +40,7 @@ public class ActionWatcher{ //Entfernt jeglichen Text wenn man sich von dem Hardwarestück entfernt, nachdem Aktion bereits eingeleitet wurde, und setzt Booleans/Counter wieder auf die Ausgangssituation if(!MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).isTrigger() && setAction){ ActionControl.resetActionPanel(); + ActionControl.resetKeyA(); infoText=false; setAction=false; action=false;