i want to make a simple memory matching game. this is my following situation: i have a levelselectionviewcontroller and a gameviewcontroller. in my levelselectionviewcontroller i have 10 buttons (10 levels). i want, that when i click on level 1, my gameviewcontroller make 1 row with 2 pairs. when i click on level 10 i want that may gameviewcontroller make 2 rows with 3 pairs for example. my maximum pairs are 11, my maximum rows are 4.
my code in my gameviewcontroller is
.h
#define CARDS_PER_ROW 4
#define NUMBER_OF_PAIRS 2
.m
-(void) generateCardViews {
int positionsLeftInRow = CARDS_PER_ROW;
int j = 0; // j = ROWNUMBER (j = 0) = ROW1, (j = 1) = ROW2...
for (int i = 0; i < [self.gameModel.cards count]; i++) {
NSInteger value = ((CardModel *)self.gameModel.cards[i]).value;
CGFloat x = (i % CARDS_PER_ROW) * 121 + (i % CARDS_PER_ROW) * 40 + 285;
if (j == 1) {
x += 80; // set additional indent (horizontal displacement)
}
if (j == 2) {
x -= 160;
}
CGFloat y = j * 122 + j * 40 + 158;
CGRect frame = CGRectMake(x, y, 125, 125);
CardView *cv = [[CardView alloc] initWithFrame:frame andPosition:i andValue:value];
if (!((CardModel *)self.gameModel.cards[i]).outOfPlay) {
[self.boardView addSubview:cv];
if ([self.gameModel.turnedCards containsObject: self.gameModel.cards[i]]) {
[self.turnedCardViews addObject: cv];
[cv flip];
}
}
if (--positionsLeftInRow == 0) {
j++;
positionsLeftInRow = CARDS_PER_ROW;
if (j == 1) {
positionsLeftInRow = CARDS_PER_ROW-1;
if (j == 2) {
positionsLeftInRow = CARDS_PER_ROW-2;
}}
}
}
}
my code now is working, but i can only change the rows and pairs in my #define macro in my gameviewcontroller. but how can i #define it in my levelselectionviewcontroller? i want a reusable gameviewcontroller for n levels.
i hope my question is understandable.