mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 10:19:46 +02:00
Keysequence eingeführt und ein Balken für Smashing
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;i<keysequence.getLength();i++){
|
||||
for(int i=0;i<arr.length;i++){
|
||||
str=str+getSequence()[i]+" ";
|
||||
}
|
||||
str=str + "\" "+"so schnell wie moeglich eingeben";
|
||||
actionLabel.setText(str);*/
|
||||
actionLabel.setText(str);
|
||||
}
|
||||
}
|
||||
public static void actionControl(){
|
||||
if(ActionWatcher.getAction()){
|
||||
if(option){
|
||||
if(count<30){
|
||||
//Smashing-Tick
|
||||
if(option==1){
|
||||
bar.setValue(0);
|
||||
bar.setVisible(true);
|
||||
if(count<50){
|
||||
if(time){
|
||||
time = !time;
|
||||
beforeTime=System.nanoTime();
|
||||
}
|
||||
bar.setValue((int)(count*2));;
|
||||
}else{
|
||||
bar.setVisible(false);
|
||||
afterTime=System.nanoTime()-beforeTime;
|
||||
if(afterTime>8_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(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);
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<length;i++){
|
||||
switch(rdm.nextInt(4)+1){
|
||||
|
||||
Reference in New Issue
Block a user