-2
我有一個非常意想不到的問題,讓我發瘋。這是36卡非常簡單的記憶遊戲類型。在下面的代碼中,我使用36個objets(18個雙重對象)進行數組。當你在1-12之間選擇卡時,一切都很好。當您選擇較高的卡片時,匹配過程無法識別匹配。爲什麼???匹配圖片
memory.m
for (int i = 0; i < [imagesArray count]; ++i)
{
int n = i;
[imagesArray exchangeObjectAtIndex:i withObjectAtIndex:n];
NSLog(@"index obrázku %i",i);
NSLog(@"index array %i",n);
}
// Set button images
for (int i=0; i<[buttonsArray count]; i++) {
NSLog(@"index button %i",i);
UIButton *singleButton = [buttonsArray objectAtIndex:i];
[singleButton setBackgroundImage:[UIImage imageNamed:TILE_BACKGROUND] forState:UIControlStateNormal];
[singleButton setBackgroundImage:[UIImage imageNamed:TILE_BACKGROUND] forState:UIControlStateHighlighted];
if ([[imagesArray objectAtIndex:i] integerValue] == 1) {
[singleButton setBackgroundImage:[UIImage imageNamed:TILE_IMAGE1] forState:UIControlStateDisabled];
NSLog(@"Karta 1 tag %i",i);
} else if ([[imagesArray objectAtIndex:i] integerValue] == 2) {
[singleButton setBackgroundImage:[UIImage imageNamed:TILE_IMAGE2] forState:UIControlStateDisabled];
NSLog(@"Karta 2 tag %i",i);
}
對象是從1到18 ...
- (IBAction)tileClicked:(id)sender {
// Button is clicked
if (!matchingInPogress) {
UIButton *clickedButton = sender;
tilesOpened++;
NSLog(@"Počet otočených karet je %i",tilesOpened);
[clickedButton setEnabled:NO];
if (tilesOpened == 1) {
// Only one tiled opened, remeber tag for match
openTileIndex = clickedButton.tag;
} else {
// Second tile is opened, perform match
matchingInPogress = YES;
[self performSelector:@selector(matchTiles:) withObject:[NSNumber numberWithInt:clickedButton.tag] afterDelay:0.5];
tilesOpened = 0;
}
}
按鈕控制..
- (void)matchTiles:(NSNumber *)clickedTile {
// Match opened tiles
int clickedTileIndex = [clickedTile integerValue];
NSLog(@"Karta 1 tag %i",clickedTileIndex);
NSLog(@"Karta 2 tag %i",openTileIndex);
if ([imagesArray objectAtIndex:clickedTileIndex] != [imagesArray objectAtIndex:openTileIndex]) {
NSLog(@"Porovnává hodnoty v clickedTileIndex a openTileIndex");
// If tiles don't match set them to enabled state
UIButton *firstButton = [buttonsArray objectAtIndex:openTileIndex];
UIButton *secondButton = [buttonsArray objectAtIndex:clickedTileIndex];
NSLog(@"Nesouhlas tag je %i",openTileIndex);
NSLog(@"Nesouhlas tag je %i",clickedTileIndex);
[firstButton setEnabled:YES];
[secondButton setEnabled:YES];
} else {
NSLog(@"Match!");
UIButton *firstButton = [buttonsArray objectAtIndex:openTileIndex];
UIButton *secondButton = [buttonsArray objectAtIndex:clickedTileIndex];
NSLog(@"Souhlas tag je %i",openTileIndex);
NSLog(@"Souhlas tag je %i",clickedTileIndex);
[firstButton setHidden:YES];
[secondButton setHidden:YES];
}
matchingInPogress = NO;
}
和finaly匹配處理
由於!
這是什麼,Objective-C的? – JJJ
@Juhana:我猜Obj-C/Cocoa ...我正在設置標籤 – Seki
這裏有一個明顯缺乏信息imo –