From 945837642e83fabab9d061269b03fa8b19237519 Mon Sep 17 00:00:00 2001 From: toksikk Date: Fri, 7 Nov 2014 16:00:57 +0100 Subject: [PATCH 1/4] Erweiterte Collision Detection --- .../de/heatup/mapengine/CollisionHandler.java | 70 +++++++++++++++++-- HeatUp/src/de/heatup/testing/GameLoopD.java | 4 +- 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/HeatUp/src/de/heatup/mapengine/CollisionHandler.java b/HeatUp/src/de/heatup/mapengine/CollisionHandler.java index cbd6ae1..08a626c 100644 --- a/HeatUp/src/de/heatup/mapengine/CollisionHandler.java +++ b/HeatUp/src/de/heatup/mapengine/CollisionHandler.java @@ -3,6 +3,7 @@ package de.heatup.mapengine; import java.util.ArrayList; import de.heatup.logging.Logger; +import de.heatup.testing.Opponent; import de.heatup.testing.Player; public class CollisionHandler { @@ -14,29 +15,90 @@ public class CollisionHandler { * @return */ public static boolean checkCollision(Player movingObject, char d) { +// if (movingObject == (movingObjects.get(0))) { + if (movingObject.equals(movingObjects.get(0))) { + enemyCollision(movingObject, d); + hardwareCollision(movingObject, d); + return normalCheck(movingObject, d); + } else { + playerCollision(movingObject, d); + return normalCheck(movingObject, d); + } +// switch (d) { +// case 'l': +// if (MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).isTrigger()) { +// Logger.write("Collision with trigger of hardware ID: " + MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).getCorrespondingHardwareToTrigger()); +// } +// return MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).isPath(); +// case 'r': +// if (MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).isTrigger()) { +// Logger.write("Collision with trigger of hardware ID: " + MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).getCorrespondingHardwareToTrigger()); +// } +// return MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).isPath(); +// case 'd': +// if (MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).isTrigger()) { +// Logger.write("Collision with trigger of hardware ID: " + MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).getCorrespondingHardwareToTrigger()); +// } +// return MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).isPath(); +// case 'u': +// if (MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).isTrigger()) { +// Logger.write("Collision with trigger of hardware ID: " + MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).getCorrespondingHardwareToTrigger()); +// } +// return MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).isPath(); +// default: +// return true; +// } + } + private static void playerCollision(Player movingObject, char d) { + if (movingObject.getGridLocation().x== movingObjects.get(0).getGridLocation().x && movingObject.getGridLocation().y == movingObjects.get(0).getGridLocation().y) { +// System.exit(-1); + } + } + private static void enemyCollision(Player movingObject, char d ) { + for (int i=1; i Date: Fri, 7 Nov 2014 18:48:53 +0100 Subject: [PATCH 2/4] actionPanel erste Klassen --- .../heatup/ui/actionPanel/ActionControl.java | 48 +++++++++++++++++++ .../de/heatup/ui/actionPanel/Keysequence.java | 32 +++++++++++++ .../de/heatup/ui/actionPanel/Smashing.java | 29 +++++++++++ 3 files changed, 109 insertions(+) create mode 100644 HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java create mode 100644 HeatUp/src/de/heatup/ui/actionPanel/Keysequence.java create mode 100644 HeatUp/src/de/heatup/ui/actionPanel/Smashing.java diff --git a/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java b/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java new file mode 100644 index 0000000..cbb1f2e --- /dev/null +++ b/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java @@ -0,0 +1,48 @@ +package de.heatup.ui.actionPanel; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Font; + +import javax.swing.*; +import javax.swing.border.LineBorder; + +public class ActionControl { + private Smashing smashing; + private Keysequence keysequence; + private JPanel panel; + private JLabel comp; + + public void setPanel(JPanel newPanel){ + panel = newPanel; + } + + public void setAction(String s){ + + if(s.equals("smashing")){ + smashing = new Smashing(); + String tmp= "Bitte die Taste "+smashing.getKey()+" so schnell wie möglich drücken"; + comp = new JLabel(tmp); + comp.setFont(new Font("Arial", Font.CENTER_BASELINE, 16)); + comp.setBorder(new LineBorder(Color.BLACK, 1)); + comp.setSize(100,10); + panel.add(comp); + panel.setVisible(false); + panel.setVisible(true); + }else{ + keysequence = new Keysequence(); + String tmp="Bitte diese Tastenkombination "+keysequence.getKeySequence()[0]+" "+keysequence.getKeySequence()[1]+" "+keysequence.getKeySequence()[2]+" "+keysequence.getKeySequence()[3]+" "+" so schnell wie möglich drücken"; + comp = new JLabel(tmp); + comp.setFont(new Font("Arial", Font.CENTER_BASELINE, 16)); + comp.setBorder(new LineBorder(Color.BLACK, 1)); + comp.setSize(100,10); + panel.add(comp); + panel.setVisible(false); + panel.setVisible(true); + + } + } + public void wishPanel(){ + comp.setVisible(false); + } +} diff --git a/HeatUp/src/de/heatup/ui/actionPanel/Keysequence.java b/HeatUp/src/de/heatup/ui/actionPanel/Keysequence.java new file mode 100644 index 0000000..f5408d2 --- /dev/null +++ b/HeatUp/src/de/heatup/ui/actionPanel/Keysequence.java @@ -0,0 +1,32 @@ +package de.heatup.ui.actionPanel; + +import java.util.Random; + +public class Keysequence { + char[] key_sq; + Random rdm; + public Keysequence(){ + rdm = new Random(); + key_sq=new char[4]; + } + + public char[] getKeySequence(){ + for(int i=0;i<4;i++){ + switch(rdm.nextInt(4)+1){ + case 1: + key_sq[i]='Q'; + break; + case 2: + key_sq[i]='W'; + break; + case 3: + key_sq[i]='E'; + break; + case 4: + key_sq[i]='R'; + break; + } + } + return key_sq; + } +} diff --git a/HeatUp/src/de/heatup/ui/actionPanel/Smashing.java b/HeatUp/src/de/heatup/ui/actionPanel/Smashing.java new file mode 100644 index 0000000..ca21c2b --- /dev/null +++ b/HeatUp/src/de/heatup/ui/actionPanel/Smashing.java @@ -0,0 +1,29 @@ +package de.heatup.ui.actionPanel; + +import java.util.Random; + +public class Smashing { + char key; + Random rdm; + + public Smashing(){ + rdm = new Random(); + } + public char getKey(){ + switch(rdm.nextInt(4)+1){ + case 1: + key='Q'; + break; + case 2: + key='W'; + break; + case 3: + key='E'; + break; + case 4: + key='R'; + break; + } + return key; + } +} From 99250750faad8eaad457f4a0db7f1c66162507fb Mon Sep 17 00:00:00 2001 From: Ivan Date: Fri, 7 Nov 2014 21:21:08 +0100 Subject: [PATCH 3/4] ActionControl Anpassungen --- .../heatup/ui/actionPanel/ActionControl.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java b/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java index cbb1f2e..a3354ef 100644 --- a/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java +++ b/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java @@ -8,41 +8,41 @@ import javax.swing.*; import javax.swing.border.LineBorder; public class ActionControl { - private Smashing smashing; - private Keysequence keysequence; - private JPanel panel; - private JLabel comp; + private static Smashing smashing; + private static Keysequence keysequence; + private static JPanel panel; + private static JLabel comp; - public void setPanel(JPanel newPanel){ + public static void setPanel(JPanel newPanel){ panel = newPanel; + smashing = new Smashing(); + keysequence = new Keysequence(); + comp = new JLabel(); + panel.add(comp); } - public void setAction(String s){ - + public static void setAction(String s){ + System.out.println("prompt"); if(s.equals("smashing")){ - smashing = new Smashing(); - String tmp= "Bitte die Taste "+smashing.getKey()+" so schnell wie möglich drücken"; - comp = new JLabel(tmp); + String str= "Bitte die Taste "+smashing.getKey()+" 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.add(comp); panel.setVisible(false); panel.setVisible(true); }else{ - keysequence = new Keysequence(); - String tmp="Bitte diese Tastenkombination "+keysequence.getKeySequence()[0]+" "+keysequence.getKeySequence()[1]+" "+keysequence.getKeySequence()[2]+" "+keysequence.getKeySequence()[3]+" "+" so schnell wie möglich drücken"; - comp = new JLabel(tmp); + char []tmp = keysequence.getKeySequence(); + 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.add(comp); panel.setVisible(false); panel.setVisible(true); - } } - public void wishPanel(){ - comp.setVisible(false); + public static void wishPanel(){ + comp.setText(""); } } From a60e083dac5eeda4b8ba37692fa05f008d2fcbf1 Mon Sep 17 00:00:00 2001 From: Ivan Date: Fri, 7 Nov 2014 21:29:05 +0100 Subject: [PATCH 4/4] =?UTF-8?q?Kommentar=20f=C3=BCr=20die=20Entwicklung=20?= =?UTF-8?q?hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../de/heatup/ui/actionPanel/ActionControl.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java b/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java index a3354ef..c6513cd 100644 --- a/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java +++ b/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java @@ -24,7 +24,15 @@ public class ActionControl { public static void setAction(String s){ System.out.println("prompt"); if(s.equals("smashing")){ - String str= "Bitte die Taste "+smashing.getKey()+" so schnell wie möglich drücken"; + 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)); @@ -33,6 +41,11 @@ public class ActionControl { panel.setVisible(true); }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));