Beispiel #1
0
        //List<PlayerTank> listPlayerTank = new List<PlayerTank>();

        /// <summary>
        /// 添加游戏对象
        /// </summary>
        /// <param name="go"></param>
        public void AddGameObject(GameObject go)
        {
            if (go is PlayerTank)
            {
                PT = go as PlayerTank;
            }
        }
Beispiel #2
0
 /// <summary>
 /// 添加游戏对象
 /// </summary>
 /// <param name="go"></param>
 public void AddGameObject(GameObject go)
 {
     if (go is PlayerTank)
     {
         PT = go as PlayerTank;
     }
     else if (go is EnemyTank)
     {
         listEnemyTank.Add(go as EnemyTank);
     }
     else if (go is PlayerBullet)
     {
         listPlayerBullet.Add(go as PlayerBullet);
     }
 }
Beispiel #3
0
        //is 和 as 操作

        /*
         * In general, the as operator is more efficient because it actually returns the cast value
         * if the cast can be made successfully. The is operator returns only a Boolean value.
         * It can therefore be used when you just want to determine an object's type but do not have
         * to actually cast it.
         */
        //第二步 添加游戏对象
        public bool AddGameObject(GameObject go)
        {
            if (go is PlayerTank)
            {
                PT = go as PlayerTank;
                return(true);
            }
            else if (go is EnemyTank)
            {
                listEnemyTank.Add(go as EnemyTank);
                return(true);
            }
            else if (go is EnemyBullet)
            {
                //一次只能连发两颗子弹
                if (listEnemyBullet.Count() <= 1)
                {
                    listEnemyBullet.Add(go as EnemyBullet);
                    return(true);
                }
            }
            else if (go is PlayerBullet)
            {
                //一次只能连发两颗子弹
                if (listPlayerBullet.Count() <= 1)
                {
                    listPlayerBullet.Add(go as PlayerBullet);
                    return(true);
                }
            }
            else if (go is Boom)
            {
                listBoom.Add(go as Boom);
                return(true);
            }
            else if (go is SmallBoom)
            {
                listSmallBoom.Add(go as SmallBoom);
                return(true);
            }
            else if (go is TankBorn)
            {
                listTankBorn.Add(go as TankBorn);
                return(true);
            }
            else if (go is Blood)
            {
                listBlood.Add(go as Blood);
                return(true);
            }
            else if (go is Wall)
            {
                listWall.Add(go as Wall);
                return(true);
            }
            else if (go is Grass)
            {
                listGrass.Add(go as Grass);
                return(true);
            }
            else if (go is SteelWall)
            {
                listSteelWall.Add(go as SteelWall);
                return(true);
            }
            else if (go is Water)
            {
                listWater.Add(go as Water);
                return(true);
            }
            else if (go is Symbol)
            {
                listSymbol.Add(go as Symbol);
                return(true);
            }
            return(false);
        }