开发者

How do I implement different difficulty levels for an iPhone game inside of one file?

开发者 https://www.devze.com 2023-04-11 19:36 出处:网络
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 gamep

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
        }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号