一个简单的推箱子游戏
public class GameFrame extends JFrame implements ActionListener, MouseListener, KeyListener {
private int grade = 0;
private int manY = 7, manX = 7, leftX = 0, leftY = 0;
private int mapRow = 0, mapColumn = 0;
private int width = 0, height = 0;
private boolean acceptKey = true;
private Image pic[] = null;
private byte[][] map = null;
private ArrayList list = new ArrayList();
Sound sound;
// 墙,箱子, 在目的地的箱子, 目的地, 四个方向的人, 通道 , 在目的地四个方向的人
final byte WALL = 1;
final byte BOX = 2;
final byte BOX_ON_END = 3;
final byte END = 4;
final byte MAN_DOWN = 5;
final byte MAN_LEFT = 6;
final byte MAN_RIGHT = 7;
final byte MAN_UP = 8;
final byte GRASS = 9;
final byte MAN_DOWN_ON_END = 10;
final byte MAN_LEFT_ON_END = 11;
final byte MAN_RIGHT_ON_END = 12;
final byte MAN_UP_ON_END = 13;
public GameFrame() {
super("");
setSize(600, 600);
setVisible(true);
setResizable(false);
setLocation(300, 20);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cont = getContentPane();
cont.setLayout(null);
cont.setBackground(Color.black);
getPic();
width = getWidth();
height = getHeight();
setFocusable(true);
initMap();
addKeyListener(this);
addMouseListener(this);
sound = new Sound();
sound.loadSound();
}
。。。}
评论