Diverse Anpassungen für das ActionControl

This commit is contained in:
Ivan
2014-11-11 22:35:06 +01:00
parent 6590f7af65
commit b64039e8a6
4 changed files with 78 additions and 38 deletions
+6 -2
View File
@@ -18,6 +18,7 @@ import de.heatup.objects.StaticObject;
import de.heatup.ui.KeyBindings; import de.heatup.ui.KeyBindings;
import de.heatup.ui.StatusPanelAdder; import de.heatup.ui.StatusPanelAdder;
import de.heatup.ui.actionPanel.ActionControl; import de.heatup.ui.actionPanel.ActionControl;
import de.heatup.ui.actionPanel.ActionWatcher;
public class GameLoopD extends JFrame implements Runnable { public class GameLoopD extends JFrame implements Runnable {
@@ -78,7 +79,7 @@ public class GameLoopD extends JFrame implements Runnable {
actionPanel = new JPanel(); actionPanel = new JPanel();
actionPanel.setLayout(new GridLayout(1,1)); actionPanel.setLayout(new GridLayout(1,1));
actionPanel.setPreferredSize(new Dimension(800,80)); actionPanel.setPreferredSize(new Dimension(800,80));
actionPanel.setFocusable(false); actionPanel.setFocusable(true);
outerPanel.add(statusPanel,BorderLayout.NORTH); outerPanel.add(statusPanel,BorderLayout.NORTH);
outerPanel.add(gamePanel,BorderLayout.CENTER); outerPanel.add(gamePanel,BorderLayout.CENTER);
@@ -93,7 +94,8 @@ public class GameLoopD extends JFrame implements Runnable {
StatusPanelAdder.createPanel(); StatusPanelAdder.createPanel();
// ActionPanel bauen // ActionPanel bauen
ActionControl.setPanel(actionPanel); ActionControl.setPanel(actionPanel);
ActionControl.setAction("foo");
player01 = new Player(); // !!! PLAYER IMMER ZUERST INSTANZIIEREN, DANACH OPPONENTS !!! player01 = new Player(); // !!! PLAYER IMMER ZUERST INSTANZIIEREN, DANACH OPPONENTS !!!
// Query.setPlayer(player01); // Query.setPlayer(player01);
@@ -130,6 +132,7 @@ public class GameLoopD extends JFrame implements Runnable {
kb = new KeyBindings(player01); kb = new KeyBindings(player01);
gamePanel.addKeyListener(kb); gamePanel.addKeyListener(kb);
MapEngine me = new MapEngine(1); MapEngine me = new MapEngine(1);
me.addAllToPanel(gamePanel); me.addAllToPanel(gamePanel);
@@ -252,6 +255,7 @@ public class GameLoopD extends JFrame implements Runnable {
Config.currentTickNr++; Config.currentTickNr++;
} }
kb.checkKeyActivity(); kb.checkKeyActivity();
ActionWatcher.tick();
player01.tick(); player01.tick();
opponent01.tick(); opponent01.tick();
opponent02.tick(); opponent02.tick();
+5
View File
@@ -3,9 +3,11 @@ package de.heatup.ui;
import java.awt.event.KeyAdapter; import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import sun.awt.resources.awt;
import de.heatup.mapengine.CollisionHandler; import de.heatup.mapengine.CollisionHandler;
import de.heatup.testing.GameLoopD; import de.heatup.testing.GameLoopD;
import de.heatup.testing.Player; import de.heatup.testing.Player;
import de.heatup.ui.actionPanel.ActionWatcher;
public class KeyBindings extends KeyAdapter { public class KeyBindings extends KeyAdapter {
@@ -61,6 +63,9 @@ public class KeyBindings extends KeyAdapter {
case KeyEvent.VK_ESCAPE: case KeyEvent.VK_ESCAPE:
esc = true; esc = true;
break; break;
case KeyEvent.VK_A:
ActionWatcher.action = true;
break;
} }
} }
@@ -3,59 +3,52 @@ package de.heatup.ui.actionPanel;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.Font; import java.awt.Font;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.LineBorder; import javax.swing.border.LineBorder;
import de.heatup.testing.Player;
public class ActionControl{ public class ActionControl{
private static Smashing smashing; private static Smashing smashing;
private static Keysequence keysequence; private static Keysequence keysequence;
private static JPanel panel; private static JPanel panel;
private static JLabel comp; private static boolean smash=false;
private static char chr;
private static int count=0;
protected static JLabel actionLabel;
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();
comp = new JLabel(); actionLabel = new JLabel();
panel.add(comp); actionLabel.setFont(new Font("Arial", Font.CENTER_BASELINE, 16));
actionLabel.setBorder(new LineBorder(Color.BLACK, 1));
actionLabel.setSize(100,10);
panel.add(actionLabel);
wishPanel();
} }
public static void setAction(int rd){
public static void setAction(String s){ if(rd==1){
System.out.println("prompt"); setSmash(smashing.getKey());
if(s.equals("smashing")){ String str= "Bitte die Taste "+getSmash()+" so schnell wie moeglich druecken";
char tmp = smashing.getKey(); actionLabel.setText(str);
//Hier soll eine Methode rein, sowas wie setTaste() oder setKey(), welche in der Manipulationshändling Klasse
//Implemintiert ist. Damit das Programm weiß welche Tasten Ausgelost wurden. Man übergibt einfach den tmp Char weiter.
String str= "Bitte die Taste "+tmp+" so schnell wie möglich drücken";
comp.setText(str);
comp.setFont(new Font("Arial", Font.CENTER_BASELINE, 16));
comp.setBorder(new LineBorder(Color.BLACK, 1));
comp.setSize(100,10);
panel.setVisible(false);
panel.setVisible(true);
}else{ }else{
char []tmp = keysequence.getKeySequence(); char []tmp = keysequence.getKeySequence();
String str="Bitte diese Tastenkombination \""+tmp[0]+" "+tmp[1]+" "+tmp[2]+" "+tmp[3]+"\" "+"so schnell wie moeglich eingeben";
actionLabel.setText(str);
//Das selbe wie oben...
String str="Bitte diese Tastenkombination \""+tmp[0]+" "+tmp[1]+" "+tmp[2]+" "+tmp[3]+"\" "+"so schnell wie möglich eingeben";
comp.setText(str);
comp.setFont(new Font("Arial", Font.CENTER_BASELINE, 16));
comp.setBorder(new LineBorder(Color.BLACK, 1));
comp.setSize(100,10);
panel.setVisible(false);
panel.setVisible(true);
} }
} }
private static void setSmash(char c){
chr=c;
}
private static char getSmash(){
return chr;
}
public static void wishPanel(){ public static void wishPanel(){
comp.setText(""); actionLabel.setText("");
} }
} }
@@ -0,0 +1,38 @@
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{
public static boolean action =false;
public static boolean setaction =false;
private static Random rdm =new Random();
public static void tick(){
if(MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).isTrigger() && !action){
ActionControl.actionLabel.setText("Taste A druecken");
}
if(!MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).isTrigger() && !action && !setaction){
ActionControl.wishPanel();
}
if(action&&!setaction){
setaction = !setaction;
ActionControl.actionLabel.setText("");
ActionControl.setAction(rdm.nextInt(2)+1);
}
if(!MapGrid.getGridCell(GameLoopD.player01.getGridLocation().x, GameLoopD.player01.getGridLocation().y).isTrigger() && setaction){
ActionControl.wishPanel();
setaction = !setaction;
action = !action;
}
}
}