Hey guys, I am having trouble with my java pacman game. What I have currently is the basics. I am reading in my maze from a txt file which is working. I am stumpted on how to replace the W for my walls with my jpeg of a blue wall(imgGhost in this case). Can anyone point me in the right direction ? I have attached my maze.txt to demonstrate.
Thanks in advance.
Here is my code so far:
import java.awt.*;
import javax.swing.*;
import java.io.*;
public class pacman3 extends JFrame {
private static final long serialVersionUID = 1L;
private static final Dimension WindowSize = new Dimension(600,600);
private Image imgGhost;
private ImageIcon icon;
public pacman3() {
this.setTitle("Pacman, or something..");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBackground(Color.BLACK);
Dimension screensize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
int x = screensize.width/2 - WindowSize.width/2;
int y = screensize.height/2 - WindowSize.height/2;
setBounds(x, y, WindowSize.width, WindowSize.height);
setVisible(true);
icon = new ImageIcon("C:/Ghost1.png");
imgGhost = icon.getImage();
repaint();
}
public void paint(Graphics g) {
g.setFont(new Font("Courier New", Font.PLAIN, 18));
g.setColor(Color.WHITE);
int ypos = 45;
String line=null;
try {
BufferedReader reader = new BufferedReader(new
FileReader("C:/maze.txt"));
do {
try {
if(line !=null && line.startsWith("#")){
}
else if(line !=null){
g.drawString(line, 20, ypos);
ypos += 20;
}
line = reader.readLine();
} catch (IOException e) { }
}
while (line != null);
try {
reader.close();
} catch (IOException e) { }
} catch (FileNotFoundException e) { }
}
public static void main(String [ ] args) {
pacman3 w = new pacman3();
}
}