所以,我有一个敌人,当它死亡时,它需要被删除。所以,在该类的基类中,我试图放入一个删除第一个类的函数,但是我在传递对类的引用时遇到了麻烦。我如何传递引用或者是否有其他方法可以删除更好的类?
请问您是否需要澄清,因为我无法解释这一点。
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
if (currentHealth <= 0)
{
alive = false;
//This is not working \/
killswitch(ref Game1.ant1);
//Kills bug and gives out loot etc.
}
else if (position == house1 || position == house2 || position == house3 || position == house4
|| position == house5 || position == house6 || position == house7 || position == house8
|| position == house9 || position == house10 || position == house11 || position == house12)
{
killswitch(ref Game1.ant1);
}
public void killswitch(ref Ant ant1)
{
//This is where loot is given
Global.money += bountyGiven;
//delete class code here
}
答案 0 :(得分:1)
Public Class Ant
public position as vector2
public health as integer = 100
public isdead ad boolean = false
End class
Public Class Ants
Inherit list (of Ant)
Public Sub AddAnt(Position)
// add new ant to list
End Sub
Public Sub Update()
For Each ant As ant In ants
If Not(ant.isdead)
// update ants
End If
Next
Me.RemoveAll(function(c) c.isdead = true)
End Sub
Public Sub Draw()
For Each ant As ant In ants
If not(ant.isdead)
// draw ants
End If
Next
End Sub
End class