mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 11:29:46 +02:00
Merge branch 'master' of github.com:jokerx3/prp
This commit is contained in:
@@ -3,6 +3,7 @@ package de.heatup.mapengine;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import de.heatup.logging.Logger;
|
import de.heatup.logging.Logger;
|
||||||
|
import de.heatup.testing.Opponent;
|
||||||
import de.heatup.testing.Player;
|
import de.heatup.testing.Player;
|
||||||
|
|
||||||
public class CollisionHandler {
|
public class CollisionHandler {
|
||||||
@@ -14,29 +15,90 @@ public class CollisionHandler {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean checkCollision(Player movingObject, char d) {
|
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<movingObjects.size();i++) {
|
||||||
|
if (movingObject.getGridLocation().x== movingObjects.get(i).getGridLocation().x && movingObject.getGridLocation().y == movingObjects.get(i).getGridLocation().y) {
|
||||||
|
// System.exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static void hardwareCollision(Player movingObject, char d) {
|
||||||
switch (d) {
|
switch (d) {
|
||||||
case 'l':
|
case 'l':
|
||||||
if (MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).isTrigger()) {
|
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());
|
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':
|
case 'r':
|
||||||
if (MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).isTrigger()) {
|
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());
|
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':
|
case 'd':
|
||||||
if (MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).isTrigger()) {
|
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());
|
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':
|
case 'u':
|
||||||
if (MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).isTrigger()) {
|
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());
|
Logger.write("Collision with trigger of hardware ID: " + MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).getCorrespondingHardwareToTrigger());
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static boolean normalCheck(Player movingObject, char d) {
|
||||||
|
switch (d) {
|
||||||
|
case 'l':
|
||||||
|
|
||||||
|
return MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).isPath();
|
||||||
|
case 'r':
|
||||||
|
|
||||||
|
return MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).isPath();
|
||||||
|
case 'd':
|
||||||
|
|
||||||
|
return MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).isPath();
|
||||||
|
case 'u':
|
||||||
|
|
||||||
return MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).isPath();
|
return MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).isPath();
|
||||||
default:
|
default:
|
||||||
return true;
|
return true; // should not happen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static void addMovingObject(Player movingObject) {
|
public static void addMovingObject(Player movingObject) {
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class GameLoopD extends JFrame implements Runnable {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
// Logging ausgabe auf Console aktivieren bzw. deaktivieren.
|
// Logging ausgabe auf Console aktivieren bzw. deaktivieren.
|
||||||
Logger.enableLogging();
|
// Logger.enableLogging();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* hier drin bauen wir unser ui zusammen.
|
* hier drin bauen wir unser ui zusammen.
|
||||||
@@ -85,7 +85,7 @@ public class GameLoopD extends JFrame implements Runnable {
|
|||||||
StatusPanelAdder.setPanel(statusPanel);
|
StatusPanelAdder.setPanel(statusPanel);
|
||||||
StatusPanelAdder.createPanel();
|
StatusPanelAdder.createPanel();
|
||||||
|
|
||||||
player01 = new Player();
|
player01 = new Player(); // !!! PLAYER IMMER ZUERST INSTANZIIEREN, DANACH OPPONENTS !!!
|
||||||
// Query.setPlayer(player01);
|
// Query.setPlayer(player01);
|
||||||
gamePanel.add(player01);
|
gamePanel.add(player01);
|
||||||
player01.setBounds(25,25,25, 25); // !!! MUSS DRIN BLEIBEN TROTZ NACHTRÄGLICHES SPAWN UMSETZEN !!!
|
player01.setBounds(25,25,25, 25); // !!! MUSS DRIN BLEIBEN TROTZ NACHTRÄGLICHES SPAWN UMSETZEN !!!
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
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 static Smashing smashing;
|
||||||
|
private static Keysequence keysequence;
|
||||||
|
private static JPanel panel;
|
||||||
|
private static JLabel comp;
|
||||||
|
|
||||||
|
public static void setPanel(JPanel newPanel){
|
||||||
|
panel = newPanel;
|
||||||
|
smashing = new Smashing();
|
||||||
|
keysequence = new Keysequence();
|
||||||
|
comp = new JLabel();
|
||||||
|
panel.add(comp);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void wishPanel(){
|
||||||
|
comp.setText("");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user