mapmenu fertiggestellt
parent
c137c9080a
commit
671bfa3748
|
@ -1,4 +1,3 @@
|
||||||
Ms Pac-Man
|
|
||||||
############################
|
############################
|
||||||
# ## ## #
|
# ## ## #
|
||||||
#.#### ## ######## ## ####.#
|
#.#### ## ######## ## ####.#
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
/MapMenu.class
|
/MapMenu.class
|
||||||
|
/MapMenu$1.class
|
||||||
|
|
BIN
bin/Game.class
BIN
bin/Game.class
Binary file not shown.
BIN
bin/Main.class
BIN
bin/Main.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.
|
@ -46,7 +46,7 @@ public class Game {
|
||||||
int minn;
|
int minn;
|
||||||
int[] HCost = new int[4];
|
int[] HCost = new int[4];
|
||||||
|
|
||||||
public Game() { // Erstellen des Konstruktors (Was soll passieren, sobald dieses Klasse
|
public Game(String selectedMap) { // Erstellen des Konstruktors (Was soll passieren, sobald dieses Klasse
|
||||||
// aufgerufen wird?)
|
// aufgerufen wird?)
|
||||||
|
|
||||||
frame = new JFrame(); // Fenster
|
frame = new JFrame(); // Fenster
|
||||||
|
@ -100,7 +100,7 @@ public class Game {
|
||||||
ghosts[i].setBounds(ghosts[i].getPos('x', 0), ghosts[i].getPos('y', 0), 20, 20);
|
ghosts[i].setBounds(ghosts[i].getPos('x', 0), ghosts[i].getPos('y', 0), 20, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
map = new Map(player, ghosts); // Map auf der gespielt wird
|
map = new Map(selectedMap, player, ghosts); // Map auf der gespielt wird
|
||||||
map.mapping();
|
map.mapping();
|
||||||
|
|
||||||
player.setBounds(player.getPos('x', 0), player.getPos('y', 0), 20, 20); // Pac-Man wird das erste Mal gerendert
|
player.setBounds(player.getPos('x', 0), player.getPos('y', 0), 20, 20); // Pac-Man wird das erste Mal gerendert
|
||||||
|
|
|
@ -10,10 +10,26 @@ public class Main {
|
||||||
|
|
||||||
System.setProperty("sun.java2d.opengl", "true");
|
System.setProperty("sun.java2d.opengl", "true");
|
||||||
|
|
||||||
// Game game = new Game(); // Das Spiel wird gestartet
|
// Game game = new Game("map1.txt"); // Das Spiel wird gestartet
|
||||||
|
|
||||||
MapMenu menu = new MapMenu();
|
MapMenu menu = new MapMenu();
|
||||||
|
|
||||||
|
while(!menu.rdy) {
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game = new Game(menu.selectedMap + ".txt");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Methode zum verzögern (warten) in ms
|
||||||
|
public static void delay(int time) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(time);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
10
src/Map.java
10
src/Map.java
|
@ -25,19 +25,25 @@ public class Map {
|
||||||
public static int pac_posX;
|
public static int pac_posX;
|
||||||
public static int pac_posY;
|
public static int pac_posY;
|
||||||
|
|
||||||
|
String selectedMap;
|
||||||
|
|
||||||
String line; // String in dem eingelsene Zeilen der Datei gespeichert werden
|
String line; // String in dem eingelsene Zeilen der Datei gespeichert werden
|
||||||
|
|
||||||
public Map(Player player, Ghost ghosts[]) { // Erstellen des Konstruktors
|
public Map(String selectedMap, Player player, Ghost ghosts[]) { // Erstellen des Konstruktors
|
||||||
|
|
||||||
this.ghosts = ghosts;
|
this.ghosts = ghosts;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
|
||||||
|
this.selectedMap = selectedMap;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mapping() {
|
public void mapping() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
reader = new BufferedReader(new FileReader("assets/map.txt")); // Einlesen der .txt Datei
|
reader = new BufferedReader(new FileReader("assets/Maps/" + selectedMap)); // Einlesen der .txt Datei
|
||||||
|
|
||||||
|
System.out.println(selectedMap);
|
||||||
|
|
||||||
for (int i = 0; i < 35; i++) { // für die ersten 35 Zeilen der Datei:
|
for (int i = 0; i < 35; i++) { // für die ersten 35 Zeilen der Datei:
|
||||||
String line = reader.readLine(); // Einlesen der jeweiligen Zeile
|
String line = reader.readLine(); // Einlesen der jeweiligen Zeile
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JComboBox;
|
import javax.swing.JComboBox;
|
||||||
|
@ -9,6 +12,8 @@ import javax.swing.JTextField;
|
||||||
|
|
||||||
public class MapMenu extends JFrame {
|
public class MapMenu extends JFrame {
|
||||||
|
|
||||||
|
public boolean rdy;
|
||||||
|
|
||||||
JButton button;
|
JButton button;
|
||||||
|
|
||||||
JPanel panel;
|
JPanel panel;
|
||||||
|
@ -21,17 +26,26 @@ public class MapMenu extends JFrame {
|
||||||
|
|
||||||
Game game;
|
Game game;
|
||||||
|
|
||||||
|
String selectedMap;
|
||||||
|
|
||||||
public MapMenu() {
|
public MapMenu() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
super("Map Menu");
|
super("Map Menu");
|
||||||
|
|
||||||
|
System.setProperty("sun.java2d.opengl", "true");
|
||||||
|
|
||||||
path = new File("assets/maps");
|
path = new File("assets/maps");
|
||||||
|
|
||||||
maps = path.list();
|
maps = path.list();
|
||||||
|
|
||||||
|
for (int i = 0; i < maps.length; i++) {
|
||||||
|
maps[i] = maps[i].substring(0, maps[i].length() - 4);
|
||||||
|
}
|
||||||
|
|
||||||
this.setVisible(true);
|
this.setVisible(true);
|
||||||
this.setBounds(100, 100, 300, 200);
|
this.setBounds(100, 100, 300, 200);
|
||||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
this.setResizable(false); // Man kann die Größe des Frame nicht verändern
|
this.setResizable(false); // Man kann die Größe des Frame nicht verändern
|
||||||
|
|
||||||
panel = new JPanel(); // Panel auf dem visuellen Elemente angezeigt werden
|
panel = new JPanel(); // Panel auf dem visuellen Elemente angezeigt werden
|
||||||
|
@ -40,16 +54,34 @@ public class MapMenu extends JFrame {
|
||||||
this.setContentPane(panel);
|
this.setContentPane(panel);
|
||||||
this.getContentPane().setLayout(null);
|
this.getContentPane().setLayout(null);
|
||||||
|
|
||||||
|
|
||||||
button = new JButton("Lauch dat shit");
|
button = new JButton("Lauch dat shit");
|
||||||
panel.add(button);
|
panel.add(button);
|
||||||
button.setBounds(20, 100, 150, 30);
|
button.setBounds(20, 100, 150, 30);
|
||||||
|
button.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent evt) {
|
||||||
|
try {
|
||||||
|
button_ActionPerformed(evt);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
bob = new JComboBox(maps);
|
bob = new JComboBox(maps);
|
||||||
// bob.setEditable(true);
|
|
||||||
panel.add(bob);
|
panel.add(bob);
|
||||||
bob.setBounds(30, 30, 180, 30);
|
bob.setBounds(30, 30, 180, 30);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getSelectedMap() {
|
||||||
|
return selectedMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Was passieren soll, wenn der Button gedrückt wird
|
||||||
|
public void button_ActionPerformed(ActionEvent evt) throws SQLException {
|
||||||
|
selectedMap = String.valueOf(bob.getSelectedItem());
|
||||||
|
System.out.println(selectedMap + " is now the selected Map!");
|
||||||
|
rdy = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue