Diverse Anpassungen

This commit is contained in:
Ivan
2014-11-18 22:47:46 +01:00
parent ece9e99e34
commit ac852f1d40
3 changed files with 42 additions and 52 deletions
+1 -1
View File
@@ -259,7 +259,7 @@ public class GameLoopD extends JFrame implements Runnable {
kb.checkKeyActivity(); kb.checkKeyActivity();
if (!pause) { if (!pause) {
ActionWatcher.tick(); ActionWatcher.tick();
ActionControl.actionControl(); ActionControl.tick();
HardwareResetTimers.tick(); HardwareResetTimers.tick();
player01.tick(); player01.tick();
opponent01.tick(); opponent01.tick();
@@ -12,15 +12,12 @@ import de.heatup.testing.GameLoopD;
public class ActionControl{ public class ActionControl{
private static int count = 0; private static int count = 0;
private static long afterTime = 0; private static long beforTime = 0;
private static long beforeTime = 0;
private static boolean time = true; private static boolean time = true;
private static boolean keySequenceFail=false; private static boolean keySequenceFail=false;
private static int option=0; private static int option=0;
private static char chr; private static char chr;
private static char arr[]; private static char arr[];
private static Smashing smashing;
private static Keysequence keysequence;
private static JPanel panel; private static JPanel panel;
private static JProgressBar bar; private static JProgressBar bar;
private static JLabel actionLabel; private static JLabel actionLabel;
@@ -28,30 +25,31 @@ public class ActionControl{
public static void setPanel(JPanel newPanel){ public static void setPanel(JPanel newPanel){
panel = newPanel; panel = newPanel;
smashing = new Smashing();
keysequence = new Keysequence();
actionLabel = new JLabel(); actionLabel = new JLabel();
bigActionLabel = new JLabel(); bigActionLabel = new JLabel();
actionLabel.setFont(new Font("Arial", Font.CENTER_BASELINE, 16));
bigActionLabel.setFont(new Font("Arial", Font.LAYOUT_RIGHT_TO_LEFT,40));
bigActionLabel.setVisible(false);
bar = new JProgressBar(); bar = new JProgressBar();
actionLabel.setFont(new Font("Arial", Font.CENTER_BASELINE, 16));
actionLabel.setHorizontalAlignment(JLabel.CENTER);
bigActionLabel.setFont(new Font("Arial", Font.LAYOUT_RIGHT_TO_LEFT,40));
bigActionLabel.setForeground(Color.RED);
bigActionLabel.setHorizontalAlignment(JLabel.CENTER);
bigActionLabel.setVisible(false);
bar.setVisible(false); bar.setVisible(false);
panel.setLayout(new BorderLayout()); panel.setLayout(new BorderLayout());
panel.add(actionLabel, BorderLayout.NORTH); panel.add(actionLabel, BorderLayout.NORTH);
panel.add(bar,BorderLayout.SOUTH); panel.add(bar,BorderLayout.SOUTH);
panel.add(bigActionLabel,BorderLayout.CENTER); panel.add(bigActionLabel,BorderLayout.CENTER);
wishPanel(); resetActionPanel();
} }
public static void setAction(int rd){ public static void setAction(int rd){
if(rd==1){ if(rd==1){
option=1; option=1;
setSmash(smashing.getKey()); setSmash(new 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=2; option=2;
setSequence(keysequence.getKeySequence()); setSequence(new Keysequence().getKeySequence());
String str="Bitte diese Tastenkombination \""; String str="Bitte diese Tastenkombination \"";
for(int i=0;i<arr.length;i++){ for(int i=0;i<arr.length;i++){
str=str+getSequence()[i]+" "; str=str+getSequence()[i]+" ";
@@ -60,7 +58,7 @@ public class ActionControl{
actionLabel.setText(str); actionLabel.setText(str);
} }
} }
public static void actionControl(){ public static void tick(){
if(ActionWatcher.getAction()){ if(ActionWatcher.getAction()){
//Smashing-Tick //Smashing-Tick
if(option==1){ if(option==1){
@@ -68,21 +66,17 @@ public class ActionControl{
bar.setVisible(true); bar.setVisible(true);
if(count<50){ if(count<50){
if(time){ if(time){
time = !time; time = false;
beforeTime=System.nanoTime(); beforTime=System.nanoTime();
} }
bar.setValue((int)(count*2));; bar.setValue((int)(count*2));
}else{ }else{
bar.setVisible(false); bar.setVisible(false);
afterTime=System.nanoTime()-beforeTime;
if(afterTime>8_000_000_000L){
ActionWatcher.setAction(false); ActionWatcher.setAction(false);
if(System.nanoTime()-beforTime>8_000_000_000L){
actionLabel.setText("Zu langsam! Fehlgeschlagen!!!"); actionLabel.setText("Zu langsam! Fehlgeschlagen!!!");
}else{ }else{
ActionWatcher.setAction(false);
actionLabel.setText("Manipulation erfolgreich!"); 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());
} }
} }
@@ -92,8 +86,8 @@ public class ActionControl{
if(count<arr.length){ if(count<arr.length){
bigActionLabel.setVisible(true); bigActionLabel.setVisible(true);
if(time){ if(time){
time = !time; time = false;
beforeTime=System.nanoTime(); beforTime=System.nanoTime();
}else if(count!=0){ }else if(count!=0){
actionLabel.setText(""); actionLabel.setText("");
String str=""; String str="";
@@ -104,15 +98,12 @@ public class ActionControl{
} }
}else{ }else{
bigActionLabel.setVisible(false); bigActionLabel.setVisible(false);
afterTime=System.nanoTime()-beforeTime;
if(afterTime>7_000_000_000L){
ActionWatcher.setAction(false); ActionWatcher.setAction(false);
if(System.nanoTime()-beforTime>7_000_000_000L){
actionLabel.setText("Zu langsam! Fehlgeschlagen!!!"); actionLabel.setText("Zu langsam! Fehlgeschlagen!!!");
}else{ }else{
ActionWatcher.setAction(false);
actionLabel.setText("Manipulation erfolgreich!"); 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());
} }
} }
@@ -139,7 +130,7 @@ public class ActionControl{
public static char[] getSequence(){ public static char[] getSequence(){
return arr; return arr;
} }
public static void wishPanel(){ public static void resetActionPanel(){
bigActionLabel.setText(""); bigActionLabel.setText("");
bar.setValue(0); bar.setValue(0);
bar.setVisible(false); bar.setVisible(false);
@@ -148,8 +139,8 @@ public class ActionControl{
public static void resetTime(){ public static void resetTime(){
time=true; time=true;
} }
public static void resetBeforeTime(){ public static void resetBeforTime(){
beforeTime=0; beforTime=0;
} }
public static int getCount(){ public static int getCount(){
return count; return count;
@@ -14,9 +14,8 @@ 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 boolean infoText =false;
private static Random rdm = new Random();
public static void setAction(boolean b){ public static void setAction(boolean b){
action = b; action = b;
@@ -25,35 +24,35 @@ public class ActionWatcher{
return action; return action;
} }
public static void tick(){ public static void tick(){
//Taucht auf, falls man in der Näche von einem Hardwareteil steht //Infotext, wenn man in der he 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; 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.setTextforA();; ActionControl.setTextforA();
}else{ }else{
ActionControl.setTextforManipulate(); ActionControl.setTextforManipulate();
} }
} }
//Entfernt "Taste A drücken" //Entfernt InfoText
if(!MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).isTrigger() && infoText){ if(!MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).isTrigger() && infoText){
ActionControl.wishPanel(); ActionControl.resetActionPanel();
infoText=false; infoText=false;
} }
//Nach dem man A gedrueckt hat kommt entweder Smashing oder Keysequence Text. //Leitet das Manipulieren ein, nachdem man das "A" gedrückt hat. Es kommt entweder Smashing oder Keysequence Text.
if(action&&!setaction){ if(action&&!setAction){
setaction=true; setAction=true;
ActionControl.wishPanel(); ActionControl.resetActionPanel();
ActionControl.setAction(rdm.nextInt(2)+1); ActionControl.setAction(new Random().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, 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){ if(!MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).isTrigger() && setAction){
ActionControl.wishPanel(); ActionControl.resetActionPanel();
ActionControl.resetCount(); ActionControl.resetCount();
ActionControl.resetTime(); ActionControl.resetTime();
ActionControl.resetBeforeTime(); ActionControl.resetBeforTime();
ActionControl.resetKeySequenceFail(); ActionControl.resetKeySequenceFail();
infoText=false; infoText=false;
setaction=false; setAction=false;
action=false; action=false;
} }
} }