??????????д??С??????????????????????????????????????????????????н??л???????壬?????????????????????????????

???????????£?
import java.awt.*;
import java.awt.event.*;
import java.util.List;
import java.util.ArrayList;
public class SnakeClient extends Frame {
/**
* ????????????
* ???????????????????
* 0.4????????????
*/
private static final long serialVersionUID = 1L;
private static int WIDTH=406??HEIGHT=428;
List<Snake> snakes=new ArrayList<Snake>();
List<Egg> eggs=new ArrayList<Egg>();
Snake s=new Snake(3??25??true??0??this);
Snake body1=new Snake(3??45??false??1??this);
Snake body2=new Snake(3??65??false??2??this);
boolean eat=false;
Egg e=new Egg();
public static void main(String []args){
SnakeClient sc=new SnakeClient();
sc.launchFrame();
}
void launchFrame(){
this.setBounds(100?? 100?? WIDTH?? HEIGHT);
this.setVisible(true);
this.setResizable(false);
this.addWindowListener(new WinCloseMonitor());
//      bug2 :???????????????·????????
this.addKeyListener(new KeyMonitor());
new Thread(new MyThread()).start();
snakes.add(s);
eggs.add(e);
}
class WinCloseMonitor extends WindowAdapter{
//      bug1 ???windowClosing д??WindowClosing
//      ?????д???????????????Eclipse????д????
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
public void paint(Graphics g){
for(int i=0;i<snakes.size();i++){
Snake sn=snakes.get(i);
if(s.hitSnake(sn)&&!sn.head){
snakes.removeAll(snakes);
return;
}
sn.draw(g);
if(sn.eatEgg(e)) eat=true;
}
if(eat){
snakes.add(new Snake(snakes.get(snakes.size()-1).oldX??snakes.get(snakes.size()-1).oldY??
false??snakes.size()??this));
eat=false;
eggs.remove(e);
e=new Egg();
eggs.add(e);
}
e.draw(g);
}
class MyThread implements Runnable{
@Override
public void run() {
while(true){
repaint();
try {
Thread.sleep(350);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
class KeyMonitor extends KeyAdapter{
@Override
public void keyPressed(KeyEvent e) {
s.keyPressed(e);
}
}
}