I'm making an iPhone game and have it so you can chose your difficulty. Instead of making files for each difficulty (such as EasyGameplay.h and EasyGameplay.m) is there a way I can have all the gameplay files in a single one? I would like a single file that holds all the different types of difficulty and has the type of gameplay 开发者_开发技巧corresponding. I tried to do this but I had no idea what to do.
Is this what your after?
Somewhere your class can see, probably at the top of GameDifficulty.h
typedef enum
{
kGameDifficultyEasy,
kGameDifficultyMedium,
etc,
} GameDifficulty
As the interface for your class:
@interface GamePlay{
GameDifficulty difficulty;
}
@end
And in the implementation of your class
@implementation GamePlay
{
-(void) methodOne
{
//Could use switch here instead
if (difficulty == kGameDifficultyEasy)
{
//Do what you want if game is easy
}
}
}
精彩评论