Ejemplo n.º 1
0
 private Game()
 {
     //const int VERTICAL = 13;              //纵向格数
         Element.width = width;              //每一格的宽度
         map = new Barrier[CROSS, CROSS];    //定义游戏数组
         p1Tank = tankFactory.factory(TankType.PlayerTank, 10, 10);
         AddElement(p1Tank);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 添加对象
 /// </summary>
 /// <param name="e">要添加的对象</param>
 public void AddElement(Element e)
 {
     if (e is Bullet)
     {
         bullets.Add(e as Bullet);
     }
     else if (e is PlayerTank)
     {
         playerTanks.Add(e as PlayerTank);
     }
     else if (e is EnemyTank)
     {
         enemyTanks.Add(e as EnemyTank);
     }
     else if (e != null)
     {
         map[e.PosX, e.PosY] = e as Barrier;
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 检测对象是否死亡,如死亡则移除
 /// </summary>
 /// <param name="ele">要检测的对象</param>
 private bool IsDead(Element ele)
 {
     if (ele.Blood <= 0)
     {
         ele.Boom();
         if (ele is Bullet)  //子弹直接爆炸
         {
             this.RemoveElement(ele);
             return true;
         }
         if (ele.IsDead)
         {
             this.RemoveElement(ele);
             return true;
         }
         ele.IsDead = true;
         return false;
     }
     return false;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 检查对象是否可以继续移动
 /// </summary>
 /// <param name="ele">要检查的对象</param>
 /// <returns>如果可以移动返回true</returns>
 private bool IsCanMove(Element ele)
 {
     if (ele is Bullet)
     {
         switch (ele.EleDirection)
         {
             case Direction.Up:
                 if (ele.PosY <= 0 )
                     return false;
                 break;
             case Direction.Down:
                 if (ele.PosY >= CROSS - 1 )
                     return false;
                 break;
             case Direction.Right:
                 if (ele.PosX >= CROSS - 1 )
                     return false;
                 break;
             case Direction.Left:
                 if (ele.PosX <= 0 )
                     return false;
                 break;
             default:
                 break;
         }
         return true;
     }
     if (ele.IsDead)
     {
         return false;
     }
     switch (ele.EleDirection)
     {
         case Direction.Up:
             if (ele.PosY <= 0 || map[ele.PosX, ele.PosY - 1] != null && map[ele.PosX, ele.PosY - 1].IsCanCross==false)
                 return false;
             break;
         case Direction.Down:
             if (ele.PosY >= CROSS - 1 || map[ele.PosX, ele.PosY + 1] != null && map[ele.PosX, ele.PosY + 1].IsCanCross == false)
                 return false;
             break;
         case Direction.Right:
             if (ele.PosX >= CROSS - 1 || map[ele.PosX + 1, ele.PosY] != null && map[ele.PosX + 1, ele.PosY].IsCanCross == false)
                 return false;
             break;
         case Direction.Left:
             if (ele.PosX <= 0 || map[ele.PosX - 1, ele.PosY] != null && map[ele.PosX - 1, ele.PosY].IsCanCross == false)
                 return false;
             break;
         default:
             break;
     }
     return true;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 删除对象
 /// </summary>
 /// <param name="e"></param>
 public void RemoveElement(Element e)
 {
     if (e is Bullet)
     {
         bullets.Remove(e as Bullet);
     }
     else if (e is PlayerTank)
     {
         playerTanks.Remove(e as PlayerTank);
     }
     else if (e is EnemyTank)
     {
         enemyTanks.Remove(e as EnemyTank);
     }
     else if (e!=null)
     {
         map[e.PosX, e.PosY] = null;
     }
 }