diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/AppDelegate.h" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/AppDelegate.h" new file mode 100755 index 00000000..90f0773b --- /dev/null +++ "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/AppDelegate.h" @@ -0,0 +1,17 @@ +// +// AppDelegate.h +// cardGame +// +// Created by 葛 云波 on 14/11/29. +// Copyright (c) 2014年 葛 云波. All rights reserved. +// + +#import + +@interface AppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + + +@end + diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/AppDelegate.m" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/AppDelegate.m" new file mode 100755 index 00000000..bfdbb969 --- /dev/null +++ "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/AppDelegate.m" @@ -0,0 +1,45 @@ +// +// AppDelegate.m +// cardGame +// +// Created by 葛 云波 on 14/11/29. +// Copyright (c) 2014年 葛 云波. All rights reserved. +// + +#import "AppDelegate.h" + +@interface AppDelegate () + +@end + +@implementation AppDelegate + + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // Override point for customization after application launch. + return YES; +} + +- (void)applicationWillResignActive:(UIApplication *)application { + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. +} + +- (void)applicationDidEnterBackground:(UIApplication *)application { + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. +} + +- (void)applicationWillEnterForeground:(UIApplication *)application { + // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. +} + +- (void)applicationDidBecomeActive:(UIApplication *)application { + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. +} + +- (void)applicationWillTerminate:(UIApplication *)application { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. +} + +@end diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Base.lproj/LaunchScreen.xib" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Base.lproj/LaunchScreen.xib" new file mode 100755 index 00000000..b055c3da --- /dev/null +++ "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Base.lproj/LaunchScreen.xib" @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Base.lproj/Main.storyboard" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Base.lproj/Main.storyboard" new file mode 100755 index 00000000..f9d8f227 --- /dev/null +++ "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Base.lproj/Main.storyboard" @@ -0,0 +1,183 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Card.h" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Card.h" new file mode 100755 index 00000000..28f6ce65 --- /dev/null +++ "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Card.h" @@ -0,0 +1,18 @@ +// +// Card.h +// cardGame +// +// Created by 葛 云波 on 14/11/29. +// Copyright (c) 2014年 葛 云波. All rights reserved. +// + +#import + +@interface Card : NSObject +@property (strong, nonatomic) NSString *contents; + +@property (nonatomic, getter=isChosen) BOOL chosen; +@property (nonatomic, getter=isMatched) BOOL matched; + +-(int) match:(NSArray *) otherCards; +@end diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Card.m" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Card.m" new file mode 100755 index 00000000..bdd73abb --- /dev/null +++ "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Card.m" @@ -0,0 +1,30 @@ +// +// Card.m +// cardGame +// +// Created by 葛 云波 on 14/11/29. +// Copyright (c) 2014年 葛 云波. All rights reserved. +// + +#import "Card.h" + +@interface Card() + +@end + +@implementation Card +//if match return 1, otherwise return 0 +-(int) match:(NSArray *)otherCards{ + int score = 0; + for (Card *card in otherCards){ + if ([card.contents isEqualToString:self.contents]){ + score = 1; + } + } + + + return score; +} + + +@end diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/CardMatchingGame.h" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/CardMatchingGame.h" new file mode 100644 index 00000000..2da0fbfb --- /dev/null +++ "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/CardMatchingGame.h" @@ -0,0 +1,23 @@ +// +// CardMatchingGame.h +// cardGame +// +// Created by 葛云波 on 14/12/1. +// Copyright (c) 2014年 葛 云波. All rights reserved. +// + +#import +#import "Deck.h" + +@interface CardMatchingGame : NSObject + +//designated initializer +-(instancetype)initWithCardCount:(NSUInteger)count + usingDeck:(Deck *)deck; + +-(void)chooseCardAtIndex:(NSUInteger)index withMatchCount:(NSInteger)matchCount; +-(Card *)cardAtIndex:(NSUInteger)index; + +@property (nonatomic) NSInteger score; + +@end diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/CardMatchingGame.m" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/CardMatchingGame.m" new file mode 100644 index 00000000..3ca0f984 --- /dev/null +++ "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/CardMatchingGame.m" @@ -0,0 +1,86 @@ +// +// CardMatchingGame.m +// cardGame +// +// Created by 葛云波 on 14/12/1. +// Copyright (c) 2014年 葛 云波. All rights reserved. +// + +#import "CardMatchingGame.h" + +@interface CardMatchingGame() +@property (nonatomic, strong) NSMutableArray *cards;//of Card +@property (nonatomic, strong) NSMutableArray *matchArray; + +@end + +@implementation CardMatchingGame +-(NSMutableArray *)matchArray{ + if(!_matchArray){ + _matchArray = [[NSMutableArray alloc] init]; + } + return _matchArray; +} +-(NSMutableArray *)cards{ + if (!_cards) { + _cards = [[NSMutableArray alloc] init]; + } + return _cards; +} + +-(instancetype)initWithCardCount:(NSUInteger)count + usingDeck:(Deck *)deck{ + self = [super init]; + if (self) { + for (int i = 0; i < count; i++) { + Card *card = [deck drawRandomCard]; + if (card) { + [self.cards addObject:card]; + } else { + self = nil; + break; + } + } + } + return self; +} + +-(Card *)cardAtIndex:(NSUInteger)index{ + return (index < [self.cards count]) ? self.cards[index] : nil; +} + +static const int MATCH_BONUS = 4; +static const int COST_TO_CHOOSE = 1; +static const int MISMATCH_PENALTY = 2; + +-(void)chooseCardAtIndex:(NSUInteger)index withMatchCount:(NSInteger)matchCount{ + Card *card = [self cardAtIndex:index]; + + if (!card.isMatched) { + if (card.isChosen) { + card.Chosen = NO; + } else { + //match against other chosen cards + for (Card *otherCard in self.cards){ + if (otherCard.isChosen && !otherCard.isMatched) { + int matchScore = [card match:@[otherCard]]; + if (matchScore) { + self.score += matchScore * MATCH_BONUS; + otherCard.matched = YES; + card.matched = YES; + } else { + self.score -= matchScore * MISMATCH_PENALTY; + otherCard.chosen = NO; + } + break;//can only choose 2 cards + } + } + self.score -= COST_TO_CHOOSE; + card.chosen = YES; + } + } +} + + + +@end diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Deck.h" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Deck.h" new file mode 100755 index 00000000..fe1f45ee --- /dev/null +++ "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Deck.h" @@ -0,0 +1,19 @@ +// +// Deck.h +// cardGame +// +// Created by 葛 云波 on 14/11/29. +// Copyright (c) 2014年 葛 云波. All rights reserved. +// + +#import +#import "Card.h" + +@interface Deck : NSObject +@property (strong, nonatomic)NSMutableArray *cards;//of Card +-(void)addCard:(Card *)card atTop:(BOOL)atTop; +-(void)addcard:(Card *)card; + +-(Card *)drawRandomCard; + +@end diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Deck.m" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Deck.m" new file mode 100755 index 00000000..83e9c1d7 --- /dev/null +++ "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Deck.m" @@ -0,0 +1,47 @@ +// +// Deck.m +// cardGame +// +// Created by 葛 云波 on 14/11/29. +// Copyright (c) 2014年 葛 云波. All rights reserved. +// + +#import "Deck.h" + +@interface Deck() + + +@end + +@implementation Deck + +-(NSMutableArray *)cards{ + if (!_cards) { + _cards = [[NSMutableArray alloc] init]; + } + return _cards; +} + +-(void)addCard:(Card *)card atTop:(BOOL)atTop{ + if (atTop) { + [self.cards insertObject:card atIndex:0]; + } else { + [self.cards addObject:card]; + } +} +-(void)addcard:(Card *)card{ + [self addCard:card atTop:NO]; +} + +-(Card *)drawRandomCard{ + Card *randomCard = nil; + if ([self.cards count]) { + unsigned index = arc4random() % [self.cards count]; + randomCard = self.cards[index]; + [self.cards removeObjectAtIndex:index]; + } + return randomCard; +} + + +@end diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Images.xcassets/AppIcon.appiconset/Contents.json" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Images.xcassets/AppIcon.appiconset/Contents.json" new file mode 100755 index 00000000..118c98f7 --- /dev/null +++ "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Images.xcassets/AppIcon.appiconset/Contents.json" @@ -0,0 +1,38 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Images.xcassets/cardBack.imageset/Contents.json" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Images.xcassets/cardBack.imageset/Contents.json" new file mode 100755 index 00000000..908ebb08 --- /dev/null +++ "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Images.xcassets/cardBack.imageset/Contents.json" @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x", + "filename" : "cardBack1.png" + }, + { + "idiom" : "universal", + "scale" : "2x", + "filename" : "onepiece-two_desktopsky_12.png" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Images.xcassets/cardBack.imageset/cardBack1.png" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Images.xcassets/cardBack.imageset/cardBack1.png" new file mode 100755 index 00000000..d00fe46f Binary files /dev/null and "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Images.xcassets/cardBack.imageset/cardBack1.png" differ diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Images.xcassets/cardBack.imageset/onepiece-two_desktopsky_12.png" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Images.xcassets/cardBack.imageset/onepiece-two_desktopsky_12.png" new file mode 100755 index 00000000..93bf25ad Binary files /dev/null and "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Images.xcassets/cardBack.imageset/onepiece-two_desktopsky_12.png" differ diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Images.xcassets/cardFront.imageset/Contents.json" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Images.xcassets/cardFront.imageset/Contents.json" new file mode 100755 index 00000000..77a8364b --- /dev/null +++ "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Images.xcassets/cardFront.imageset/Contents.json" @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x", + "filename" : "blank card rounded corner.png" + }, + { + "idiom" : "universal", + "scale" : "2x", + "filename" : "blank card hi-res.png" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Images.xcassets/cardFront.imageset/blank card hi-res.png" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Images.xcassets/cardFront.imageset/blank card hi-res.png" new file mode 100755 index 00000000..d5723d8b Binary files /dev/null and "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Images.xcassets/cardFront.imageset/blank card hi-res.png" differ diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Images.xcassets/cardFront.imageset/blank card rounded corner.png" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Images.xcassets/cardFront.imageset/blank card rounded corner.png" new file mode 100755 index 00000000..569f8bf2 Binary files /dev/null and "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Images.xcassets/cardFront.imageset/blank card rounded corner.png" differ diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Info.plist" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Info.plist" new file mode 100755 index 00000000..27f52823 --- /dev/null +++ "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/Info.plist" @@ -0,0 +1,40 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + com.geyunbo.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/PlayingCard.h" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/PlayingCard.h" new file mode 100755 index 00000000..e598f152 --- /dev/null +++ "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/PlayingCard.h" @@ -0,0 +1,20 @@ +// +// PlayingCard.h +// cardGame +// +// Created by 葛 云波 on 14/11/29. +// Copyright (c) 2014年 葛 云波. All rights reserved. +// + +//#import +#import "Card.h" + +@interface PlayingCard : Card + +@property (strong, nonatomic) NSString *suit; +@property (nonatomic) NSUInteger rank; + ++(NSArray *)validSuits; ++(NSUInteger)maxRank; + +@end diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/PlayingCard.m" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/PlayingCard.m" new file mode 100755 index 00000000..f83dfad9 --- /dev/null +++ "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/PlayingCard.m" @@ -0,0 +1,63 @@ +// +// PlayingCard.m +// cardGame +// +// Created by 葛 云波 on 14/11/29. +// Copyright (c) 2014年 葛 云波. All rights reserved. +// + +#import "PlayingCard.h" + +@implementation PlayingCard + +-(int)match:(NSArray *)otherCards{ + int score = 0; + if ([otherCards count] == 1) { + id card = [otherCards firstObject]; + if ([card isKindOfClass:[PlayingCard class]]){ + PlayingCard *otherCard = (PlayingCard *) card; + if (otherCard.rank == self.rank ) { + score = 4; + } else if ([otherCard.suit isEqualToString:self.suit]){ + score = 1; + } + } + } + return score; +} + +-(NSString *)contents{ + NSArray *rankStrings = [PlayingCard rankStrings]; + return [rankStrings[self.rank] stringByAppendingString:self.suit]; +} + +@synthesize suit = _suit;//because we provide setter and getter + ++(NSArray *)validSuits{ + return @[@"♥️",@"♦️",@"♠️",@"♣️"]; +} + +-(void)setSuit:(NSString *)suit{ + if ([[PlayingCard validSuits] containsObject:suit]) { + _suit = suit; + } +} + +-(NSString *)suit{ + return _suit ? _suit : @"?";//如果suit是nil则返回“?”,否则返回实际值 +} + ++(NSArray *)rankStrings{ + return @[@"?",@"A",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"J",@"Q",@"K"]; +} + ++(NSUInteger)maxRank{ + return [[self rankStrings] count]-1; +} + +-(void)setRank:(NSUInteger)rank{ + if (rank <= [PlayingCard maxRank]) { + _rank = rank; + } +} +@end diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/PlayingCardDeck.h" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/PlayingCardDeck.h" new file mode 100755 index 00000000..6c615806 --- /dev/null +++ "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/PlayingCardDeck.h" @@ -0,0 +1,13 @@ +// +// PlayingCardDeck.h +// cardGame +// +// Created by 葛 云波 on 14/11/29. +// Copyright (c) 2014年 葛 云波. All rights reserved. +// + +#import "Deck.h" +#import "PlayingCard.h" +@interface PlayingCardDeck : Deck + +@end diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/PlayingCardDeck.m" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/PlayingCardDeck.m" new file mode 100755 index 00000000..1611e839 --- /dev/null +++ "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/PlayingCardDeck.m" @@ -0,0 +1,33 @@ +// +// PlayingCardDeck.m +// cardGame +// +// Created by 葛 云波 on 14/11/29. +// Copyright (c) 2014年 葛 云波. All rights reserved. +// + +#import "PlayingCardDeck.h" +#import "PlayingCard.h" + +@interface PlayingCardDeck() + +@end + +@implementation PlayingCardDeck + +-(instancetype)init{ + self = [super init]; + if(self){ + for (NSString *suit in [PlayingCard validSuits]){ + for (NSUInteger rank=1;rank <= [PlayingCard maxRank];rank++){ + PlayingCard *card = [[PlayingCard alloc] init]; + card.suit = suit; + card.rank = rank; + [self addcard:card]; + } + } + } + return self; +} + +@end diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/PlayingCardGameViewController.h" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/PlayingCardGameViewController.h" new file mode 100644 index 00000000..dd56ba3b --- /dev/null +++ "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/PlayingCardGameViewController.h" @@ -0,0 +1,13 @@ +// +// PlayingCardGameViewController.h +// cardGame +// +// Created by 葛云波 on 14/12/15. +// Copyright (c) 2014年 葛 云波. All rights reserved. +// + +#import "ViewController.h" + +@interface PlayingCardGameViewController : ViewController + +@end diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/PlayingCardGameViewController.m" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/PlayingCardGameViewController.m" new file mode 100644 index 00000000..186cf44b --- /dev/null +++ "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/PlayingCardGameViewController.m" @@ -0,0 +1,22 @@ +// +// PlayingCardGameViewController.m +// cardGame +// +// Created by 葛云波 on 14/12/15. +// Copyright (c) 2014年 葛 云波. All rights reserved. +// + +#import "PlayingCardGameViewController.h" +#import "PlayingCardDeck.h" +@interface PlayingCardGameViewController () + +@end + +@implementation PlayingCardGameViewController + +-(Deck *)creatDeck{ + return [[PlayingCardDeck alloc]init]; +} + + +@end diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/ViewController.h" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/ViewController.h" new file mode 100755 index 00000000..49910a33 --- /dev/null +++ "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/ViewController.h" @@ -0,0 +1,15 @@ +// +// ViewController.h +// cardGame +// +// Created by 葛 云波 on 14/11/29. +// Copyright (c) 2014年 葛 云波. All rights reserved. +//Abstract class.Must implement methods as described below. + +#import +#import "Deck.h" +@interface ViewController : UIViewController + +-(Deck *)creatDeck;//abstract +@end + diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/ViewController.m" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/ViewController.m" new file mode 100755 index 00000000..9c047310 --- /dev/null +++ "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/ViewController.m" @@ -0,0 +1,74 @@ +// +// ViewController.m +// cardGame +// +// Created by 葛 云波 on 14/11/29. +// Copyright (c) 2014年 葛 云波. All rights reserved. +// + +#import "ViewController.h" +#import "CardMatchingGame.h" + +@interface ViewController () +@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *cardButtons; +@property (weak, nonatomic) IBOutlet UILabel *scoreLabel; +@property (nonatomic, strong) CardMatchingGame *game; +@property (nonatomic) NSInteger matchCount; +@end + +@implementation ViewController + +- (IBAction)touchRestartButton:(UIButton *)sender { + self.game = nil; + self.game = [self game]; + [self updateUI]; +} + +-(CardMatchingGame *)game{ + if (!_game) { + _game = [[CardMatchingGame alloc] initWithCardCount:[self.cardButtons count] + usingDeck:[self creatDeck]]; + } + return _game; +} + + +-(Deck *)creatDeck{ + return nil; +} + +- (IBAction)touchCardButton:(UIButton *)sender { + NSUInteger chosenButtonIndex = [self.cardButtons indexOfObject:sender]; + [self.game chooseCardAtIndex:chosenButtonIndex withMatchCount:self.matchCount]; + [self updateUI]; + +} + +-(void)updateUI{ + for(UIButton *cardButton in self.cardButtons){ + NSUInteger cardButtonIndex = [self.cardButtons indexOfObject:cardButton]; + Card *card = [self.game cardAtIndex:cardButtonIndex]; + [cardButton setTitle:[self titleForCard:card] forState:UIControlStateNormal]; + [cardButton setBackgroundImage:[self backgroundImageForCard:card] forState:UIControlStateNormal]; + self.scoreLabel.text = [NSString stringWithFormat:@"Score:%ld",(long)self.game.score]; + + } +} +-(NSString *)titleForCard:(Card *)card{ + return card.isChosen ? card.contents :@""; +} +-(UIImage *)backgroundImageForCard:(Card *)card{ + return [UIImage imageNamed:card.isChosen ? @"cardFront" : @"cardBack"]; +} + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view, typically from a nib. +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +@end diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/cardBack.jpg" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/cardBack.jpg" new file mode 100755 index 00000000..b81ba64e Binary files /dev/null and "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/cardBack.jpg" differ diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/main.m" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/main.m" new file mode 100755 index 00000000..4647fa06 --- /dev/null +++ "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGame/main.m" @@ -0,0 +1,16 @@ +// +// main.m +// cardGame +// +// Created by 葛 云波 on 14/11/29. +// Copyright (c) 2014年 葛 云波. All rights reserved. +// + +#import +#import "AppDelegate.h" + +int main(int argc, char * argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGameTests/Info.plist" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGameTests/Info.plist" new file mode 100755 index 00000000..576b190e --- /dev/null +++ "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGameTests/Info.plist" @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + com.geyunbo.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git "a/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGameTests/cardGameTests.m" "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGameTests/cardGameTests.m" new file mode 100755 index 00000000..21d9be5c --- /dev/null +++ "b/yxb144325079\350\221\233\344\272\221\346\263\242/cardGame/cardGameTests/cardGameTests.m" @@ -0,0 +1,40 @@ +// +// cardGameTests.m +// cardGameTests +// +// Created by 葛 云波 on 14/11/29. +// Copyright (c) 2014年 葛 云波. All rights reserved. +// + +#import +#import + +@interface cardGameTests : XCTestCase + +@end + +@implementation cardGameTests + +- (void)setUp { + [super setUp]; + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown { + // Put teardown code here. This method is called after the invocation of each test method in the class. + [super tearDown]; +} + +- (void)testExample { + // This is an example of a functional test case. + XCTAssert(YES, @"Pass"); +} + +- (void)testPerformanceExample { + // This is an example of a performance test case. + [self measureBlock:^{ + // Put the code you want to measure the time of here. + }]; +} + +@end