diff --git a/HeadsUpper/HeadsUpper.xcodeproj/project.pbxproj b/HeadsUpper/HeadsUpper.xcodeproj/project.pbxproj index fb900f8..afed502 100644 --- a/HeadsUpper/HeadsUpper.xcodeproj/project.pbxproj +++ b/HeadsUpper/HeadsUpper.xcodeproj/project.pbxproj @@ -7,21 +7,33 @@ objects = { /* Begin PBXBuildFile section */ + 1887DC561C7A11670037888D /* HUCategoriesTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1887DC551C7A11670037888D /* HUCategoriesTableViewController.m */; }; + 1887DC591C7A11900037888D /* HUGameViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1887DC581C7A11900037888D /* HUGameViewController.m */; }; + 1887DC5F1C7A11F00037888D /* HUGameCategory.m in Sources */ = {isa = PBXBuildFile; fileRef = 1887DC5E1C7A11F00037888D /* HUGameCategory.m */; }; + 1887DC621C7A17320037888D /* CategoryAndClueSetup.m in Sources */ = {isa = PBXBuildFile; fileRef = 1887DC611C7A17320037888D /* CategoryAndClueSetup.m */; }; + 18B3CAEA1C7A2C690057381E /* HUGameCategory+GameScore.m in Sources */ = {isa = PBXBuildFile; fileRef = 18B3CAE91C7A2C690057381E /* HUGameCategory+GameScore.m */; }; 8D89695C1C755D0200D32E8A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D89695B1C755D0200D32E8A /* main.m */; }; 8D89695F1C755D0200D32E8A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D89695E1C755D0200D32E8A /* AppDelegate.m */; }; - 8D8969621C755D0200D32E8A /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D8969611C755D0200D32E8A /* ViewController.m */; }; 8D8969651C755D0200D32E8A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8D8969631C755D0200D32E8A /* Main.storyboard */; }; 8D8969671C755D0200D32E8A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8D8969661C755D0200D32E8A /* Assets.xcassets */; }; 8D89696A1C755D0200D32E8A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8D8969681C755D0200D32E8A /* LaunchScreen.storyboard */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 1887DC541C7A11670037888D /* HUCategoriesTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HUCategoriesTableViewController.h; sourceTree = ""; }; + 1887DC551C7A11670037888D /* HUCategoriesTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HUCategoriesTableViewController.m; sourceTree = ""; }; + 1887DC571C7A11900037888D /* HUGameViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HUGameViewController.h; sourceTree = ""; }; + 1887DC581C7A11900037888D /* HUGameViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HUGameViewController.m; sourceTree = ""; }; + 1887DC5D1C7A11F00037888D /* HUGameCategory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HUGameCategory.h; sourceTree = ""; }; + 1887DC5E1C7A11F00037888D /* HUGameCategory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HUGameCategory.m; sourceTree = ""; }; + 1887DC601C7A17320037888D /* CategoryAndClueSetup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CategoryAndClueSetup.h; sourceTree = ""; }; + 1887DC611C7A17320037888D /* CategoryAndClueSetup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CategoryAndClueSetup.m; sourceTree = ""; }; + 18B3CAE81C7A2C690057381E /* HUGameCategory+GameScore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "HUGameCategory+GameScore.h"; sourceTree = ""; }; + 18B3CAE91C7A2C690057381E /* HUGameCategory+GameScore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "HUGameCategory+GameScore.m"; sourceTree = ""; }; 8D8969571C755D0200D32E8A /* HeadsUpper.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HeadsUpper.app; sourceTree = BUILT_PRODUCTS_DIR; }; 8D89695B1C755D0200D32E8A /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 8D89695D1C755D0200D32E8A /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 8D89695E1C755D0200D32E8A /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; - 8D8969601C755D0200D32E8A /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; - 8D8969611C755D0200D32E8A /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 8D8969641C755D0200D32E8A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 8D8969661C755D0200D32E8A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 8D8969691C755D0200D32E8A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; @@ -39,6 +51,44 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 18201EE31C7A546E0027F5F2 /* Categories */ = { + isa = PBXGroup; + children = ( + 18B3CAE81C7A2C690057381E /* HUGameCategory+GameScore.h */, + 18B3CAE91C7A2C690057381E /* HUGameCategory+GameScore.m */, + ); + name = Categories; + sourceTree = ""; + }; + 18201EE41C7A54980027F5F2 /* ViewControllers */ = { + isa = PBXGroup; + children = ( + 1887DC541C7A11670037888D /* HUCategoriesTableViewController.h */, + 1887DC551C7A11670037888D /* HUCategoriesTableViewController.m */, + 1887DC571C7A11900037888D /* HUGameViewController.h */, + 1887DC581C7A11900037888D /* HUGameViewController.m */, + ); + name = ViewControllers; + sourceTree = ""; + }; + 18201EE51C7A54A80027F5F2 /* SetupHelperClass */ = { + isa = PBXGroup; + children = ( + 1887DC601C7A17320037888D /* CategoryAndClueSetup.h */, + 1887DC611C7A17320037888D /* CategoryAndClueSetup.m */, + ); + name = SetupHelperClass; + sourceTree = ""; + }; + 18201EE61C7A54B90027F5F2 /* Model */ = { + isa = PBXGroup; + children = ( + 1887DC5D1C7A11F00037888D /* HUGameCategory.h */, + 1887DC5E1C7A11F00037888D /* HUGameCategory.m */, + ); + name = Model; + sourceTree = ""; + }; 8D89694E1C755D0200D32E8A = { isa = PBXGroup; children = ( @@ -60,8 +110,10 @@ children = ( 8D89695D1C755D0200D32E8A /* AppDelegate.h */, 8D89695E1C755D0200D32E8A /* AppDelegate.m */, - 8D8969601C755D0200D32E8A /* ViewController.h */, - 8D8969611C755D0200D32E8A /* ViewController.m */, + 18201EE31C7A546E0027F5F2 /* Categories */, + 18201EE61C7A54B90027F5F2 /* Model */, + 18201EE51C7A54A80027F5F2 /* SetupHelperClass */, + 18201EE41C7A54980027F5F2 /* ViewControllers */, 8D8969631C755D0200D32E8A /* Main.storyboard */, 8D8969661C755D0200D32E8A /* Assets.xcassets */, 8D8969681C755D0200D32E8A /* LaunchScreen.storyboard */, @@ -110,6 +162,7 @@ TargetAttributes = { 8D8969561C755D0200D32E8A = { CreatedOnToolsVersion = 7.2.1; + DevelopmentTeam = BULEKXRKSR; }; }; }; @@ -149,9 +202,13 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 8D8969621C755D0200D32E8A /* ViewController.m in Sources */, + 1887DC561C7A11670037888D /* HUCategoriesTableViewController.m in Sources */, 8D89695F1C755D0200D32E8A /* AppDelegate.m in Sources */, 8D89695C1C755D0200D32E8A /* main.m in Sources */, + 18B3CAEA1C7A2C690057381E /* HUGameCategory+GameScore.m in Sources */, + 1887DC5F1C7A11F00037888D /* HUGameCategory.m in Sources */, + 1887DC591C7A11900037888D /* HUGameViewController.m in Sources */, + 1887DC621C7A17320037888D /* CategoryAndClueSetup.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -261,11 +318,14 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; INFOPLIST_FILE = HeadsUpper/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.1; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.mikekavouras.HeadsUpper; + PRODUCT_BUNDLE_IDENTIFIER = com.mesfin.HeadsUpper; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = ""; }; name = Debug; }; @@ -273,11 +333,14 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; INFOPLIST_FILE = HeadsUpper/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.1; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.mikekavouras.HeadsUpper; + PRODUCT_BUNDLE_IDENTIFIER = com.mesfin.HeadsUpper; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = ""; }; name = Release; }; @@ -300,6 +363,7 @@ 8D8969701C755D0200D32E8A /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/HeadsUpper/HeadsUpper/Base.lproj/LaunchScreen.storyboard b/HeadsUpper/HeadsUpper/Base.lproj/LaunchScreen.storyboard index 2e721e1..be4a2ee 100644 --- a/HeadsUpper/HeadsUpper/Base.lproj/LaunchScreen.storyboard +++ b/HeadsUpper/HeadsUpper/Base.lproj/LaunchScreen.storyboard @@ -1,7 +1,8 @@ - + - + + @@ -15,8 +16,19 @@ - - + + + + + + + + diff --git a/HeadsUpper/HeadsUpper/Base.lproj/Main.storyboard b/HeadsUpper/HeadsUpper/Base.lproj/Main.storyboard index f56d2f3..6a4aa38 100644 --- a/HeadsUpper/HeadsUpper/Base.lproj/Main.storyboard +++ b/HeadsUpper/HeadsUpper/Base.lproj/Main.storyboard @@ -1,25 +1,107 @@ - + - + + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + - + + + + + + + + + + + + + + + + + - + + diff --git a/HeadsUpper/HeadsUpper/CategoryAndClueSetup.h b/HeadsUpper/HeadsUpper/CategoryAndClueSetup.h new file mode 100644 index 0000000..bedb94b --- /dev/null +++ b/HeadsUpper/HeadsUpper/CategoryAndClueSetup.h @@ -0,0 +1,21 @@ +// +// CategoryAndClueSetup.h +// HeadsUpper +// +// Created by Mesfin Bekele Mekonnen on 2/21/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import +#import "HUGameCategory.h" + + +@interface CategoryAndClueSetup : NSObject + + +@property (nonatomic) NSMutableArray *gameCategories; + +-(instancetype)initCategories; + + +@end diff --git a/HeadsUpper/HeadsUpper/CategoryAndClueSetup.m b/HeadsUpper/HeadsUpper/CategoryAndClueSetup.m new file mode 100644 index 0000000..e5dfaee --- /dev/null +++ b/HeadsUpper/HeadsUpper/CategoryAndClueSetup.m @@ -0,0 +1,76 @@ +// +// CategoryAndClueSetup.m +// HeadsUpper +// +// Created by Mesfin Bekele Mekonnen on 2/21/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import "CategoryAndClueSetup.h" + +@implementation CategoryAndClueSetup + + +-(instancetype)initCategories { + + if (self = [super init]) { + self.gameCategories = [NSMutableArray new]; + self.gameCategories = [self setup]; + return self; + } + + return nil; +} + +-(HUGameCategory *)createHUGameCategoryFor:(NSString *)category andClues:(NSMutableArray *)clues { + + HUGameCategory *gameCategory = [[HUGameCategory alloc] initWithName:category andClues:clues]; + return gameCategory; +} + +-(NSMutableArray *)setup { + + NSMutableArray *gameCategoriesArray = [NSMutableArray new]; + + NSMutableArray *superstarsClues = [[NSMutableArray alloc] initWithArray:@[@"Janet Jackson", @"Leighton Meester", @"Willow Smith", @"Matt Lauer", @"Josh Duhamel", @"Sharon Osbourne", @"Spencer Pratt", @"Demi Moore", @"Whitney Houston", @"Nicole Kidman", @"Miley Cyrus", @"Victoria Beckham", @"LeAnn Rimes", @"Dakota Fanning", @"Dr. Seuss", @"Ryan Phillippe", @"Steve Carell", @"Chris Rock", @"Collin Ferell", @"Drake", @"Rachel McAdams", @"Maya Rudolph"]]; + + + HUGameCategory *superstars = [self createHUGameCategoryFor:@"Superstars" andClues:superstarsClues]; + + [gameCategoriesArray addObject:superstars]; + + NSMutableArray *so90sClues = [[NSMutableArray alloc] initWithArray:@[@"El Niño", @"Viagra", @"Animaniacs", @"League of their Own", @"Happy Gilmore", @"Nick Carter", @"My Heart Will Go On", @"I Know What You Did Last Summer", @"Can You Feel The Love Tonight", @"The Macarana", @"Light-up Sneakers", @"Boy Meets World", @"Baby Got Back", @"Smells Like Teen Spirit", @"Super Soakers", @"7th Heaven", @"Garth Brooks", @"Floppy Discs", @"Kramer", @"Blink 182", @"Surge"]]; + + HUGameCategory *so90s = [self createHUGameCategoryFor:@"That's so 90's" andClues:so90sClues]; + + [gameCategoriesArray addObject:so90s]; + + NSMutableArray *heyMrDJclues = [[NSMutableArray alloc] initWithArray:@[@"\"Girl On Fire\" Alicia Keys", @"\"U Can't Touch This\" MC Hammer", @"\"Hello\" Lionel Richie", @"\"Dark Horse\" Katy Perry", @"\"Someboyd To Love\" Queen", @"\"No Scrubs\" TLC", @"\"Happy\" Pharrell Williams", @"\"Piano Man\" Billy Joel", @"\"Blurred Lines\" Robin Thicke", @"\"Fantasy\" Mariah Carey", @"\"I Will Survive\" Gloria Gaynor", @"\"Come and Get it\" Selena Gomez", @"\"Halo\" Beyonce", @"\"I Believe I Can Fly\" R.Kelly", @"\"The Sign\" Ace of Base", @"\"Diamonds\" Rihanna", @"\"A Thousand Miles\" Vanessa Carlton", @"\"What a Wonderful World\" Louis Armstrong", @"\"We Belong Together\" Mariah Carey", @"\"(I Can't Get No) Satisfaction\""]]; + + HUGameCategory *heyMrDJ = [self createHUGameCategoryFor:@"Hey Mr. DJ!" andClues:heyMrDJclues]; + + [gameCategoriesArray addObject:heyMrDJ]; + + + NSMutableArray *iconsClues = [[NSMutableArray alloc] initWithArray:@[@"Colin Farrell", @"Mozart", @"Billy Joel", @"Judy Garland", @"Napoleon Bonaparte", @"Queen Elizabeth II", @"Fred Armisen", @"Henry Ford", @"Jon Lovitz", @"Julia Child", @"Catherine the Great", @"Magic Johnson", @"Uma Thurman", @"Orson Welles", @"Kathy Bates", @"George Orwell", @"Billy Crystal", @"Farrah Fawcett", @"Gary Busey", @"Chris Farley", @"Tom Selleck", @"Alexander the Great"]]; + + HUGameCategory *icons = [self createHUGameCategoryFor:@"Icons" andClues:iconsClues]; + + [gameCategoriesArray addObject:icons]; + + NSMutableArray *animalsGoneWildClues = [[NSMutableArray alloc] initWithArray:@[@"Chipmunk", @"Dragon", @"Wasp", @"Snake", @"Jellyfish", @"Emu", @"Boar", @"Crocodile", @"Shrimp", @"Lemur", @"Caterpillar", @"Sea Urchain", @"Dolphin ", @"Camel", @"Viper", @"Fox", @"Tuna", @"Baboon", @"Chinchilla", @"Human", @"Crawfish", @"Cricket", @"Frog", @"Tiger", @"Guinea Pig", @"Gnat", @"Killer Whale", @"Coral", @"T-Rex", @"Oyster"]]; + + HUGameCategory *animalsGoneWild = [self createHUGameCategoryFor:@"Animals Gone wild" andClues:animalsGoneWildClues]; + [gameCategoriesArray addObject:animalsGoneWild]; + + + NSMutableArray *accesscoders22 = [[NSMutableArray alloc] initWithArray:@[@"Artur Lan", @"Ayuna Vogel", @"Bereket Ghebremedhin", @"Brian Blanco", @"Charles H Kang", @"Chris David", @"Christella Dolmo", @"Christian Maldonado", @"Daaaaaammmmmmnnnnn Daniel", @"Derek Netto", @"Diana Elezaj", @"Elber Carneiro", @"Eric Sanchez", @"Eric Sze", @"Felicia Weathers", @"Henna Ahmed", @"Jackie Meggesto", @"Jamaal Sedayao", @"Jason Wang", @"Jovanny Espinal", @"Justine Gartner", @"Kaira Villanueva", @"Kaisha Jones", @"Krishna Picart", @"Lauren Caponong",@"Mesfin Bekele Mekonnen", @"Natalia Estrella", @"Shena Yoshida", @"Umar Mahmud", @"Varindra Hart", @"Xiulan Shi", @"Zoufishan Mehdi"]]; + + HUGameCategory *accessCode = [self createHUGameCategoryFor:@"iOS Legends" andClues:accesscoders22]; + + [gameCategoriesArray addObject:accessCode]; + + return gameCategoriesArray; +} + +@end diff --git a/HeadsUpper/HeadsUpper/HUCategoriesTableViewController.h b/HeadsUpper/HeadsUpper/HUCategoriesTableViewController.h new file mode 100644 index 0000000..9b95b3f --- /dev/null +++ b/HeadsUpper/HeadsUpper/HUCategoriesTableViewController.h @@ -0,0 +1,15 @@ +// +// HUCategoriesTableViewController.h +// HeadsUpper +// +// Created by Mesfin Bekele Mekonnen on 2/21/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import + +@interface HUCategoriesTableViewController : UITableViewController + + + +@end diff --git a/HeadsUpper/HeadsUpper/HUCategoriesTableViewController.m b/HeadsUpper/HeadsUpper/HUCategoriesTableViewController.m new file mode 100644 index 0000000..8a3aee5 --- /dev/null +++ b/HeadsUpper/HeadsUpper/HUCategoriesTableViewController.m @@ -0,0 +1,65 @@ +// +// HUCategoriesTableViewController.m +// HeadsUpper +// +// Created by Mesfin Bekele Mekonnen on 2/21/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import "HUCategoriesTableViewController.h" +#import "CategoryAndClueSetup.h" +#import "HUGameCategory.h" +#import "HUGameViewController.h" + +@interface HUCategoriesTableViewController () + +@property (nonatomic) NSMutableArray *categories; + +@end + +@implementation HUCategoriesTableViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + self.navigationItem.title = @"Heads UP!"; + self.tableView.dataSource = self; + self.tableView.delegate = self; + [self setup]; +} + +-(void)setup { + self.categories = [NSMutableArray new]; + CategoryAndClueSetup *categoriesAndClues = [[CategoryAndClueSetup alloc] initCategories]; + self.categories = categoriesAndClues.gameCategories; +} + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return self.categories.count; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CategoryCellIdentifier" forIndexPath:indexPath]; + [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; + + HUGameCategory *category = self.categories[indexPath.row]; + + cell.textLabel.text = category.name; + + return cell; +} + +-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + + HUGameViewController *gameVC = [self.storyboard instantiateViewControllerWithIdentifier:@"GameViewControllerID"]; + gameVC.category = self.categories[indexPath.row]; + + [self.navigationController pushViewController:gameVC animated:YES]; +} + +@end diff --git a/HeadsUpper/HeadsUpper/HUGameCategory+GameScore.h b/HeadsUpper/HeadsUpper/HUGameCategory+GameScore.h new file mode 100644 index 0000000..d50d7b8 --- /dev/null +++ b/HeadsUpper/HeadsUpper/HUGameCategory+GameScore.h @@ -0,0 +1,16 @@ +// +// HUGameCategory+GameScore.h +// HeadsUpper +// +// Created by Mesfin Bekele Mekonnen on 2/21/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import "HUGameCategory.h" + +@interface HUGameCategory (GameScore) + ++(NSString *)getreportForScore:(NSInteger)score andCategory:(HUGameCategory *)category; + + +@end diff --git a/HeadsUpper/HeadsUpper/HUGameCategory+GameScore.m b/HeadsUpper/HeadsUpper/HUGameCategory+GameScore.m new file mode 100644 index 0000000..5e332e4 --- /dev/null +++ b/HeadsUpper/HeadsUpper/HUGameCategory+GameScore.m @@ -0,0 +1,19 @@ +// +// HUGameCategory+GameScore.m +// HeadsUpper +// +// Created by Mesfin Bekele Mekonnen on 2/21/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import "HUGameCategory+GameScore.h" + +@implementation HUGameCategory (GameScore) + + ++(NSString *)getreportForScore:(NSInteger)score andCategory:(HUGameCategory *)category { + + return [NSString stringWithFormat:@"%d/%d", score,category.clues.count]; +} + +@end diff --git a/HeadsUpper/HeadsUpper/HUGameCategory.h b/HeadsUpper/HeadsUpper/HUGameCategory.h new file mode 100644 index 0000000..1a49c04 --- /dev/null +++ b/HeadsUpper/HeadsUpper/HUGameCategory.h @@ -0,0 +1,18 @@ +// +// HUGameCategory.h +// HeadsUpper +// +// Created by Mesfin Bekele Mekonnen on 2/21/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import + +@interface HUGameCategory : NSObject + +@property (nonatomic) NSString *name; +@property (nonatomic) NSMutableArray *clues; + +- (instancetype)initWithName:(NSString *)categoryName andClues:(NSMutableArray *)clues; + +@end diff --git a/HeadsUpper/HeadsUpper/HUGameCategory.m b/HeadsUpper/HeadsUpper/HUGameCategory.m new file mode 100644 index 0000000..2fb9a5f --- /dev/null +++ b/HeadsUpper/HeadsUpper/HUGameCategory.m @@ -0,0 +1,25 @@ +// +// HUGameCategory.m +// HeadsUpper +// +// Created by Mesfin Bekele Mekonnen on 2/21/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import "HUGameCategory.h" + +@implementation HUGameCategory + +- (instancetype)initWithName:(NSString *)categoryName andClues:(NSMutableArray *)clues{ + + if (self = [super init]) { + + self.name = categoryName; + self.clues = clues; + + return self; + } + return nil; +} + +@end diff --git a/HeadsUpper/HeadsUpper/HUGameViewController.h b/HeadsUpper/HeadsUpper/HUGameViewController.h new file mode 100644 index 0000000..05d9dcf --- /dev/null +++ b/HeadsUpper/HeadsUpper/HUGameViewController.h @@ -0,0 +1,16 @@ +// +// HUGameViewController.h +// HeadsUpper +// +// Created by Mesfin Bekele Mekonnen on 2/21/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import +#import "HUGameCategory.h" + +@interface HUGameViewController : UIViewController + +@property (nonatomic) HUGameCategory *category; + +@end diff --git a/HeadsUpper/HeadsUpper/HUGameViewController.m b/HeadsUpper/HeadsUpper/HUGameViewController.m new file mode 100644 index 0000000..ec3b842 --- /dev/null +++ b/HeadsUpper/HeadsUpper/HUGameViewController.m @@ -0,0 +1,245 @@ +// +// HUGameViewController.m +// HeadsUpper +// +// Created by Mesfin Bekele Mekonnen on 2/21/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import "HUGameViewController.h" +#import "HUGameCategory+GameScore.h" +#import + +@interface HUGameViewController () + +@property (weak, nonatomic) IBOutlet UILabel *clueLabel; +@property (weak, nonatomic) IBOutlet UILabel *timerLabel; + +@property (nonatomic) NSInteger gameScore; +@property (nonatomic) NSInteger currentIndex; +@property (nonatomic, assign) NSInteger timerCount; +@property (nonatomic) UISwipeGestureRecognizer *leftGesture; +@property (nonatomic) UISwipeGestureRecognizer *rightGesture; +@property (nonatomic) NSTimer *timer; +@property (nonatomic,strong) CMMotionManager *motionManager; +@property (nonatomic) BOOL isTilted; + +@end + +@implementation HUGameViewController + +#pragma mark - Life Cycle + +- (void)viewDidLoad { + + [super viewDidLoad]; + + [self setup]; + [self setupSwipeGestures]; + [self setupTimer]; + [self setupAccelerometer]; +} + + +-(void)viewWillDisappear:(BOOL)animated { + + [super viewWillDisappear:animated]; + + self.gameScore = 0; + self.currentIndex = 0; + self.timerCount = 0; +} + +#pragma mark - setup + +- (void)setup { + + self.navigationItem.title = @"Let's Play!"; + self.gameScore = 0; + self.currentIndex = 0; + self.timerCount = 0; + self.clueLabel.text =self.category.clues[self.currentIndex]; +} + +- (void)setupTimer { + + NSTimer *timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(timerFired:) userInfo:nil repeats:YES]; + + [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; + self.timer = timer; + [timer fire]; +} + +- (void)setupAccelerometer { + self.motionManager = [[CMMotionManager alloc]init]; + self.motionManager.accelerometerUpdateInterval = 1.0f/60.0f; + + [self.motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue] + withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) { + [self outputAccelerationData:accelerometerData.acceleration]; + if(error){ + NSLog(@"Error, no data for acceleroeter :%@",[error localizedDescription]); + } + }]; +} + +#pragma mark - Handle Timer + +- (void)timerFired:(NSTimer *)timer { + + self.timerCount++; + + if (self.timerCount > 20) { + self.timerLabel.text = [NSString stringWithFormat:@"0:0%d",30-self.timerCount]; + } + else { + self.timerLabel.text = [NSString stringWithFormat:@"0:%d",30-self.timerCount]; + } + if (self.timerCount >= 30) { + [timer invalidate]; + [self showAlert]; + } +} + +#pragma mark - Accelerometer + +- (void) outputAccelerationData:(CMAcceleration)acceleration{ + + if(self.timer){ + + if (!self.isTilted) { + if (acceleration.x > 0.4f) { + self.isTilted = YES; + [self correctAnswer]; + } + else if (acceleration.x < -0.4f) { + self.isTilted = YES; + [self skip]; + } + } + else { + if (acceleration.x < 0.2f && acceleration.x > -0.2f) { + self.isTilted = NO; + } + } + } +} + +- (void)correctAnswer { + + if (self.currentIndex < self.category.clues.count-1) { + + [self animateWithColor:[UIColor greenColor]]; + [self setupNextClue]; + self.gameScore+=1; + } + + else { + self.gameScore+=1; + [self showAlert]; + [self.timer invalidate]; + } + +} + +- (void)skip { + + if (self.currentIndex < self.category.clues.count-1) { + [self animateWithColor:[UIColor orangeColor]]; + [self setupNextClue]; + } + else { + [self showAlert]; + [self.timer invalidate]; + } +} + + +#pragma mark - Swipes + +- (void)setupSwipeGestures { + + UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeLeft:)]; + + swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft; + + [self.view addGestureRecognizer:swipeLeft]; + + self.leftGesture = swipeLeft; + + UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeRight:)]; + + swipeRight.direction = UISwipeGestureRecognizerDirectionRight; + + [self.view addGestureRecognizer:swipeRight]; + + self.rightGesture = swipeRight; +} + + +- (void)handleSwipeLeft:(UISwipeGestureRecognizer *)gesture { + + if (self.currentIndex < self.category.clues.count-1) { + [self animateWithColor:[UIColor orangeColor]]; + [self setupNextClue]; + } + else { + [self showAlert]; + [self.timer invalidate]; + } +} + +- (void)handleSwipeRight:(UISwipeGestureRecognizer *)gesture { + + if (self.currentIndex < self.category.clues.count-1) { + + [self animateWithColor:[UIColor greenColor]]; + [self setupNextClue]; + self.gameScore+=1; + } + else { + self.gameScore+=1; + [self showAlert]; + [self.timer invalidate]; + } +} + +-(void)removeGesture { + [self.view removeGestureRecognizer:self.leftGesture]; + [self.view removeGestureRecognizer:self.rightGesture]; +} + +#pragma mark - Label Helper Method + +-(void)setupNextClue { + self.currentIndex+=1; + self.clueLabel.text = self.category.clues[self.currentIndex]; +} + +#pragma mark - Alert + +-(void)showAlert { + NSString *score = [HUGameCategory getreportForScore:self.gameScore andCategory:self.category]; + + UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Game Over" message:[NSString stringWithFormat:@"You got: %@. Play another category!",score] preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]; + [alert addAction:okAction]; + + [self removeGesture]; + + [self presentViewController:alert animated:YES completion:nil]; +} + +#pragma mark - Animation Helper + +-(void)animateWithColor:(UIColor *)color { + + [UIView animateWithDuration:0.5 delay:0.09 options:UIViewAnimationOptionCurveEaseInOut animations:^{ + self.view.backgroundColor = color; + } completion:^(BOOL finished) { + self.view.backgroundColor = [UIColor whiteColor]; + }]; +} + +@end diff --git a/HeadsUpper/HeadsUpper/ViewController.h b/HeadsUpper/HeadsUpper/ViewController.h deleted file mode 100644 index 65d6cf5..0000000 --- a/HeadsUpper/HeadsUpper/ViewController.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// ViewController.h -// HeadsUpper -// -// Created by Michael Kavouras on 2/17/16. -// Copyright © 2016 Michael Kavouras. All rights reserved. -// - -#import - -@interface ViewController : UIViewController - - -@end - diff --git a/HeadsUpper/HeadsUpper/ViewController.m b/HeadsUpper/HeadsUpper/ViewController.m deleted file mode 100644 index 14ce57a..0000000 --- a/HeadsUpper/HeadsUpper/ViewController.m +++ /dev/null @@ -1,27 +0,0 @@ -// -// ViewController.m -// HeadsUpper -// -// Created by Michael Kavouras on 2/17/16. -// Copyright © 2016 Michael Kavouras. All rights reserved. -// - -#import "ViewController.h" - -@interface ViewController () - -@end - -@implementation ViewController - -- (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