Android项目--坦克大战

要求

项目的内容主要实现我方坦克与敌方坦克进行对打,消灭对方坦克则成功,相反则游戏失败,完成对我方坦克的移动攻击以及相关的随机道具对坦克进行强化,敌方坦克也进行道具的获取和强化,游戏分为四个难度可以使用的坦克类型也不相同。对于的坦克的造型以及道具的UI的选取就很重要,对于炮弹对敌人造成的伤害以及不同难度下自己所受到的伤害都有所不同,不同的坦克的护甲血量以及攻击力也不相同,对应的不同的难度的敌人的AI也更加的智能伤害也随着难度的增加而增加,并且还增加了蓝牙对战的功能好友安装了游戏的话,双人可以进行对战。

基础代码

public class Tank {
   
   private Point centerPoint;
   
   
   private Point pp=new Point();
   
   private int speed=GamePanel.UNIT;
   
   private int  flag=0;//坦克敌我标志
   
   private int screenHeight;
   
   private int screenWidth;
   
   private Bitmap tankBmp ;

   
   private int direction=GamePanel.UP;
   
   public Matrix m=new Matrix();
   
   private long lastTrunTime;
   
   private int column;//坦克所占行数
   private int row;//坦克所占列数
   
   
   public Tank(){
      
   }
   public Tank(Point p){
      this.centerPoint=p;
   }
   public Tank(BitmapDrawable tankDrawable,int flag){
      centerPoint=new Point(200, 350);
      this.flag=flag;
      this.tankBmp=tankDrawable.getBitmap();
      pp.setY(centerPoint.getY());
      pp.setX(centerPoint.getX()+tankBmp.getWidth()/2);
      column=tankBmp.getWidth()/GamePanel.UNIT;
      row=tankBmp.getHeight()/GamePanel.UNIT;
   }
   public Tank(BitmapDrawable tankDrawable,Point p,int flag,int direction,int h,int w){
      this.flag=flag;
      this.tankBmp=tankDrawable.getBitmap();
      m.postRotate((direction-GamePanel.UP)*90);
      tankBmp=Bitmap.createBitmap(tankBmp, 0, 0, tankBmp.getWidth(), tankBmp.getHeight(), m, true);
      this.direction=direction;
      this.centerPoint=p;
      pp.setY(centerPoint.getY());
      pp.setX(centerPoint.getX()+tankBmp.getWidth()/2);
      this.screenHeight=h;
      this.screenWidth=w;
      column=tankBmp.getWidth()/GamePanel.UNIT;
      row=tankBmp.getHeight()/GamePanel.UNIT;
   }
   
   public void setScreenHeight(int h){
      screenHeight=h;
   }
   public void setScreenWidth(int w){
      screenWidth=w;
   }
   /**
    * 重新初始化炮筒的坐标点
    */
   private void resetFrontPoint(){
      if(direction==GamePanel.UP){
         pp.setY(centerPoint.getY());
         pp.setX(centerPoint.getX()+tankBmp.getWidth()/2);
      }else if(direction==GamePanel.DOWN){
         pp.setY(centerPoint.getY()+tankBmp.getHeight());
         pp.setX(centerPoint.getX()+tankBmp.getWidth()/2);
      }else if(direction==GamePanel.LEFT){
         pp.setY(centerPoint.getY()+tankBmp.getHeight()/2);
         pp.setX(centerPoint.getX());
      }else if(direction==GamePanel.RIGHT){
         pp.setY(centerPoint.getY()+tankBmp.getHeight()/2);
         pp.setX(centerPoint.getX()+tankBmp.getWidth());
      }
   }
   private void resetTankPoint(){
      modifyMapStatus(0);//释放原有地图占位
      if(direction==GamePanel.UP){
         this.centerPoint.setY(centerPoint.getY()-speed);
      }else if(direction==GamePanel.DOWN){
         this.centerPoint.setY(centerPoint.getY()+speed);
      }else if(direction==GamePanel.LEFT){
         this.centerPoint.setX(centerPoint.getX()-speed);
      }else if(direction==GamePanel.RIGHT){
         this.centerPoint.setX(centerPoint.getX()+speed);
      }
      resetFrontPoint();
      modifyMapStatus(1);//重新进行地图占位
   }
   /** 
    * 修改地图状态
    */
   private void modifyMapStatus(int status){
      int bC=centerPoint.getX()/GamePanel.UNIT;
      int bR=centerPoint.getY()/GamePanel.UNIT;
   
      for(int i=bR;i

你可能感兴趣的:(周记)