1、 /坦克的高度 private int top; /坦克位置的纵坐标 private int left; /坦克位置的横坐标 private int type; /坦克的类型(2-5敌方,6己方) private int direct; /0-上,1-下,2-左,3-右 public ArrayList bList=new ArrayList();/子弹序列 public Tank(int tank_type)/构造函数 Random r = new Random(); this.direct = r.Next(0, 4);/产生03的数 this.width = 32; this.heigh
2、t = 32; this.left = r.Next(0, 1);/产生09的数 this.top = r.Next(0, 1); this.type = tank_type; public int Top/Top属性 get return top; set if (top = 0 & top left =0; i-)/遍历子弹序列 /for (int i = 0; i bList.Count;i+ ) bullet t = (bullet)bListi); /移动以前 if (t.Left 9 | t.Top 9) /超出边界 bList.RemoveAt(i); continue;/删除此
3、颗子弹 if (Mapt.Left, t.Top ! Mapt.Left, t.Top!= this.type ) /已遇到坦克和墙等障碍物 if (t.hitE(Mapt.Left, t.Top)/击中对方坦克 Mapt.Left, t.Top = -1;/此处坦克被打中 t.move();/移动以后 0 |t.Top continue;= 0)/已遇到物体 public void DrawBullet(Graphics g,int ,Map)/画子弹 MoveBullet(ref Map); foreach (bullet t in bList)/遍历子弹序列 t.Draw(g); /public void NewPosition()/产生新坐标 / / Random r = new Random(); / this.left = r.Next(0, 10); / this.top = r.Next(0, 10); / /public bool ComparePosition(Tank s)/比较坦克位置 / if (this.left = s.left & this.top = s.top) / return true; / else / return false; /