plenderj
Mar 5th, 2001, 07:52 AM
Howdy.
Im learning Java at the moment, and I'm making a maze game, in which, imaginatively enough, the user has to try and solve mazes.
Anyway, I'm trying to do the userinput part, all I really need is up down left and right, but I'm not sure how to get keyboard events.
I also need the app to get input from the map.txt file, which contains vertices in the maze.
The file is in the format :
MazeName :My maze
Vertices :1
Vertex :4000,3200,2000,1000
MazeName :My maze2
Vertices :2
Vertex :1600,1600,1600,3000
Vertex :2400,1600,2400,3000
This is the code im using :
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class Maze extends Frame {
static int NumVertices = 128;
static myVertex[] Vertex = new myVertex[129];
static Frame f = new Maze();
public static void main(String[] args) {
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
f.addKeyListener(new KeyAdapter() {
private void processKeyEvent(KeyEvent e) {
f.setTitle("testing");
}
});
f.setSize(300,300);
f.setResizable(false);
f.setBackground(Color.white);
f.setVisible(true);
//f.setTitle("Maze");
}
public void paint(Graphics g) {
g.setColor(Color.red);
for (int i = 0 ; i <= NumVertices ; i++) {
g.drawLine(Vertex[i].x1, Vertex[i].y1, Vertex[i].x2, Vertex[i].y2);
}
}
}
class myVertex {
int x1;
int y1;
int x2;
int y2;
}
Any help is much oblidged.
Thanks,
jamie.
Im learning Java at the moment, and I'm making a maze game, in which, imaginatively enough, the user has to try and solve mazes.
Anyway, I'm trying to do the userinput part, all I really need is up down left and right, but I'm not sure how to get keyboard events.
I also need the app to get input from the map.txt file, which contains vertices in the maze.
The file is in the format :
MazeName :My maze
Vertices :1
Vertex :4000,3200,2000,1000
MazeName :My maze2
Vertices :2
Vertex :1600,1600,1600,3000
Vertex :2400,1600,2400,3000
This is the code im using :
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class Maze extends Frame {
static int NumVertices = 128;
static myVertex[] Vertex = new myVertex[129];
static Frame f = new Maze();
public static void main(String[] args) {
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
f.addKeyListener(new KeyAdapter() {
private void processKeyEvent(KeyEvent e) {
f.setTitle("testing");
}
});
f.setSize(300,300);
f.setResizable(false);
f.setBackground(Color.white);
f.setVisible(true);
//f.setTitle("Maze");
}
public void paint(Graphics g) {
g.setColor(Color.red);
for (int i = 0 ; i <= NumVertices ; i++) {
g.drawLine(Vertex[i].x1, Vertex[i].y1, Vertex[i].x2, Vertex[i].y2);
}
}
}
class myVertex {
int x1;
int y1;
int x2;
int y2;
}
Any help is much oblidged.
Thanks,
jamie.