import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/**
* 这个类代表贪吃蛇的活动场所
* @author 郭炜
* @version 1.0
*/
public class Yard extends Frame {
PaintThread paintThread = new PaintThread();
private boolean gameOver = false; //游戏是否结束
/**
* 行数
*/
public static final int ROWS = 30;
public static final int COLS = 30;
public static final int BLOCK_SIZE = 15;
private Font fontGameOver = new Font("宋体", Font.BOLD, 50);
private int score = 0;
Snake s = new Snake(this);
Egg e = new Egg();
Image offScreenImage = null;
public void launch() {
this.setLocation(200, 200);
this.setSize(COLS * BLOCK_SIZE, ROWS * BLOCK_SIZE);
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
this.setVisible(true);
this.addKeyListener(new KeyMonitor());
new Thread(paintThread).start();
}
public static void main(String[] args) {
new Yard().launch();
}
public void stop() {
gameOver = true;