1

我正在尝试在 C# + XNA 中制作一个简单的成就类,并且我想实现一个队列,以便当您快速获得多个成就时,后者将被添加到队列列表中。

这是为获得特定成就而调用的方法:

//This is the list that I want to add the achievements to be queued to
static List<Achievement> queueList;

public void GetAchievement()
{
        //If the player hasn't got the achievement yet and another achievement is NOT being drawn, get the achievement
        if (!got && !drawing)
            get = true;
        //If the player hasn't got the achievement yet and another achievement IS being drawn, add the achievement to the queue list
        else if (!got && drawing)
            queueList.Add(); //What do I do here?
 }

所以这将被称为:exampleAchievement.GetAchievement(); exampleAchievement 是Achievement 类的对象。

我只是不知道如何知道哪个对象正在调用 GetAchievement(),所以我不知道要向 queueList 添加什么。

任何帮助将不胜感激!

~卢卡

编辑:我用过:

queueList.Add(this);

但我只是愚蠢并且没有正确测试它,所以看起来没有任何东西被添加到列表中。无论如何感谢您的帮助:3

4

4 回答 4

2

你在找exampleAchievement例子吗?

queueList.Add(this);// is this you're looking for?

我错过了什么吗?

于 2013-10-14T13:30:51.137 回答
1

听起来您在要求this,它指的是调用实例方法的当前对象。

于 2013-10-14T13:30:43.100 回答
0

如果ExampleAchievement从其基类中获取此方法Achievement,则只需执行以下操作:

queueList.Add(this);

并且一个实例ExampleAchievement将被添加到队列中。但是,在使用它时,如果存在您需要获取的基本合同中不可见的特殊属性,则需要以某种方式检查类型。

如果所有属性都只是覆盖子类中的属性,那么您无需担心这一点,因为您将在访问它们时取回子实现。

于 2013-10-14T13:30:47.803 回答
0

是否可以选择传递一个可以将自己标识为调用它的参数的选项?

所以

public void GetAchievement(string caller)
{

if(caller == "Something")
{
//Do Something
}
else
{
//Do Something else
}
     //If the player hasn't got the achievement yet and another achievement is NOT being drawn, get the achievement
    if (!got && !drawing)
        get = true;
    //If the player hasn't got the achievement yet and another achievement IS being drawn, add the achievement to the queue list
    else if (!got && drawing)
        queueList.Add(); //What do I do here?
}

然后使用 exampleAchievement.GetAchievement(this.name); 调用它

于 2013-10-14T13:33:45.460 回答