Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
Hi All, I have a card game where the cards have exact origin points where they are placed on the screen. The cards get swapped a lot and at the end of the game the values get added up.

When the card game starts the cards are in an array and get a tag the correlates to the position in the mixed deck. There are 12 cards so card 7 is index 7 (the first card at index 0 is discarded). So as the cards are laid out the tags are sequential 1,2,3,4.... But the end of the game the cards values are mixed, example 42,12,17,44....

If I can cycle through the NSImageView in the self.view I can retrieve the tag numbers and match them up with the array indexes.

This is just Sudo code below to give an example of what I am looking for.
Code:
    xLocNumbers = @[@"25",@"150",@"275",@"25",@"150",@"275",@"25",@"150",@"275",@"25",@"150",@"275"];
    yLocNumbers = @[@"50",@"50",@"50",@"175",@"175",@"175",@"425",@"425",@"425",@"550",@"550",@"550"];
    CGPoint point = CGPointMake([[xLocNumbersobjectAtIndex:0]floatValue], [[yLocNumbersobjectAtIndex:0]floatValue]);
    NSImageView *view = (NSImageView*) [self.view viewAtOrigin:point]; // bogus code, just an example.

This may not be possible, but I thought I would ask?

Thanks!
 
After 3 days I'm still not sure what you're up to.

Is a card a class with both a NSImageView and a card value?
Or, is the tag also the card value?
You said the cards have exact origin points (NSRects), but get swapped, so I'm assuming each card starts at one location but ends up in another location during the game, so it gets moved.
What is the user action that causes the cards to swap?
It looks like you have fixed rows and columns for the cards. Are you trying to sum the card values vertically or/and horizontally?
Are you movings cards around like you might do on iOS to move the app icons around?

One thought...
Create a Card class that contained an NSImageView for the card, card value, current row and current column.
Initialize appropriately and place into array.
Set the NSRect for each cards NSImageView.
Add each card's NSImageView to the superview.
As the cards move, update the column and row for each card moved.
At the end, loop through the array once to sum the card values to individual sum variables per column or row.
Display the sums.

P.S. NSCollectionView could be handy.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.