2013-10-14 31 views
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();例如成就是成就类的一个对象。

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

任何帮助将不胜感激!

〜卢卡

编辑: 我用:

queueList.Add(this); 

但我只是哑巴,并没有正确地测试它,所以它看上去像什么也没有得到添加到列表中。 感谢您的帮助:3

+3

为什么不总是将成就添加到队列中,即使它只有一个? –

回答

1

这听起来像你要求this,它指的是一个实例方法被调用的当前对象。

0

如果ExampleAchievement正从它的基类Achievement这种方法,那么就这样做:

queueList.Add(this); 

ExampleAchievement一个实例将被添加到队列中。但是,使用它时,如果在基础合同中看不到特殊属性,您需要检查类型

如果所有的属性都只是在子类中覆盖属性,那么你不需要担心,因为你会在访问它们时返回子实现。

2

您是否在寻找exampleAchievement的实例?

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

我错过了什么吗?

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);