设为首页 加入收藏

TOP

Java实现支持双黑两人激战的 坦克大战源码(经典游戏)(五)
2014-11-24 01:43:08 来源: 作者: 【 】 浏览:5
Tags:Java 实现 支持 双黑两 激战 坦克 大战 源码 经典游戏
case 4:g.setColor(color);paintLeftTank(x,y,g);break;
}
}
}
/**纯画图打造坦克*/
public void paintUpTank(int x,int y,Graphics g){
g.fill3DRect(x, y, 15, 50, false);
g.fill3DRect(x+35, y, 15, 50, false);
g.fill3DRect(x+15, y+10, 20, 30, false);
g.setColor(Color.black);
g.fill3DRect(x+23, y-10, 5, 33, false);
g.setColor(Color.yellow);
g.fillOval(x+20, y+18, 10, 10);
}
public void paintLeftTank(int x,int y,Graphics g){
g.fill3DRect(x, y, 50, 15, false);
g.fill3DRect(x, y+35, 50, 15, false);
g.fill3DRect(x+10, y+15, 30, 20, false);
g.setColor(Color.black);
g.fill3DRect(x-10, y+22, 33, 5, false);
g.setColor(Color.yellow);
g.fillOval(x+20, y+18, 10, 10);
}
public void paintDownTank(int x,int y,Graphics g){
g.fill3DRect(x, y, 15, 50, false);
g.fill3DRect(x+35, y, 15, 50, false);
g.fill3DRect(x+15, y+10, 20, 30, false);
g.setColor(Color.black);
g.fill3DRect(x+23, y+25, 5, 33, false);
g.setColor(Color.yellow);
g.fillOval(x+20, y+18, 10, 10);
}
public void paintRightTank(int x,int y,Graphics g){
g.fill3DRect(x, y, 50, 15, false);
g.fill3DRect(x, y+35, 50, 15, false);
g.fill3DRect(x+10, y+15, 30, 20, false);
g.setColor(Color.black);
g.fill3DRect(x+23, y+22, 33, 5, false);
g.setColor(Color.yellow);
g.fillOval(x+20, y+18, 10, 10);
}
/**重新开始游戏的时候会清空子弹数组里面的数据*/
public void cleanShoot(){
for (int i = 0; i < Shoot.enemyShoot.length; i++) {
Shoot.enemyShoot[i]=0;
}
for (int i = 0; i < Shoot.myShoot.length; i++) {
Shoot.myShoot[i]=0;
}
}
/**子弹消失了*/
public void ShootDispeal(){
for (int i = 0; i < Shoot.myShoot.length; i+=4) {//撞到边缘
if(Shoot.myShoot[i]<0||Shoot.myShoot[i]>WIDTH||Shoot.myShoot[i+1]<0||Shoot.myShoot[i+1]>HEIGHT){
Shoot.myShoot[i]=0;Shoot.myShoot[i+1]=0;
Shoot.myShoot[i+2]=0;Shoot.myShoot[i+3]=0;
shootNum++;
shootNum1++;
}
int x=Shoot.myShoot[i];
int y=Shoot.myShoot[i+1];
//撞到柱子
if((x>330&&x<360&&y>150&&y<380)||(x>130&&x<570&&y>240&&y<280)){
Shoot.myShoot[i]=0;Shoot.myShoot[i+1]=0;
Shoot.myShoot[i+2]=0;Shoot.myShoot[i+3]=0;
shootNum++;
shootNum1++;
}
}
for (int i = 0; i < Shoot.enemyShoot.length; i+=4) {//撞到边缘
if(Shoot.enemyShoot[i]<0||Shoot.enemyShoot[i]>WIDTH||Shoot.enemyShoot[i+1]<0||Shoot.enemyShoot[i+1]>HEIGHT){
Shoot.enemyShoot[i]=0;Shoot.enemyShoot[i+1]=0;
Shoot.enemyShoot[i+2]=0;Shoot.enemyShoot[i+3]=0;
}
int x=Shoot.enemyShoot[i];
int y=Shoot.enemyShoot[i+1];
//撞到柱子
if((x>330&&x<360&&y>150&&y<380)||(x>130&&x<570&&y>240&&y<280)){
Shoot.enemyShoot[i]=0;Shoot.enemyShoot[i+1]=0;
Shoot.enemyShoot[i+2]=0;Shoot.enemyShoot[i+3]=0;
}
}
}
}



/********************Tanks类***********************/


package tank;
import java.util.Random;
/**坦克父类,继承了线程*/
public class Tanks extends Thread{
private int x;//坦克坐标x
private int y;//坦克坐标y
private int step;//坦克的速度
private int direct;//方向,1表示向上,2表示向右,3表示向下,4表示向左
private int who;//坦克标识,0和-1表示自己的坦克,1,2,3表示敌人的坦克,颜色随机.
private boolean isLive = true;//判断坦克是否死亡
Shoot shoot;//shoot坦克的射击
public Tanks(int x, int y, int step, int direct,int who ,boolean isLive) {
super();
this.x = x;
this.y = y;
this.step = step+2;
this.direct = direct;
this.who = who;
this.isLive = isLive;
}
public boolean canMove(){//boolean返回值类型.判断坦克是否能移动,比如撞墙了.
if(x<0){
x=0;
return false;
}else if(x>690){

首页 上一页 2 3 4 5 6 下一页 尾页 5/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android.mk文件中的功能宏介绍 下一篇Android.mk中系统变量的介绍

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: