diff --git a/HeadsUpper/.gitignore b/HeadsUpper/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/HeadsUpper/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/HeadsUpper/HeadsUpper.xcodeproj/project.pbxproj b/HeadsUpper/HeadsUpper.xcodeproj/project.pbxproj index fb900f8..b457a85 100644 --- a/HeadsUpper/HeadsUpper.xcodeproj/project.pbxproj +++ b/HeadsUpper/HeadsUpper.xcodeproj/project.pbxproj @@ -7,21 +7,30 @@ objects = { /* Begin PBXBuildFile section */ + 5A3055D51C7A430E00100C42 /* TitlesTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5A3055D41C7A430E00100C42 /* TitlesTableViewController.m */; }; + 5A3591E91C7AF5E400546A0B /* GestureManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 5A3591E81C7AF5E400546A0B /* GestureManager.m */; }; + 5A4C555A1C7A62A70098B1B6 /* GameData.m in Sources */ = {isa = PBXBuildFile; fileRef = 5A4C55591C7A62A70098B1B6 /* GameData.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 */; }; + 8D8969621C755D0200D32E8A /* GameViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D8969611C755D0200D32E8A /* GameViewController.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 */ + 5A3055D31C7A430D00100C42 /* TitlesTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TitlesTableViewController.h; sourceTree = ""; }; + 5A3055D41C7A430E00100C42 /* TitlesTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TitlesTableViewController.m; sourceTree = ""; }; + 5A3591E71C7AF5E400546A0B /* GestureManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GestureManager.h; sourceTree = ""; }; + 5A3591E81C7AF5E400546A0B /* GestureManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GestureManager.m; sourceTree = ""; }; + 5A4C55581C7A62A70098B1B6 /* GameData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GameData.h; sourceTree = ""; }; + 5A4C55591C7A62A70098B1B6 /* GameData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GameData.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 = ""; }; + 8D8969601C755D0200D32E8A /* GameViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GameViewController.h; sourceTree = ""; }; + 8D8969611C755D0200D32E8A /* GameViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GameViewController.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 */, + 8D8969601C755D0200D32E8A /* GameViewController.h */, + 8D8969611C755D0200D32E8A /* GameViewController.m */, + 5A3055D31C7A430D00100C42 /* TitlesTableViewController.h */, + 5A3055D41C7A430E00100C42 /* TitlesTableViewController.m */, + 5A3591E71C7AF5E400546A0B /* GestureManager.h */, + 5A3591E81C7AF5E400546A0B /* GestureManager.m */, + 5A4C55581C7A62A70098B1B6 /* GameData.h */, + 5A4C55591C7A62A70098B1B6 /* GameData.m */, 8D8969631C755D0200D32E8A /* Main.storyboard */, 8D8969661C755D0200D32E8A /* Assets.xcassets */, 8D8969681C755D0200D32E8A /* LaunchScreen.storyboard */, @@ -149,8 +164,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 8D8969621C755D0200D32E8A /* ViewController.m in Sources */, + 8D8969621C755D0200D32E8A /* GameViewController.m in Sources */, + 5A3591E91C7AF5E400546A0B /* GestureManager.m in Sources */, + 5A4C555A1C7A62A70098B1B6 /* GameData.m in Sources */, 8D89695F1C755D0200D32E8A /* AppDelegate.m in Sources */, + 5A3055D51C7A430E00100C42 /* TitlesTableViewController.m in Sources */, 8D89695C1C755D0200D32E8A /* main.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..645c3f6 100644 --- a/HeadsUpper/HeadsUpper/Base.lproj/Main.storyboard +++ b/HeadsUpper/HeadsUpper/Base.lproj/Main.storyboard @@ -1,25 +1,108 @@ - + - + + + + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + - + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + diff --git a/HeadsUpper/HeadsUpper/GameData.h b/HeadsUpper/HeadsUpper/GameData.h new file mode 100644 index 0000000..eebf371 --- /dev/null +++ b/HeadsUpper/HeadsUpper/GameData.h @@ -0,0 +1,20 @@ +// +// GameData.h +// HeadsUpper +// +// Created by Brian Blanco on 2/21/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import + +@interface GameData : NSObject + +@property (strong, nonatomic) NSString *title; +@property (strong, nonatomic) NSArray *subject; + +- (id)initWithTitle:(NSString *)title; ++ (id) topicWithTitle:(NSString *)title; + + +@end diff --git a/HeadsUpper/HeadsUpper/GameData.m b/HeadsUpper/HeadsUpper/GameData.m new file mode 100644 index 0000000..8f119bd --- /dev/null +++ b/HeadsUpper/HeadsUpper/GameData.m @@ -0,0 +1,29 @@ +// +// GameData.m +// HeadsUpper +// +// Created by Brian Blanco on 2/21/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import "GameData.h" + +@implementation GameData + + +- (instancetype)initWithTitle:(NSString *)title +{ + self = [super init]; + if (self) { + self.title = title; + + } + return self; +} + ++ (id)topicWithTitle:(NSString *)title +{ + return [[self alloc] initWithTitle:title]; +} + +@end diff --git a/HeadsUpper/HeadsUpper/GameViewController.h b/HeadsUpper/HeadsUpper/GameViewController.h new file mode 100644 index 0000000..f316519 --- /dev/null +++ b/HeadsUpper/HeadsUpper/GameViewController.h @@ -0,0 +1,22 @@ +// +// ViewController.h +// HeadsUpper +// +// Created by Michael Kavouras on 2/17/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import +#import "GameData.h" + +@interface GameViewController : UIViewController + +@property (strong, nonatomic)NSString *category; +@property (strong, nonatomic)GameData *data; +@property (nonatomic) NSUInteger correct; +@property (nonatomic) NSUInteger incorrect; + +-(void) randomClue; + +@end + diff --git a/HeadsUpper/HeadsUpper/GameViewController.m b/HeadsUpper/HeadsUpper/GameViewController.m new file mode 100644 index 0000000..1bc7bc0 --- /dev/null +++ b/HeadsUpper/HeadsUpper/GameViewController.m @@ -0,0 +1,137 @@ +// +// ViewController.m +// HeadsUpper +// +// Created by Michael Kavouras on 2/17/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import "GameViewController.h" + + +@interface GameViewController () + +@property (weak, nonatomic) IBOutlet UILabel *gameLabel; +@property (weak, nonatomic) IBOutlet UILabel *timerLabel; +@property (nonatomic) NSString *message; +@property (nonatomic) NSUInteger count; +@property (nonatomic) NSUInteger totalScore; + +@property (nonatomic) NSTimer *countDown; + +@end + +@implementation GameViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + [self randomClue]; + [self timerCountDown]; + +} + +- (void)viewDidAppear:(BOOL)animated +{ + [self gestures]; +} + +- (void)gestures +{ + UISwipeGestureRecognizer *left = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipManager:)]; + left.direction = UISwipeGestureRecognizerDirectionLeft; + + UISwipeGestureRecognizer *right = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipManager:)]; + right.direction = UISwipeGestureRecognizerDirectionRight; + + + [self.view addGestureRecognizer:left]; + [self.view addGestureRecognizer:right]; + +} + +- (void)swipManager:(UISwipeGestureRecognizer *)gesture +{ + switch (gesture.direction) { + case UISwipeGestureRecognizerDirectionRight: + self.view.backgroundColor = [UIColor redColor]; + self.correct++; + [self randomClue]; + break; + case UISwipeGestureRecognizerDirectionLeft: + self.view.backgroundColor = [UIColor greenColor]; + self.incorrect++; + [self randomClue]; + break; + + + default: + return; + + } +} + +-(NSString *)scoreKeeper +{ + self.totalScore = self.correct + self.incorrect; + return self.message = [NSString stringWithFormat:@"%i/%i", self.correct, self.incorrect]; +} + +-(void) randomClue +{ + NSUInteger shuffleSubjects = arc4random_uniform(self.data.subject.count); + + NSString *shuffledSubject = [self.data.subject objectAtIndex: shuffleSubjects]; + + self.gameLabel.text = shuffledSubject; + + +} + +-(void) timerCountDown +{ + self.count = 20; + self.countDown = [NSTimer scheduledTimerWithTimeInterval:1.0 + target:self + selector:@selector(startCounting) + userInfo:nil + repeats:YES]; +} + +-(void)startCounting +{ + self.count--; + self.timerLabel.text = [NSString stringWithFormat:@"%i", self.count]; + + if (self.count == 0) { + [self.countDown invalidate]; + + UIAlertView *alert = [[UIAlertView alloc] + initWithTitle:@"Game Over" + message:self.scoreKeeper + delegate:self + cancelButtonTitle:@"Done" + otherButtonTitles:nil]; + + [alert show]; + + } + +} + +/* found resource here http://stackoverflow.com/questions/25806040/how-to-unwind-segues-from-uialertview-button */ +- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex +{ + //Using buttonIndex you could find whether OK or CANCEL is pressed and perform your popToRootViewController call. + //Below on OK press then moving to root VC + if (buttonIndex==0) + { + //OK is pressed... + [self.navigationController popToRootViewControllerAnimated:YES]; + } +} + + + + +@end diff --git a/HeadsUpper/HeadsUpper/GestureManager.h b/HeadsUpper/HeadsUpper/GestureManager.h new file mode 100644 index 0000000..3733d78 --- /dev/null +++ b/HeadsUpper/HeadsUpper/GestureManager.h @@ -0,0 +1,17 @@ +// +// GestureManager.h +// HeadsUpper +// +// Created by Brian Blanco on 2/22/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import +#import + +@interface GestureManager : NSObject + +- (void)gestures; +- (void)swipManager:(UISwipeGestureRecognizer *)gesture; + +@end diff --git a/HeadsUpper/HeadsUpper/GestureManager.m b/HeadsUpper/HeadsUpper/GestureManager.m new file mode 100644 index 0000000..48bb771 --- /dev/null +++ b/HeadsUpper/HeadsUpper/GestureManager.m @@ -0,0 +1,53 @@ +// +// GestureManager.m +// HeadsUpper +// +// Created by Brian Blanco on 2/22/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import "GestureManager.h" +#import "GameViewController.h" + +@implementation GestureManager + +- (void)gestures +{ + GameViewController *vc = [[GameViewController alloc] init]; + UISwipeGestureRecognizer *left = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipManager:)]; + left.direction = UISwipeGestureRecognizerDirectionLeft; + + UISwipeGestureRecognizer *right = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipManager:)]; + right.direction = UISwipeGestureRecognizerDirectionRight; + + + [vc.view addGestureRecognizer:left]; + [vc.view addGestureRecognizer:right]; + +} + +- (void)swipManager:(UISwipeGestureRecognizer *)gesture +{ + GameViewController *vc = [[GameViewController alloc] init]; + switch (gesture.direction) { + case UISwipeGestureRecognizerDirectionRight: + vc.view.backgroundColor = [UIColor redColor]; + vc.correct++; + [vc randomClue]; + break; + case UISwipeGestureRecognizerDirectionLeft: + vc.view.backgroundColor = [UIColor greenColor]; + vc.incorrect++; + [vc randomClue]; + break; + + + default: + return; + + } +} + + + +@end diff --git a/HeadsUpper/HeadsUpper/TitlesTableViewController.h b/HeadsUpper/HeadsUpper/TitlesTableViewController.h new file mode 100644 index 0000000..c2d9872 --- /dev/null +++ b/HeadsUpper/HeadsUpper/TitlesTableViewController.h @@ -0,0 +1,17 @@ +// +// TitlesTableViewController.h +// HeadsUpper +// +// Created by Brian Blanco on 2/21/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import + + +@interface TitlesTableViewController : UITableViewController + +@property (strong, nonatomic) NSMutableArray *topics; +@property (strong, nonatomic) NSMutableArray *subjects; + +@end diff --git a/HeadsUpper/HeadsUpper/TitlesTableViewController.m b/HeadsUpper/HeadsUpper/TitlesTableViewController.m new file mode 100644 index 0000000..9cca3ae --- /dev/null +++ b/HeadsUpper/HeadsUpper/TitlesTableViewController.m @@ -0,0 +1,91 @@ +// +// TitlesTableViewController.m +// HeadsUpper +// +// Created by Brian Blanco on 2/21/16. +// Copyright © 2016 Michael Kavouras. All rights reserved. +// + +#import "TitlesTableViewController.h" +#import "GameData.h" +#import "GameViewController.h" + + +@interface TitlesTableViewController () + +@end + +@implementation TitlesTableViewController + + +- (void)viewDidLoad { + [super viewDidLoad]; + + [self fetchHeadsUpperAPI]; +} + +- (void) fetchHeadsUpperAPI +{ + NSURL *topicsURL = [NSURL URLWithString:@"https://heads-up-api.herokuapp.com/"]; + + NSData *jsonData = [NSData dataWithContentsOfURL:topicsURL]; + + NSError *error = nil; + + NSDictionary *topicsDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error]; + + + self.topics = [NSMutableArray array]; + + // NSArray *topicsArray = [topicsDictionary objectForKey:@"title"]; + + for (NSDictionary *tDict in topicsDictionary) { + GameData *topic = [GameData topicWithTitle:[tDict objectForKey:@"title"]]; + topic.subject = [tDict objectForKey:@"subjects"]; + [self.topics addObject:topic]; + } + +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return self.topics.count; +} + + + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Title" forIndexPath:indexPath]; + + GameData *topicTitles = [self.topics objectAtIndex:indexPath.row]; + + cell.textLabel.text = topicTitles.title; + + return cell; +} + +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender +{ + if ([segue.identifier isEqualToString:@"showGame"]) { + NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; + + GameData *topicData = self.topics[indexPath.row]; + + GameViewController *viewController = segue.destinationViewController; + + viewController.data = topicData; + viewController.category = topicData.title; + } +} + +@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