Skip to content

Instantly share code, notes, and snippets.

View johncalvinyoung's full-sized avatar

John Calvin Young johncalvinyoung

  • RoleModel Software
View GitHub Profile
@johncalvinyoung
johncalvinyoung / gist:3184022
Created July 26, 2012 19:29
Testing End Conditions for a game of Go Fish
- (void)testEndConditionsDeck {
RMSGoFishGame *game = [RMSGoFishGame new];
[game deal];
RMSGoFishPlayer *player1 = [game.players objectAtIndex:(NSUInteger)0];
RMSGoFishPlayer *player2 = [game.players objectAtIndex:(NSUInteger)1];
RMSGoFishPlayer *player3 = [game.players objectAtIndex:(NSUInteger)2];
RMSGoFishPlayer *player4 = [game.players objectAtIndex:(NSUInteger)3];
game.deck.cards = [NSMutableArray new];
[game gameLoop];
STAssertEquals(player1.hand.count, (NSUInteger)5,@"Player 1 played after the game was over!");
@johncalvinyoung
johncalvinyoung / gist:3180228
Created July 26, 2012 04:18
Remove all subviews from a view
- (void)removeAllSubviewsFrom:(UIView *)view {
NSArray *subviews = [view subviews];
for (UIView *subview in subviews) {
[subview removeFromSuperview];
}
}
@johncalvinyoung
johncalvinyoung / gist:3179831
Created July 26, 2012 02:03
Auto-positioning hand draw code
CGFloat xOffset = 240 - (((player.hand.count*20)+52)/2);
__block CGPoint location = CGPointMake ((CGFloat) xOffset, (CGFloat) 0);
[player.hand enumerateObjectsUsingBlock:^(RMSPlayingCard *obj, NSUInteger idx, BOOL *stop) {
NSString *rank = obj.rank;
NSString *suit = obj.suit;
UIImage *cardImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@%@.png", [[suit substringToIndex:1] lowercaseString], [[rank substringToIndex:1] lowercaseString]]];
UIImageView *cardView = [[UIImageView alloc] initWithFrame:CGRectMake(location.x, location.y, cardImage.size.width, cardImage.size.height)];
[cardView setImage:cardImage];
[self.handView addSubview: cardView];