Design issue in Iphone Dev - Generic implementation for Game Bonuses

Posted by Idan on Stack Overflow See other posts from Stack Overflow or by Idan
Published on 2011-01-16T11:35:40Z Indexed on 2011/01/16 19:53 UTC
Read the original article Hit count: 298

So, I thought consulting you guys about my design, cause I sense there might be a better way of doing it.

I need to implement game bonuses mechanism in my app. Currently there are 9 bonuses available, each one is based of different param of the MainGame Object.

What I had in mind was at app startup to initialize 9 objects of GameBonus while each one will have different SEL (shouldBonus) which will be responsible for checking if the bonus is valid.

So, every end of game I will just run over the bonuses array and call the isBonusValid() function with the MainGame object(which is different after every game).

How's that sound ?

The only issue I have currently, is that I need to make sure that if some bonuses are accepted some other won't (inner stuff)... any advice how to do that and still maintain generic implementation ?

@interface GameBonus : NSObject {

    int bonusId;
    NSString* name;
    NSString* description;
    UIImage* img;
    SEL      shouldBonus;


}

@implementation GameBonus

-(BOOL) isBonusValid(MainGame*)mainGame
{
    [self shouldBonus:mainGame];
}

@end

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c