????? Java?棨????GUI??
???????????? ???????[ 2014/7/22 10:34:35 ] ????????????? Java
import java.awt.*;
import java.awt.event.KeyEvent;
public class Snake {
int x??y??oldX??oldY;
int id;
private static int WIDTH=20??HEIGHT=20??dx=20??dy=20;
static Direction dir=Direction.STOP;
boolean head;//?ж???????????
SnakeClient sc=null;
private boolean live;
public Snake(int x?? int y?? boolean head??int id??SnakeClient sc) {
this.x = x;
this.y = y;
this.head = head;
this.id=id;
this.sc=sc;
}
void draw(Graphics g){
move();
Color c=g.getColor();
if(head){
g.setColor(Color.red);
}else{
g.setColor(Color.green);
}
g.fillRect(x?? y?? WIDTH?? HEIGHT);
g.setColor(Color.black);
g.drawRect(x?? y?? WIDTH?? HEIGHT);
g.setColor(c);
}
public void keyPressed(KeyEvent e) {
if(!head) return;
int key=e.getKeyCode();
switch(key){
case KeyEvent.VK_UP:
if(Direction.D==dir) break;
dir=Direction.U;
break;
case KeyEvent.VK_DOWN:
if(Direction.U==dir) break;
dir=Direction.D;
break;
case KeyEvent.VK_LEFT:
if(Direction.R==dir) break;
dir=Direction.L;
break;
case KeyEvent.VK_RIGHT:
if(Direction.L==dir) break;
dir=Direction.R;
break;
case KeyEvent.VK_F2:
if(!live){
sc.snakes.add(sc.s);
}
}
}
// ?????????β???id??0??????????id?????????????????£?????μ??λ??oldX??oldY
// ??move()???????id-1?????????????λ???
void move(){
oldX=x;
oldY=y;
if(!head){
if(dir==Direction.STOP) return;
for(int i=0;i<sc.snakes.size();i++){
if(sc.snakes.get(i).id==id-1){
x=sc.snakes.get(i).oldX;
y=sc.snakes.get(i).oldY;
}
}
return;
}
switch(dir){
case U:
y-=dy;
break;
case R:
x+=dx;
break;
case D:
y+=dy;
break;
case L:
x-=dx;
break;
case STOP:
break;
}
//?°????????????????????????????
if(x<3) x=383;
if(x>383) x=3;
if(y<25) y=405;
if(y>405) y=25;
}
public Rectangle getRect(){
return new Rectangle(x??y??WIDTH-1??HEIGHT-1);
}
boolean eatEgg(Egg e){
if(!head) {
return false;
}
else{
return e.getRect().intersects(this.getRect());
}
}
boolean hitSnake(Snake s){
if(!head) return false;
if(s.getRect().intersects(this.getRect())){
live = false;
return true;
}else{
return false;
}
}
}
[java] view plaincopy
import java.awt.*;
import java.util.*;
public class Egg {
private static int WIDTH=20??HEIGHT=20;
private static Random r=new Random();
int x=3+20*r.nextInt(20);
int y=25+20*r.nextInt(20);
void draw(Graphics g){
Color c=g.getColor();
g.setColor(Color.pink);
g.fillOval(x?? y?? WIDTH?? HEIGHT);
g.setColor(c);
}
public Rectangle getRect(){
return new Rectangle(x??y??WIDTH??HEIGHT);
}
}
|
public enum Direction {
U??R??D??L??STOP;
}
|
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
Java???????????Щ???????????????Java????????????????Java?б???Map????????Java Web???????????????Java??????????????д?????Java????????7???????????????????????(java .net ?????)???Java??????????Python??????Java webdriver??λ????????′????е?????Java??д??????????????????Java???????????????JavaScript????????????Java?????????????????? Java???????10??????????????Java?м????????????????java???????ü???????????м???????????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????