简单贪吃蛇
来源:互联网 发布:我国外汇储备数据 编辑:程序博客网 时间:2024/04/30 00:49
public void showsnake(graphics g){//globeinfo.snake为vector类型
int num=globeinfo.snake.size();
int left=(w-grid*globeinfo.gridxnum)/2;
int top=h-grid*globeinfo.gridynum-space*2;
g.setcolor(0,0,255);
for(int i=0;i<num;i++){
point point=(point)globeinfo.snake.elementat(i);
if(point.x>=0&&point.y>=0){
int l=left+point.x*grid;
int t=top+point.y*grid;
g.fillrect(l, t, grid, grid);
}
}
}
public void movesnake(){//point 为一个格式点的数据结构(x,y)
point pointtail=(point)globeinfo.snake.elementat(0);
point pointhead=(point)globeinfo.snake.elementat(globeinfo.snake.size()-1);
point point=new point(-1, -1);
if(direct.right){
point.x=pointhead.x+1;
point.y=pointhead.y;
if(point.x>=globeinfo.gridxnum)
end=true;
} else if(direct.left){
point.x=pointhead.x-1;
point.y=pointhead.y;
if(point.x<0)
end=true;
} else if(direct.up){
point.x=pointhead.x;
point.y=pointhead.y-1;
if(point.y<0)
end=true;
} else if(direct.down){
point.x=pointhead.x;
point.y=pointhead.y+1;
if(point.y>=globeinfo.gridynum)
end=true;
}
for(int i=0;i<globeinfo.snake.size();i++){
point pointother=(point)globeinfo.snake.elementat(i);
if(pointother.x==point.x&&pointother.y==point.y){
end=true;
break;
}
}
if(end==false&&globeinfo.snake.size()>0){
if(point.x==eatx && point.y==eaty){
eat=false;
show=true;
globeinfo.snake.addelement(point);
globeinfo.money+=100;
num++;
if(num>=globeinfo.levelnum)
end=true;
} else{
globeinfo.snake.removeelementat(0);
globeinfo.snake.addelement(point);
}
} else{
timer.cancel();
}
servicerepaints();
}
public void randomeat(){
if(eat==false){
random rand=new random();
boolean product=false;
while(product==false){
int x=rand.nextint(globeinfo.gridxnum);
int y=rand.nextint(globeinfo.gridynum);
int i;
for(i=0;i<globeinfo.snake.size();i++){
point point=(point)globeinfo.snake.elementat(i);
if(point.x==x&&point.y==y)
break;
}
if(i==globeinfo.snake.size()){
eatx=x;
eaty=y;
eat=true;
product=true;
}
}
}
}
- 简单的贪吃蛇
- 简单贪吃蛇
- 简单的贪吃蛇
- 贪吃蛇简单小游戏
- 简单贪吃蛇
- java 简单贪吃蛇
- 简单的贪吃蛇
- 贪吃蛇的简单实现
- 简单的贪吃蛇游戏
- python 贪吃蛇(简单)
- C++ 简单贪吃蛇游戏
- C++简单贪吃蛇实现
- QT 简单编写贪吃蛇
- android实现简单贪吃蛇
- 控制台的简单贪吃蛇
- Unity实现简单贪吃蛇
- 简单的Android贪吃蛇
- 一个简单的贪吃蛇
- Java ME应用设计指南之联网重定向
- java内存的思考与总结
- 在 Ubuntu Linux 上安装 Java 和 Eclipse
- 最佳的麻将数据结构
- 音乐播放类
- 简单贪吃蛇
- 按键事件的处理
- 图象的放缩与透明处理
- 成为富人25种方法
- #include time.h和 #include sys/time.h的区别
- 嵌入式linux启动信息完全注释
- 研究伽玛概率密度函数
- 今天,我被降薪了!
- ghost 步骤