Keysequence eingeführt und ein Balken für Smashing

This commit is contained in:
Ivan
2014-11-18 17:55:50 +01:00
parent d9357e81a8
commit ece9e99e34
4 changed files with 163 additions and 79 deletions
+37 -20
View File
@@ -73,42 +73,59 @@ public class KeyBindings extends KeyAdapter {
} }
break; break;
case KeyEvent.VK_Q: case KeyEvent.VK_Q:
if(ActionWatcher.getAction()&&ActionControl.getSmash()=='Q'){ if(ActionWatcher.getAction()){
if(ActionControl.getOption()){ if(ActionControl.getOption()==1){
ActionControl.count++; if(ActionControl.getSmash()=='Q')ActionControl.incCount();
}else if(!ActionControl.getKeySequenceFail()){
if(ActionControl.getSequence()[ActionControl.getCount()]=='Q'){
ActionControl.incCount();
}else{ }else{
//ActionControl.setQ(); ActionControl.resetCount();
//ActionControl.count++; ActionControl.setKeySequenceFail();
}
} }
} }
break; break;
case KeyEvent.VK_W: case KeyEvent.VK_W:
if(ActionWatcher.getAction()&&ActionControl.getSmash()=='W'){ if(ActionWatcher.getAction()){
if(ActionControl.getOption()){ if(ActionControl.getOption()==1){
ActionControl.count++; if(ActionControl.getSmash()=='W')ActionControl.incCount();
}else if(!ActionControl.getKeySequenceFail()){
if(ActionControl.getSequence()[ActionControl.getCount()]=='W'){
ActionControl.incCount();
}else{ }else{
//ActionControl.setW(); ActionControl.resetCount();
//ActionControl.count++; ActionControl.setKeySequenceFail();
}
} }
} }
break; break;
case KeyEvent.VK_E: case KeyEvent.VK_E:
if(ActionWatcher.getAction()&&ActionControl.getSmash()=='E'){ if(ActionWatcher.getAction()){
if(ActionControl.getOption()){ if(ActionControl.getOption()==1){
ActionControl.count++; if(ActionControl.getSmash()=='E')ActionControl.incCount();
}else if(!ActionControl.getKeySequenceFail()){
if(ActionControl.getSequence()[ActionControl.getCount()]=='E'){
ActionControl.incCount();
}else{ }else{
//ActionControl.setE(); ActionControl.resetCount();
//ActionControl.count++; ActionControl.setKeySequenceFail();
}
} }
} }
break; break;
case KeyEvent.VK_R: case KeyEvent.VK_R:
if(ActionWatcher.getAction()&&ActionControl.getSmash()=='R'){ if(ActionWatcher.getAction()){
if(ActionControl.getOption()){ if(ActionControl.getOption()==1){
ActionControl.count++; if(ActionControl.getSmash()=='R')ActionControl.incCount();
}else if(!ActionControl.getKeySequenceFail()){
if(ActionControl.getSequence()[ActionControl.getCount()]=='R'){
ActionControl.incCount();
}else{ }else{
//ActionControl.setR(); ActionControl.resetCount();
//ActionControl.count++; ActionControl.setKeySequenceFail();
}
} }
} }
break; break;
@@ -1,5 +1,6 @@
package de.heatup.ui.actionPanel; package de.heatup.ui.actionPanel;
import java.awt.BorderLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.Font; import java.awt.Font;
@@ -10,89 +11,120 @@ import de.heatup.mapengine.MapGrid;
import de.heatup.testing.GameLoopD; import de.heatup.testing.GameLoopD;
public class ActionControl{ public class ActionControl{
public static int count =0; private static int count = 0;
private static long afterTime=0; private static long afterTime = 0;
static long beforeTime =0; private static long beforeTime = 0;
static boolean time =true; private static boolean time = true;
private static boolean Q=false; private static boolean keySequenceFail=false;
private static boolean W=false; private static int option=0;
private static boolean E=false; private static char chr;
private static boolean R=false;
private static boolean option;
private static char chr='0';
private static char arr[]; private static char arr[];
private static Smashing smashing; private static Smashing smashing;
private static Keysequence keysequence; private static Keysequence keysequence;
private static JPanel panel; 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){ public static void setPanel(JPanel newPanel){
panel = newPanel; panel = newPanel;
smashing = new Smashing(); smashing = new Smashing();
keysequence = new Keysequence(); keysequence = new Keysequence();
actionLabel = new JLabel(); actionLabel = new JLabel();
bigActionLabel = new JLabel();
actionLabel.setFont(new Font("Arial", Font.CENTER_BASELINE, 16)); actionLabel.setFont(new Font("Arial", Font.CENTER_BASELINE, 16));
actionLabel.setBorder(new LineBorder(Color.BLACK, 1)); bigActionLabel.setFont(new Font("Arial", Font.LAYOUT_RIGHT_TO_LEFT,40));
actionLabel.setSize(100,10); bigActionLabel.setVisible(false);
panel.add(actionLabel); 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(); wishPanel();
} }
public static void setAction(int rd){ public static void setAction(int rd){
if(true){ if(rd==1){
option=true; option=1;
setSmash(smashing.getKey()); setSmash(smashing.getKey());
String str= "Bitte die Taste "+getSmash()+" so schnell wie moeglich druecken"; String str= "Bitte die Taste "+getSmash()+" so schnell wie moeglich druecken";
actionLabel.setText(str); actionLabel.setText(str);
/*}else{ }else{
option=false; option=2;
setSequence(keysequence.getKeySequence()); setSequence(keysequence.getKeySequence());
String str="Bitte diese Tastenkombination \""; String str="Bitte diese Tastenkombination \"";
for(int i=0;i<keysequence.getLength();i++){ for(int i=0;i<arr.length;i++){
str=str+getSequence()[i]+" "; str=str+getSequence()[i]+" ";
} }
str=str + "\" "+"so schnell wie moeglich eingeben"; str=str + "\" "+"so schnell wie moeglich eingeben";
actionLabel.setText(str);*/ actionLabel.setText(str);
} }
} }
public static void actionControl(){ public static void actionControl(){
if(ActionWatcher.getAction()){ if(ActionWatcher.getAction()){
if(option){ //Smashing-Tick
if(count<30){ if(option==1){
bar.setValue(0);
bar.setVisible(true);
if(count<50){
if(time){ if(time){
time = !time; time = !time;
beforeTime=System.nanoTime(); beforeTime=System.nanoTime();
} }
bar.setValue((int)(count*2));;
}else{ }else{
bar.setVisible(false);
afterTime=System.nanoTime()-beforeTime; afterTime=System.nanoTime()-beforeTime;
if(afterTime>8_000_000_000L){ if(afterTime>8_000_000_000L){
actionLabel.setText("Fehlgeschlagen"); ActionWatcher.setAction(false);
actionLabel.setText("Zu langsam! Fehlgeschlagen!!!");
}else{ }else{
ActionWatcher.setAction(false);
actionLabel.setText("Manipulation erfolgreich!"); actionLabel.setText("Manipulation erfolgreich!");
count=0; count=0;
time=!time; time=!time;
HardewareManipulate.setHardware(MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).getCorrespondingHardwareToTrigger());
}
}
//KeySequence-Tick
}else{
if(!getKeySequenceFail()){
if(count<arr.length){
bigActionLabel.setVisible(true);
if(time){
time = !time;
beforeTime=System.nanoTime();
}else if(count!=0){
actionLabel.setText("");
String str=" ";
for(int i=count;i<arr.length;i++){
str=str+getSequence()[i]+" ";
}
bigActionLabel.setText(str);
}
}else{
bigActionLabel.setVisible(false);
afterTime=System.nanoTime()-beforeTime;
if(afterTime>7_000_000_000L){
ActionWatcher.setAction(false); 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()); HardewareManipulate.setHardware(MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).getCorrespondingHardwareToTrigger());
} }
} }
}else{ }else{
// bigActionLabel.setVisible(false);
ActionWatcher.setAction(false);
actionLabel.setText("Falsche Taste! Fehlgeschlagen!!!");
} }
} }
} }
public static void setQ(){
Q=true;
} }
public static void setW(){ public static int getOption(){
W=true;
}
public static void setE(){
E=true;
}
public static void setR(){
R=true;
}
public static boolean getOption(){
return option; return option;
} }
private static void setSmash(char c){ private static void setSmash(char c){
@@ -104,10 +136,43 @@ public class ActionControl{
public static char getSmash(){ public static char getSmash(){
return chr; return chr;
} }
private static char[] getSequence(){ public static char[] getSequence(){
return arr; return arr;
} }
public static void wishPanel(){ public static void wishPanel(){
bigActionLabel.setText("");
bar.setValue(0);
bar.setVisible(false);
actionLabel.setText(""); 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");
}
} }
@@ -15,6 +15,7 @@ import de.heatup.testing.GameLoopD;
public class ActionWatcher{ public class ActionWatcher{
private static boolean action = false; private static boolean action = false;
private static boolean setaction = false; private static boolean setaction = false;
private static boolean infoText =false;
private static Random rdm = new Random(); private static Random rdm = new Random();
public static void setAction(boolean b){ public static void setAction(boolean b){
@@ -26,30 +27,34 @@ public class ActionWatcher{
public static void tick(){ public static void tick(){
//Taucht auf, falls man in der Näche von einem Hardwareteil steht //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){ 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())){ if(!HardewareManipulate.getHardware(MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).getCorrespondingHardwareToTrigger())){
ActionControl.actionLabel.setText("Taste A druecken"); ActionControl.setTextforA();;
}else{ }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 //Entfernt "Taste A drücken"
if(!MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).isTrigger() && !action && !setaction){ if(!MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).isTrigger() && infoText){
ActionControl.wishPanel(); ActionControl.wishPanel();
infoText=false;
} }
//Nach dem man A gedrueckt hat kommt entweder Smashing oder Keysequence Text. //Nach dem man A gedrueckt hat kommt entweder Smashing oder Keysequence Text.
if(action&&!setaction){ if(action&&!setaction){
setaction = !setaction; setaction=true;
ActionControl.actionLabel.setText(""); ActionControl.wishPanel();
ActionControl.setAction(rdm.nextInt(2)+1); ActionControl.setAction(rdm.nextInt(2)+1);
} }
//Entfernt jeglichen Text wenn man sich von dem Hardwarestück entfernt und setzt Booleans wieder auf ausganssituation //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){ if(!MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).isTrigger() && setaction){
ActionControl.wishPanel(); ActionControl.wishPanel();
ActionControl.count=0; ActionControl.resetCount();
ActionControl.time=true; ActionControl.resetTime();
ActionControl.beforeTime=0; ActionControl.resetBeforeTime();
setaction = !setaction; ActionControl.resetKeySequenceFail();
action = !action; infoText=false;
setaction=false;
action=false;
} }
} }
} }
@@ -3,16 +3,13 @@ package de.heatup.ui.actionPanel;
import java.util.Random; import java.util.Random;
public class Keysequence { public class Keysequence {
private int length =8; private int length =12;
private char[] key_sq; private char[] key_sq;
private Random rdm; private Random rdm;
public Keysequence(){ public Keysequence(){
rdm = new Random(); rdm = new Random();
key_sq=new char[length]; key_sq=new char[length];
} }
public int getLength(){
return length;
}
protected char[] getKeySequence(){ protected char[] getKeySequence(){
for(int i=0;i<length;i++){ for(int i=0;i<length;i++){
switch(rdm.nextInt(4)+1){ switch(rdm.nextInt(4)+1){