From 477cd7aa7a06751fa89cf7e050f08d932681144c Mon Sep 17 00:00:00 2001 From: Xiulan Shi Date: Sun, 21 Feb 2016 15:19:58 -0500 Subject: [PATCH 1/4] Basic requirement done --- .../HeadsUpper.xcodeproj/project.pbxproj | 31 +++- .../HeadsUpper/Base.lproj/Main.storyboard | 105 ++++++++++-- HeadsUpper/HeadsUpper/CategoryModel.h | 19 +++ HeadsUpper/HeadsUpper/CategoryModel.m | 75 +++++++++ .../CategorySelectionTableViewController.h | 17 ++ .../CategorySelectionTableViewController.m | 67 ++++++++ HeadsUpper/HeadsUpper/GameCategory.h | 16 ++ HeadsUpper/HeadsUpper/GameCategory.m | 14 ++ HeadsUpper/HeadsUpper/GameViewController.h | 16 ++ HeadsUpper/HeadsUpper/GameViewController.m | 156 ++++++++++++++++++ HeadsUpper/HeadsUpper/ViewController.h | 15 -- HeadsUpper/HeadsUpper/ViewController.m | 27 --- 12 files changed, 500 insertions(+), 58 deletions(-) create mode 100644 HeadsUpper/HeadsUpper/CategoryModel.h create mode 100644 HeadsUpper/HeadsUpper/CategoryModel.m create mode 100644 HeadsUpper/HeadsUpper/CategorySelectionTableViewController.h create mode 100644 HeadsUpper/HeadsUpper/CategorySelectionTableViewController.m create mode 100644 HeadsUpper/HeadsUpper/GameCategory.h create mode 100644 HeadsUpper/HeadsUpper/GameCategory.m create mode 100644 HeadsUpper/HeadsUpper/GameViewController.h create mode 100644 HeadsUpper/HeadsUpper/GameViewController.m delete mode 100644 HeadsUpper/HeadsUpper/ViewController.h delete mode 100644 HeadsUpper/HeadsUpper/ViewController.m diff --git a/HeadsUpper/HeadsUpper.xcodeproj/project.pbxproj b/HeadsUpper/HeadsUpper.xcodeproj/project.pbxproj index fb900f8..c9c8a4b 100644 --- a/HeadsUpper/HeadsUpper.xcodeproj/project.pbxproj +++ b/HeadsUpper/HeadsUpper.xcodeproj/project.pbxproj @@ -7,21 +7,30 @@ objects = { /* Begin PBXBuildFile section */ + 6DF05E311C7A152200E67A7A /* CategorySelectionTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6DF05E301C7A152100E67A7A /* CategorySelectionTableViewController.m */; }; + 6DF05E341C7A15F000E67A7A /* GameViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6DF05E331C7A15F000E67A7A /* GameViewController.m */; }; + 6DF05E3A1C7A192A00E67A7A /* GameCategory.m in Sources */ = {isa = PBXBuildFile; fileRef = 6DF05E391C7A192A00E67A7A /* GameCategory.m */; }; + 6DF05E3D1C7A1AA500E67A7A /* CategoryModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 6DF05E3C1C7A1AA500E67A7A /* CategoryModel.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 */ + 6DF05E2F1C7A152100E67A7A /* CategorySelectionTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CategorySelectionTableViewController.h; sourceTree = ""; }; + 6DF05E301C7A152100E67A7A /* CategorySelectionTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CategorySelectionTableViewController.m; sourceTree = ""; }; + 6DF05E321C7A15F000E67A7A /* GameViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GameViewController.h; sourceTree = ""; }; + 6DF05E331C7A15F000E67A7A /* GameViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GameViewController.m; sourceTree = ""; }; + 6DF05E381C7A192A00E67A7A /* GameCategory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GameCategory.h; sourceTree = ""; }; + 6DF05E391C7A192A00E67A7A /* GameCategory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GameCategory.m; sourceTree = ""; }; + 6DF05E3B1C7A1AA500E67A7A /* CategoryModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CategoryModel.h; sourceTree = ""; }; + 6DF05E3C1C7A1AA500E67A7A /* CategoryModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CategoryModel.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 = ""; }; @@ -60,8 +69,14 @@ children = ( 8D89695D1C755D0200D32E8A /* AppDelegate.h */, 8D89695E1C755D0200D32E8A /* AppDelegate.m */, - 8D8969601C755D0200D32E8A /* ViewController.h */, - 8D8969611C755D0200D32E8A /* ViewController.m */, + 6DF05E381C7A192A00E67A7A /* GameCategory.h */, + 6DF05E391C7A192A00E67A7A /* GameCategory.m */, + 6DF05E3B1C7A1AA500E67A7A /* CategoryModel.h */, + 6DF05E3C1C7A1AA500E67A7A /* CategoryModel.m */, + 6DF05E2F1C7A152100E67A7A /* CategorySelectionTableViewController.h */, + 6DF05E301C7A152100E67A7A /* CategorySelectionTableViewController.m */, + 6DF05E321C7A15F000E67A7A /* GameViewController.h */, + 6DF05E331C7A15F000E67A7A /* GameViewController.m */, 8D8969631C755D0200D32E8A /* Main.storyboard */, 8D8969661C755D0200D32E8A /* Assets.xcassets */, 8D8969681C755D0200D32E8A /* LaunchScreen.storyboard */, @@ -149,9 +164,12 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 8D8969621C755D0200D32E8A /* ViewController.m in Sources */, + 6DF05E341C7A15F000E67A7A /* GameViewController.m in Sources */, + 6DF05E3D1C7A1AA500E67A7A /* CategoryModel.m in Sources */, 8D89695F1C755D0200D32E8A /* AppDelegate.m in Sources */, 8D89695C1C755D0200D32E8A /* main.m in Sources */, + 6DF05E3A1C7A192A00E67A7A /* GameCategory.m in Sources */, + 6DF05E311C7A152200E67A7A /* CategorySelectionTableViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -300,6 +318,7 @@ 8D8969701C755D0200D32E8A /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/HeadsUpper/HeadsUpper/Base.lproj/Main.storyboard b/HeadsUpper/HeadsUpper/Base.lproj/Main.storyboard index f56d2f3..895f4a9 100644 --- a/HeadsUpper/HeadsUpper/Base.lproj/Main.storyboard +++ b/HeadsUpper/HeadsUpper/Base.lproj/Main.storyboard @@ -1,25 +1,110 @@ - + - + + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + - + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + diff --git a/HeadsUpper/HeadsUpper/CategoryModel.h b/HeadsUpper/HeadsUpper/CategoryModel.h new file mode 100644 index 0000000..c4c221d --- /dev/null +++ b/HeadsUpper/HeadsUpper/CategoryModel.h @@ -0,0 +1,19 @@ +// +// CategoryModel.h +// HeadsUpper +// +// Created by Xiulan Shi on 2/21/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import + +@interface CategoryModel : NSObject + +@property (nonatomic) NSMutableArray *categories; + ++ (instancetype)sharedInstance; + +- (void)initializeModel; + +@end diff --git a/HeadsUpper/HeadsUpper/CategoryModel.m b/HeadsUpper/HeadsUpper/CategoryModel.m new file mode 100644 index 0000000..9b10aba --- /dev/null +++ b/HeadsUpper/HeadsUpper/CategoryModel.m @@ -0,0 +1,75 @@ +// +// CategoryModel.m +// HeadsUpper +// +// Created by Xiulan Shi on 2/21/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import "CategoryModel.h" +#import "GameCategory.h" + +@implementation CategoryModel + + ++ (instancetype)sharedInstance { + + static CategoryModel *sharedInstance = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + sharedInstance = [[CategoryModel alloc] init]; + }); + return sharedInstance; + +} + +- (void)initializeModel { + + self.categories = [[NSMutableArray alloc] init]; + + GameCategory *superStars = [[GameCategory alloc] init]; + + superStars.name = @"Superstars"; + + superStars.questions = @[@"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"]; + + [self.categories addObject:superStars]; + + GameCategory *thatsSo90s = [[GameCategory alloc] init]; + + thatsSo90s.name = @"That's so 90s"; + + thatsSo90s.questions = @[@"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"]; + + [self.categories addObject:thatsSo90s]; + + GameCategory *heyMrDJ = [[GameCategory alloc] init]; + + heyMrDJ.name = @"Hey Mr. DJ"; + + heyMrDJ.questions = @[@"\"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\""]; + + [self.categories addObject:heyMrDJ]; + + GameCategory *icons = [[GameCategory alloc] init]; + + icons.name = @"Icons"; + + icons.questions = @[@"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"];; + + [self.categories addObject:icons]; + + + GameCategory *animalsGoneWild = [[GameCategory alloc] init]; + + animalsGoneWild.name = @"Animals Gone Wild"; + + animalsGoneWild.questions = @[@"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"]; + + [self.categories addObject:animalsGoneWild]; + + +} + + +@end diff --git a/HeadsUpper/HeadsUpper/CategorySelectionTableViewController.h b/HeadsUpper/HeadsUpper/CategorySelectionTableViewController.h new file mode 100644 index 0000000..2b97637 --- /dev/null +++ b/HeadsUpper/HeadsUpper/CategorySelectionTableViewController.h @@ -0,0 +1,17 @@ +// +// CategorySelectionTableViewController.h +// HeadsUpper +// +// Created by Xiulan Shi on 2/21/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import +#import "GameCategory.h" +#import "CategoryModel.h" + +@interface CategorySelectionTableViewController : UITableViewController + +@property (nonatomic) CategoryModel *model; + +@end diff --git a/HeadsUpper/HeadsUpper/CategorySelectionTableViewController.m b/HeadsUpper/HeadsUpper/CategorySelectionTableViewController.m new file mode 100644 index 0000000..f39ec1d --- /dev/null +++ b/HeadsUpper/HeadsUpper/CategorySelectionTableViewController.m @@ -0,0 +1,67 @@ +// +// CategorySelectionTableViewController.m +// HeadsUpper +// +// Created by Xiulan Shi on 2/21/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import "CategorySelectionTableViewController.h" +#import "GameViewController.h" + +@interface CategorySelectionTableViewController () + +@end + +@implementation CategorySelectionTableViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + self.model = [CategoryModel sharedInstance]; + [self.model initializeModel]; +} + +- (void)viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; + + [self.tableView reloadData]; +} + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + + return self.model.categories.count; +} + + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier" forIndexPath:indexPath]; + + GameCategory *category = [self.model.categories objectAtIndex:indexPath.row]; + + cell.textLabel.text = category.name; + + return cell; +} + +#pragma mark - Navigation + +// In a storyboard-based application, you will often want to do a little preparation before navigation +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + + NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; + GameCategory *currentCategory = [self.model.categories objectAtIndex:indexPath.row]; + GameViewController *detailVC = segue.destinationViewController; + detailVC.category = currentCategory; + +} + + +@end diff --git a/HeadsUpper/HeadsUpper/GameCategory.h b/HeadsUpper/HeadsUpper/GameCategory.h new file mode 100644 index 0000000..2995bf5 --- /dev/null +++ b/HeadsUpper/HeadsUpper/GameCategory.h @@ -0,0 +1,16 @@ +// +// GameCategory.h +// HeadsUpper +// +// Created by Xiulan Shi on 2/21/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import + +@interface GameCategory : NSObject + +@property (nonatomic) NSString *name; +@property (nonatomic) NSArray *questions; + +@end diff --git a/HeadsUpper/HeadsUpper/GameCategory.m b/HeadsUpper/HeadsUpper/GameCategory.m new file mode 100644 index 0000000..fd272b2 --- /dev/null +++ b/HeadsUpper/HeadsUpper/GameCategory.m @@ -0,0 +1,14 @@ +// +// GameCategory.m +// HeadsUpper +// +// Created by Xiulan Shi on 2/21/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import "GameCategory.h" + +@implementation GameCategory + + +@end diff --git a/HeadsUpper/HeadsUpper/GameViewController.h b/HeadsUpper/HeadsUpper/GameViewController.h new file mode 100644 index 0000000..f5f8708 --- /dev/null +++ b/HeadsUpper/HeadsUpper/GameViewController.h @@ -0,0 +1,16 @@ +// +// GameViewController.h +// HeadsUpper +// +// Created by Xiulan Shi on 2/21/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import +#import "GameCategory.h" + +@interface GameViewController : UIViewController + +@property (nonatomic) GameCategory *category; + +@end diff --git a/HeadsUpper/HeadsUpper/GameViewController.m b/HeadsUpper/HeadsUpper/GameViewController.m new file mode 100644 index 0000000..abf1a27 --- /dev/null +++ b/HeadsUpper/HeadsUpper/GameViewController.m @@ -0,0 +1,156 @@ +// +// GameViewController.m +// HeadsUpper +// +// Created by Xiulan Shi on 2/21/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import "GameViewController.h" +#import "CategoryModel.h" + +@interface GameViewController () + +@property (weak, nonatomic) IBOutlet UILabel *timerLabel; +@property (weak, nonatomic) IBOutlet UILabel *questionLabel; + +@property (nonatomic, assign) NSInteger timerCount; + +@property (nonatomic) NSMutableArray *questions; + +@property (nonatomic) NSInteger totalCount; +@property (nonatomic) NSInteger correctCount; + + +@end + +@implementation GameViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view. + + self.questions = [self.category.questions mutableCopy]; + + self.questionLabel.text = [self nextQuestion]; + + [self setupTimer]; + [self setupGestureRecognizers]; + +} + + +- (NSString*) nextQuestion { + + NSString *question; + if (self.questions.count > 0) { + int size = (int)[self.questions count] - 1; + int r = arc4random_uniform(size); + question = self.questions[r]; + + // also need to remove integer + + } + else {NSLog(@"no more unique questions"); } + + return question; +} + + +- (void)setupTimer { + + NSTimer *timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(timerFired:) userInfo:nil repeats:YES]; + + [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; + + self.timerCount = 10; + + [timer fire]; + +} + +- (void)timerFired:(NSTimer *)timer { + + if (self.timerCount == 0) { + [timer invalidate]; + [self showAlert]; + + } + + // determine time left on timer + + NSString *string = [[NSNumber numberWithInteger: self.timerCount] stringValue]; + + self.timerLabel.text = string; + + self.timerCount--; + + +} + +- (void)showAlert { + UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Game Over" message:[NSString stringWithFormat:@"%ld/%ld", self.correctCount, self.totalCount] delegate:nil cancelButtonTitle:@"Done" otherButtonTitles:nil]; + + [alert show]; +} + + +- (void)setupGestureRecognizers +{ + UISwipeGestureRecognizer *leftSwipe = [[UISwipeGestureRecognizer alloc] + initWithTarget: self + action: @selector(handleSwipe :)]; + leftSwipe.direction = UISwipeGestureRecognizerDirectionLeft; + + UISwipeGestureRecognizer *rightSwipe = [[UISwipeGestureRecognizer alloc] + initWithTarget: self + action: @selector(handleSwipe :)]; + rightSwipe.direction = UISwipeGestureRecognizerDirectionRight; + + + [self.view addGestureRecognizer:leftSwipe]; + [self.view addGestureRecognizer:rightSwipe]; + +} + +-(void)handleSwipe:(UISwipeGestureRecognizer *)gesture +{ + switch (gesture.direction) { + case UISwipeGestureRecognizerDirectionLeft: + self.view.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:1]; + [UIView beginAnimations:@"fade out" context:nil]; + [UIView setAnimationDuration:0.8]; + self.view.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:1]; + [UIView commitAnimations]; + self.totalCount += 1; + self.questionLabel.text = [self nextQuestion]; + break; + + case UISwipeGestureRecognizerDirectionRight: + self.view.backgroundColor = [[UIColor greenColor] colorWithAlphaComponent:1]; + [UIView beginAnimations:@"fade out" context:nil]; + [UIView setAnimationDuration:0.8]; + self.view.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:1]; + [UIView commitAnimations]; + self.correctCount += 1; + self.totalCount += 1; + self.questionLabel.text = [self nextQuestion]; + break; + + default: + return; + } +} + + +/* +#pragma mark - Navigation + +// In a storyboard-based application, you will often want to do a little preparation before navigation +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + // Get the new view controller using [segue destinationViewController]. + // Pass the selected object to the new view controller. +} +*/ + +@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 From 20eabd78ff7f991c9cfc2979018b87fa08426e8b Mon Sep 17 00:00:00 2001 From: Xiulan Shi Date: Sun, 21 Feb 2016 15:47:16 -0500 Subject: [PATCH 2/4] Remove Gesture when timerCount is 0 --- HeadsUpper/HeadsUpper/Base.lproj/Main.storyboard | 4 ++-- HeadsUpper/HeadsUpper/GameViewController.m | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/HeadsUpper/HeadsUpper/Base.lproj/Main.storyboard b/HeadsUpper/HeadsUpper/Base.lproj/Main.storyboard index 895f4a9..15cac7b 100644 --- a/HeadsUpper/HeadsUpper/Base.lproj/Main.storyboard +++ b/HeadsUpper/HeadsUpper/Base.lproj/Main.storyboard @@ -5,10 +5,10 @@ - + - + diff --git a/HeadsUpper/HeadsUpper/GameViewController.m b/HeadsUpper/HeadsUpper/GameViewController.m index abf1a27..0116708 100644 --- a/HeadsUpper/HeadsUpper/GameViewController.m +++ b/HeadsUpper/HeadsUpper/GameViewController.m @@ -74,7 +74,10 @@ - (void)timerFired:(NSTimer *)timer { if (self.timerCount == 0) { [timer invalidate]; [self showAlert]; - + + for (UIGestureRecognizer *recognizer in self.view.gestureRecognizers) { + [self.view removeGestureRecognizer:recognizer]; + } } // determine time left on timer @@ -143,6 +146,8 @@ -(void)handleSwipe:(UISwipeGestureRecognizer *)gesture } + + /* #pragma mark - Navigation From 9ec888c89a9c396f5d7e8a485cfee613b9c7e3b8 Mon Sep 17 00:00:00 2001 From: Xiulan Shi Date: Sun, 21 Feb 2016 16:51:28 -0500 Subject: [PATCH 3/4] Invalidate the timer when dismiss the game viewcontroller --- HeadsUpper/HeadsUpper/AppDelegate.m | 3 +++ .../HeadsUpper/Base.lproj/Main.storyboard | 22 +++++++++++++------ HeadsUpper/HeadsUpper/GameViewController.m | 22 +++++++++++++------ HeadsUpper/HeadsUpper/Info.plist | 2 ++ 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/HeadsUpper/HeadsUpper/AppDelegate.m b/HeadsUpper/HeadsUpper/AppDelegate.m index b8814af..11956ea 100644 --- a/HeadsUpper/HeadsUpper/AppDelegate.m +++ b/HeadsUpper/HeadsUpper/AppDelegate.m @@ -17,6 +17,9 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. + + [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; + return YES; } diff --git a/HeadsUpper/HeadsUpper/Base.lproj/Main.storyboard b/HeadsUpper/HeadsUpper/Base.lproj/Main.storyboard index 15cac7b..d3a8233 100644 --- a/HeadsUpper/HeadsUpper/Base.lproj/Main.storyboard +++ b/HeadsUpper/HeadsUpper/Base.lproj/Main.storyboard @@ -3,12 +3,13 @@ + - + @@ -40,7 +41,7 @@ - + @@ -58,16 +59,16 @@ - @@ -75,9 +76,16 @@ + + + + + + + diff --git a/HeadsUpper/HeadsUpper/GameViewController.m b/HeadsUpper/HeadsUpper/GameViewController.m index 0116708..7215510 100644 --- a/HeadsUpper/HeadsUpper/GameViewController.m +++ b/HeadsUpper/HeadsUpper/GameViewController.m @@ -21,6 +21,8 @@ @interface GameViewController () @property (nonatomic) NSInteger totalCount; @property (nonatomic) NSInteger correctCount; +@property (nonatomic) NSTimer *timer; + @end @@ -39,6 +41,12 @@ - (void)viewDidLoad { } +- (void)viewWillDisappear:(BOOL)animated { + [super viewWillDisappear:animated]; + + [self.timer invalidate]; +} + - (NSString*) nextQuestion { @@ -59,20 +67,20 @@ - (NSString*) nextQuestion { - (void)setupTimer { - NSTimer *timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(timerFired:) userInfo:nil repeats:YES]; + self.timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(timerFired) userInfo:nil repeats:YES]; - [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; + [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes]; self.timerCount = 10; - [timer fire]; + [self.timer fire]; } -- (void)timerFired:(NSTimer *)timer { +- (void)timerFired { if (self.timerCount == 0) { - [timer invalidate]; + [self.timer invalidate]; [self showAlert]; for (UIGestureRecognizer *recognizer in self.view.gestureRecognizers) { @@ -122,7 +130,7 @@ -(void)handleSwipe:(UISwipeGestureRecognizer *)gesture case UISwipeGestureRecognizerDirectionLeft: self.view.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:1]; [UIView beginAnimations:@"fade out" context:nil]; - [UIView setAnimationDuration:0.8]; + [UIView setAnimationDuration:0.5]; self.view.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:1]; [UIView commitAnimations]; self.totalCount += 1; @@ -132,7 +140,7 @@ -(void)handleSwipe:(UISwipeGestureRecognizer *)gesture case UISwipeGestureRecognizerDirectionRight: self.view.backgroundColor = [[UIColor greenColor] colorWithAlphaComponent:1]; [UIView beginAnimations:@"fade out" context:nil]; - [UIView setAnimationDuration:0.8]; + [UIView setAnimationDuration:0.5]; self.view.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:1]; [UIView commitAnimations]; self.correctCount += 1; diff --git a/HeadsUpper/HeadsUpper/Info.plist b/HeadsUpper/HeadsUpper/Info.plist index 6905cc6..811a243 100644 --- a/HeadsUpper/HeadsUpper/Info.plist +++ b/HeadsUpper/HeadsUpper/Info.plist @@ -30,6 +30,8 @@ armv7 + UIStatusBarStyle + UIStatusBarStyleLightContent UISupportedInterfaceOrientations UIInterfaceOrientationPortrait From 37ecab11e6f701313750364ea67f36bc2b6ef6b9 Mon Sep 17 00:00:00 2001 From: Xiulan Shi Date: Sun, 21 Feb 2016 18:20:41 -0500 Subject: [PATCH 4/4] Done --- HeadsUpper/HeadsUpper/GameViewController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HeadsUpper/HeadsUpper/GameViewController.m b/HeadsUpper/HeadsUpper/GameViewController.m index 7215510..3bebe19 100644 --- a/HeadsUpper/HeadsUpper/GameViewController.m +++ b/HeadsUpper/HeadsUpper/GameViewController.m @@ -100,7 +100,7 @@ - (void)timerFired { } - (void)showAlert { - UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Game Over" message:[NSString stringWithFormat:@"%ld/%ld", self.correctCount, self.totalCount] delegate:nil cancelButtonTitle:@"Done" otherButtonTitles:nil]; + UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Game Over" message:[NSString stringWithFormat:@"%ld/%ld", (long)self.correctCount,(long)self.totalCount] delegate:nil cancelButtonTitle:@"Done" otherButtonTitles:nil]; [alert show]; }