mapmenu fertiggestellt
parent
c137c9080a
commit
671bfa3748
|
@ -1,4 +1,3 @@
|
|||
Ms Pac-Man
|
||||
############################
|
||||
# ## ## #
|
||||
#.#### ## ######## ## ####.#
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
/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[] 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?)
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
map = new Map(player, ghosts); // Map auf der gespielt wird
|
||||
map = new Map(selectedMap, player, ghosts); // Map auf der gespielt wird
|
||||
map.mapping();
|
||||
|
||||
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");
|
||||
|
||||
// Game game = new Game(); // Das Spiel wird gestartet
|
||||
// Game game = new Game("map1.txt"); // Das Spiel wird gestartet
|
||||
|
||||
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
|
@ -24,20 +24,26 @@ public class Map {
|
|||
|
||||
public static int pac_posX;
|
||||
public static int pac_posY;
|
||||
|
||||
String selectedMap;
|
||||
|
||||
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.player = player;
|
||||
|
||||
this.selectedMap = selectedMap;
|
||||
|
||||
}
|
||||
|
||||
public void mapping() {
|
||||
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:
|
||||
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.sql.SQLException;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
|
@ -8,30 +11,41 @@ import javax.swing.JPanel;
|
|||
import javax.swing.JTextField;
|
||||
|
||||
public class MapMenu extends JFrame {
|
||||
|
||||
public boolean rdy;
|
||||
|
||||
JButton button;
|
||||
|
||||
JPanel panel;
|
||||
|
||||
|
||||
JComboBox bob;
|
||||
|
||||
|
||||
String[] maps;
|
||||
|
||||
|
||||
File path;
|
||||
|
||||
|
||||
Game game;
|
||||
|
||||
String selectedMap;
|
||||
|
||||
public MapMenu() {
|
||||
|
||||
|
||||
|
||||
super("Map Menu");
|
||||
|
||||
System.setProperty("sun.java2d.opengl", "true");
|
||||
|
||||
path = new File("assets/maps");
|
||||
|
||||
|
||||
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.setBounds(100, 100, 300, 200);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setResizable(false); // Man kann die Größe des Frame nicht verändern
|
||||
|
||||
panel = new JPanel(); // Panel auf dem visuellen Elemente angezeigt werden
|
||||
|
@ -39,17 +53,35 @@ public class MapMenu extends JFrame {
|
|||
// Der Inhalt des Panels wird auf dem Frame angezeigt:
|
||||
this.setContentPane(panel);
|
||||
this.getContentPane().setLayout(null);
|
||||
|
||||
|
||||
|
||||
button = new JButton("Lauch dat shit");
|
||||
panel.add(button);
|
||||
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.setEditable(true);
|
||||
panel.add(bob);
|
||||
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