mit points aber buggy
parent
7b4a54d1b5
commit
c3cdb120c6
|
@ -1,17 +1,17 @@
|
|||
###################################
|
||||
# #
|
||||
# ############ ###### ########### #
|
||||
# ##### ###### ###### ###### #### #
|
||||
# ###### #
|
||||
# ############ ###### ########### #
|
||||
# ############ ########### #
|
||||
# ## ### #
|
||||
# ############ 0123 ########### #
|
||||
# ########## ###### ######### #
|
||||
# ##### ###### ###### ###### #### #
|
||||
# ##### ###### ###### #### #
|
||||
# ##,### #
|
||||
# ##### ###### ,0123, ###### #### #
|
||||
# ### ###### ###### ###### ## #
|
||||
# # # P # # #
|
||||
# ############ # ## # ########### #
|
||||
# ##### ###### # ## # ###### #### #
|
||||
# # ## # #
|
||||
# ############ ## ########### #
|
||||
# ############# ############ #
|
||||
# ############# #### ############ #
|
||||
# ### ######## ## ######## ## #
|
||||
# ##### ####### ####### #### #
|
||||
# ##### ####### #### ####### #### #
|
||||
# #
|
||||
###################################
|
Binary file not shown.
After Width: | Height: | Size: 149 B |
|
@ -0,0 +1 @@
|
|||
/Point.class
|
BIN
bin/Game.class
BIN
bin/Game.class
Binary file not shown.
BIN
bin/Ghost.class
BIN
bin/Ghost.class
Binary file not shown.
BIN
bin/Map.class
BIN
bin/Map.class
Binary file not shown.
BIN
bin/Player.class
BIN
bin/Player.class
Binary file not shown.
|
@ -5,7 +5,7 @@ import java.util.*;
|
|||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import java.lang.Math;
|
||||
import java.lang.Math;
|
||||
|
||||
// In dieser Klasse findet der größte Teil des Spiels statt:
|
||||
// Rendern von Map, Geistern, Pac-Man etc.
|
||||
|
@ -93,7 +93,15 @@ public class Game {
|
|||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 35; i++) { // für jeden Brick // points
|
||||
for (int j = 0; j < 35; j++) { // für jeden Brick
|
||||
if (Map.points[j][i] != null) { // Damit kein Fehler auftritt wegen nicht vorhandenen Bricks
|
||||
panel.add(Map.points[j][i]); // Der jeweilige Brick wird zum panel hinzugefügt
|
||||
Map.points[j][i].setBounds(Map.points[j][i].xPos, Map.points[j][i].yPos, 20, 20); // Rendern des
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
frame.setVisible(true);
|
||||
|
||||
lastT = System.nanoTime(); // delta time
|
||||
|
@ -108,44 +116,50 @@ public class Game {
|
|||
player.setLocation(player.getPos('x', dt), player.getPos('y', dt));
|
||||
|
||||
// Aktualiesieren der Positionen der Geister:
|
||||
//for (int i = 0; i < ghosts.length; i++) {
|
||||
// ghosts[i].setLocation(ghosts[i].getPos('x', dt), ghosts[i].getPos('y', dt));
|
||||
//}
|
||||
// for (int i = 0; i < ghosts.length; i++) {
|
||||
// ghosts[i].setLocation(ghosts[i].getPos('x', dt), ghosts[i].getPos('y', dt));
|
||||
// }
|
||||
|
||||
for (int i = 0; i < ghosts.length; i++) {
|
||||
|
||||
|
||||
ghost_possible[i][0] = false;
|
||||
ghost_possible[i][1] = false;
|
||||
ghost_possible[i][2] = false;
|
||||
ghost_possible[i][3] = false;
|
||||
|
||||
if ((Map.bricks[conv(ghosts[i].yPos)][conv(ghosts[i].xPos) + 1] == null && Map.bricks[conv(ghosts[i].yPos + 19)][conv(ghosts[i].xPos) + 1] == null) || (ghosts[i].xPos + 10) % 20 != 0 ){
|
||||
|
||||
if ((Map.bricks[conv(ghosts[i].yPos)][conv(ghosts[i].xPos) + 1] == null
|
||||
&& Map.bricks[conv(ghosts[i].yPos + 19)][conv(ghosts[i].xPos) + 1] == null)
|
||||
|| (ghosts[i].xPos + 10) % 20 != 0) {
|
||||
ghost_possible[i][0] = true;
|
||||
|
||||
}
|
||||
if ((Map.bricks[conv(ghosts[i].yPos)][conv(ghosts[i].xPos) - 1] == null && Map.bricks[conv(ghosts[i].yPos + 19)][conv(ghosts[i].xPos) - 1] == null) || (ghosts[i].xPos + 10) % 20 != 0 ){
|
||||
if ((Map.bricks[conv(ghosts[i].yPos)][conv(ghosts[i].xPos) - 1] == null
|
||||
&& Map.bricks[conv(ghosts[i].yPos + 19)][conv(ghosts[i].xPos) - 1] == null)
|
||||
|| (ghosts[i].xPos + 10) % 20 != 0) {
|
||||
ghost_possible[i][1] = true;
|
||||
|
||||
}
|
||||
if ((Map.bricks[conv(ghosts[i].yPos) - 1][conv(ghosts[i].xPos)] == null && Map.bricks[conv(ghosts[i].yPos) - 1][conv(ghosts[i].xPos + 19)] == null) || (ghosts[i].yPos + 10) % 20 != 0 ){
|
||||
if ((Map.bricks[conv(ghosts[i].yPos) - 1][conv(ghosts[i].xPos)] == null
|
||||
&& Map.bricks[conv(ghosts[i].yPos) - 1][conv(ghosts[i].xPos + 19)] == null)
|
||||
|| (ghosts[i].yPos + 10) % 20 != 0) {
|
||||
ghost_possible[i][2] = true;
|
||||
}
|
||||
if ((Map.bricks[conv(ghosts[i].yPos) + 1][conv(ghosts[i].xPos)] == null && Map.bricks[conv(ghosts[i].yPos) + 1][conv(ghosts[i].xPos + 19)] == null) || (ghosts[i].yPos + 10) % 20 != 0 ){
|
||||
if ((Map.bricks[conv(ghosts[i].yPos) + 1][conv(ghosts[i].xPos)] == null
|
||||
&& Map.bricks[conv(ghosts[i].yPos) + 1][conv(ghosts[i].xPos + 19)] == null)
|
||||
|| (ghosts[i].yPos + 10) % 20 != 0) {
|
||||
ghost_possible[i][3] = true;
|
||||
}
|
||||
|
||||
System.out.println(HCost[0] + " " + HCost[1] + " " + HCost[2] + " " + HCost[3]);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// System.out.println(HCost[0] + " " + HCost[1] + " " + HCost[2] + " " +
|
||||
// HCost[3]);
|
||||
|
||||
HCost[0] = ghosts[i].getHCost(player, 1, 0);
|
||||
HCost[1] = ghosts[i].getHCost(player, -1, 0);
|
||||
HCost[2] = ghosts[i].getHCost(player, 0, -1);
|
||||
HCost[3] = ghosts[i].getHCost(player, 0, 1);
|
||||
//
|
||||
int minn = 10000;
|
||||
|
||||
|
||||
if (ghosts[i].up == true) {
|
||||
HCost[3] = 10000;
|
||||
}
|
||||
|
@ -158,8 +172,7 @@ public class Game {
|
|||
if (ghosts[i].right == true) {
|
||||
HCost[1] = 10000;
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (int j = 0; j < 4; j++) {
|
||||
if (ghost_possible[i][j] == false) {
|
||||
HCost[j] = 10500;
|
||||
|
@ -171,9 +184,9 @@ public class Game {
|
|||
minn = HCost[j];
|
||||
}
|
||||
}
|
||||
|
||||
//System.out.println(minn);
|
||||
|
||||
|
||||
// System.out.println(minn);
|
||||
|
||||
//
|
||||
for (int j = 0; j < 4; j++) {
|
||||
if (HCost[j] == minn) {
|
||||
|
@ -207,8 +220,7 @@ public class Game {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -242,7 +254,13 @@ public class Game {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((player.getPos('x', 0) - 10) % 20 == 0 && (player.getPos('y', 0) - 10) % 20 == 0 && Map.points[conv(player.getPos('y', 0))][conv(player.getPos('x', 0))] != null) {
|
||||
Map.points[conv(player.yPos)][conv(player.xPos)].setBounds(0, 0, 0, 0);
|
||||
|
||||
System.out.println("" + conv(player.yPos) + " " + conv(player.xPos));
|
||||
}
|
||||
|
||||
|
||||
player.calcDir(0); // Berechnen wo Pac-Man als nächstes hin soll
|
||||
|
||||
for (int i = 0; i < ghosts.length; i++) {
|
||||
|
@ -275,10 +293,10 @@ public class Game {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private int conv(float a) { //90.0 --> 4
|
||||
int b = (int) (a - 10 )/ 20;
|
||||
|
||||
private int conv(float a) { // 90.0 --> 4
|
||||
int b = (int) (a - 10) / 20;
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@ import java.io.FileReader;
|
|||
public class Map {
|
||||
|
||||
public static Brick bricks[][] = new Brick[35][35]; // Zweidimensionales Array für alle Bricks
|
||||
// Zweidimensionale Arrays siehe
|
||||
public static Point points[][] = new Point[35][35];
|
||||
// Zweidimensionale Arrays siehe
|
||||
// https://de.wikipedia.org/wiki/Feld_(Datentyp)#Mehrdimensional_/_in-sich-mehrdimensional
|
||||
|
||||
BufferedReader reader; // reader zum Einlesen der Text Datei
|
||||
|
@ -51,6 +52,8 @@ public class Map {
|
|||
} else if (line.charAt(j) == '3') {
|
||||
ghosts[3].setPos('x', 10 + 20 * j);
|
||||
ghosts[3].setPos('y', 10 + 20 * i);
|
||||
} else if (line.charAt(j) == ' ') {
|
||||
points[i][j] = new Point(10 + 20 * j, 10 + 20 * i);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
|
|
|
@ -10,8 +10,8 @@ public class Player extends Picture implements KeyListener { // extends Picture
|
|||
|
||||
private static final long serialVersionUID = -4225811153447791553L;
|
||||
|
||||
private float xPos; // Position auf dem Frame in x-Richtung
|
||||
private float yPos; // Position auf dem Frame in y-Richtung
|
||||
public float xPos; // Position auf dem Frame in x-Richtung
|
||||
public float yPos; // Position auf dem Frame in y-Richtung
|
||||
|
||||
public int lives = 3;
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
// Diese Klasse stellt die einzelnen Bicks (Wände) auf der Map dar.
|
||||
|
||||
public class Point extends Picture { // Die übergeordnete Klasse ist Picture
|
||||
|
||||
|
||||
|
||||
private static final long serialVersionUID = -1204077187616807301L;
|
||||
|
||||
|
||||
public int xPos; // Position auf dem Frame in x-Richtung
|
||||
public int yPos; // Position auf dem Frame in y-Richtung
|
||||
|
||||
public Point(int newXPos, int newYPos) { // Erstellen des Konstruktors mit den Koordinaten, an denen sich der Brick
|
||||
// beefinden soll.
|
||||
|
||||
super("point"); // Aufrufen der übergeordneten Klasse
|
||||
|
||||
// Setzen der Positionen:
|
||||
xPos = newXPos;
|
||||
yPos = newYPos;
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue