mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 12:19:45 +02:00
Diverse Anpassungen für das ActionControl
This commit is contained in:
@@ -18,6 +18,7 @@ import de.heatup.objects.StaticObject;
|
||||
import de.heatup.ui.KeyBindings;
|
||||
import de.heatup.ui.StatusPanelAdder;
|
||||
import de.heatup.ui.actionPanel.ActionControl;
|
||||
import de.heatup.ui.actionPanel.ActionWatcher;
|
||||
|
||||
|
||||
public class GameLoopD extends JFrame implements Runnable {
|
||||
@@ -78,7 +79,7 @@ public class GameLoopD extends JFrame implements Runnable {
|
||||
actionPanel = new JPanel();
|
||||
actionPanel.setLayout(new GridLayout(1,1));
|
||||
actionPanel.setPreferredSize(new Dimension(800,80));
|
||||
actionPanel.setFocusable(false);
|
||||
actionPanel.setFocusable(true);
|
||||
|
||||
outerPanel.add(statusPanel,BorderLayout.NORTH);
|
||||
outerPanel.add(gamePanel,BorderLayout.CENTER);
|
||||
@@ -93,7 +94,8 @@ public class GameLoopD extends JFrame implements Runnable {
|
||||
StatusPanelAdder.createPanel();
|
||||
// ActionPanel bauen
|
||||
ActionControl.setPanel(actionPanel);
|
||||
ActionControl.setAction("foo");
|
||||
|
||||
|
||||
|
||||
player01 = new Player(); // !!! PLAYER IMMER ZUERST INSTANZIIEREN, DANACH OPPONENTS !!!
|
||||
// Query.setPlayer(player01);
|
||||
@@ -130,6 +132,7 @@ public class GameLoopD extends JFrame implements Runnable {
|
||||
kb = new KeyBindings(player01);
|
||||
gamePanel.addKeyListener(kb);
|
||||
|
||||
|
||||
MapEngine me = new MapEngine(1);
|
||||
me.addAllToPanel(gamePanel);
|
||||
|
||||
@@ -252,6 +255,7 @@ public class GameLoopD extends JFrame implements Runnable {
|
||||
Config.currentTickNr++;
|
||||
}
|
||||
kb.checkKeyActivity();
|
||||
ActionWatcher.tick();
|
||||
player01.tick();
|
||||
opponent01.tick();
|
||||
opponent02.tick();
|
||||
|
||||
@@ -3,9 +3,11 @@ package de.heatup.ui;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import sun.awt.resources.awt;
|
||||
import de.heatup.mapengine.CollisionHandler;
|
||||
import de.heatup.testing.GameLoopD;
|
||||
import de.heatup.testing.Player;
|
||||
import de.heatup.ui.actionPanel.ActionWatcher;
|
||||
|
||||
public class KeyBindings extends KeyAdapter {
|
||||
|
||||
@@ -61,6 +63,9 @@ public class KeyBindings extends KeyAdapter {
|
||||
case KeyEvent.VK_ESCAPE:
|
||||
esc = true;
|
||||
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.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.LineBorder;
|
||||
|
||||
public class ActionControl {
|
||||
import de.heatup.testing.Player;
|
||||
|
||||
public class ActionControl{
|
||||
private static Smashing smashing;
|
||||
private static Keysequence keysequence;
|
||||
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){
|
||||
panel = newPanel;
|
||||
smashing = new Smashing();
|
||||
keysequence = new Keysequence();
|
||||
comp = new JLabel();
|
||||
panel.add(comp);
|
||||
actionLabel = 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);
|
||||
wishPanel();
|
||||
}
|
||||
|
||||
public static void setAction(String s){
|
||||
System.out.println("prompt");
|
||||
if(s.equals("smashing")){
|
||||
char tmp = smashing.getKey();
|
||||
|
||||
|
||||
//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);
|
||||
public static void setAction(int rd){
|
||||
if(rd==1){
|
||||
setSmash(smashing.getKey());
|
||||
String str= "Bitte die Taste "+getSmash()+" so schnell wie moeglich druecken";
|
||||
actionLabel.setText(str);
|
||||
}else{
|
||||
char []tmp = keysequence.getKeySequence();
|
||||
|
||||
|
||||
//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);
|
||||
String str="Bitte diese Tastenkombination \""+tmp[0]+" "+tmp[1]+" "+tmp[2]+" "+tmp[3]+"\" "+"so schnell wie moeglich eingeben";
|
||||
actionLabel.setText(str);
|
||||
}
|
||||
}
|
||||
private static void setSmash(char c){
|
||||
chr=c;
|
||||
}
|
||||
private static char getSmash(){
|
||||
return chr;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user