これに似た基本的な継承設定を使用するcocos2dゲーム設定があります。
> Property (Base class)
> - Office : Property
> - Warehouse : Property
> - Bank : Property
すべてのプロパティは配列listOfProperties
に存在し、NSLogの各プロパティを出力しようとしていますが、その方法がわかりません。
例えば、
// Create an office
Office *o = [Office alloc] init];
[o setName:@"Some office"];
[city.listOfProperties addObject:o];
[o release];
// Debug output all the properties in the game
// city.listOfProperties in an array of Property objects
for (Property *prop in city.listOfProperties) {
// I want to print out all the different properties here
if ([prop isKindOfClass:[Office class]]==YES)
{
NSLog(@"Office");
NSLog(@"office.name = %@", prop.name); // Prop name does not work
}
} // next
問題は、一部のプロパティが同じ属性を共有していないことです。たとえば、Officeには「フロア」があり、Warehouseには「容量」があるとします。
私が必要としているのは、すべての異なるプロパティを印刷することですが、フォーカスをポインターprop
から特定のクラス(つまり、Office)のポインターに変更する方法がわかりません。
listOfProperties
後でCCMenuで使用できるように、それらすべてが存在する必要があります。また、それらを個別の配列に分割することは避けたいので、管理が非常に困難になります。
これを行う方法はありますか?
ありがとう