Skip to content

Commit

Permalink
Everything working version.
Browse files Browse the repository at this point in the history
  • Loading branch information
Danqing committed Mar 26, 2014
1 parent c4e3f26 commit bf38ed8
Show file tree
Hide file tree
Showing 17 changed files with 678 additions and 65 deletions.
12 changes: 12 additions & 0 deletions m2048.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
24C4516418DABABE0001FCFD /* M2GlobalState.m in Sources */ = {isa = PBXBuildFile; fileRef = 24C4516218DABABE0001FCFD /* M2GlobalState.m */; };
24C4516818DD64A90001FCFD /* M2GridView.m in Sources */ = {isa = PBXBuildFile; fileRef = 24C4516718DD64A90001FCFD /* M2GridView.m */; };
24C4517018DFF10B0001FCFD /* M2ScoreView.m in Sources */ = {isa = PBXBuildFile; fileRef = 24C4516F18DFF10B0001FCFD /* M2ScoreView.m */; };
24C4517318E140AE0001FCFD /* M2SettingsDetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 24C4517218E140AE0001FCFD /* M2SettingsDetailViewController.m */; };
24C4518118E265390001FCFD /* M2Overlay.m in Sources */ = {isa = PBXBuildFile; fileRef = 24C4518018E265390001FCFD /* M2Overlay.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -86,6 +88,10 @@
24C4516718DD64A90001FCFD /* M2GridView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = M2GridView.m; sourceTree = "<group>"; };
24C4516E18DFF10B0001FCFD /* M2ScoreView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = M2ScoreView.h; sourceTree = "<group>"; };
24C4516F18DFF10B0001FCFD /* M2ScoreView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = M2ScoreView.m; sourceTree = "<group>"; };
24C4517118E140AE0001FCFD /* M2SettingsDetailViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = M2SettingsDetailViewController.h; sourceTree = "<group>"; };
24C4517218E140AE0001FCFD /* M2SettingsDetailViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = M2SettingsDetailViewController.m; sourceTree = "<group>"; };
24C4517F18E265390001FCFD /* M2Overlay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = M2Overlay.h; sourceTree = "<group>"; };
24C4518018E265390001FCFD /* M2Overlay.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = M2Overlay.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -231,6 +237,8 @@
2443DCA518D66CCC00C920C1 /* M2ViewController.m */,
2443DC9E18D6647000C920C1 /* M2SettingsViewController.h */,
2443DC9F18D6647000C920C1 /* M2SettingsViewController.m */,
24C4517118E140AE0001FCFD /* M2SettingsDetailViewController.h */,
24C4517218E140AE0001FCFD /* M2SettingsDetailViewController.m */,
);
path = Controller;
sourceTree = "<group>";
Expand All @@ -252,6 +260,8 @@
24C4516718DD64A90001FCFD /* M2GridView.m */,
24C4516E18DFF10B0001FCFD /* M2ScoreView.h */,
24C4516F18DFF10B0001FCFD /* M2ScoreView.m */,
24C4517F18E265390001FCFD /* M2Overlay.h */,
24C4518018E265390001FCFD /* M2Overlay.m */,
);
path = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -360,10 +370,12 @@
24C4516818DD64A90001FCFD /* M2GridView.m in Sources */,
2443DC9A18D663FC00C920C1 /* M2Scene.m in Sources */,
24C4515E18D6DC740001FCFD /* M2Grid.m in Sources */,
24C4518118E265390001FCFD /* M2Overlay.m in Sources */,
2443DCAF18D6C18400C920C1 /* M2Tile.m in Sources */,
2443DCA018D6647000C920C1 /* M2SettingsViewController.m in Sources */,
24C4517018DFF10B0001FCFD /* M2ScoreView.m in Sources */,
2443DCA318D6649500C920C1 /* M2Theme.m in Sources */,
24C4517318E140AE0001FCFD /* M2SettingsDetailViewController.m in Sources */,
24C4516418DABABE0001FCFD /* M2GlobalState.m in Sources */,
2443DC6818D662CA00C920C1 /* M2AppDelegate.m in Sources */,
2443DC9B18D663FC00C920C1 /* M2GameManager.m in Sources */,
Expand Down
243 changes: 231 additions & 12 deletions m2048/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions m2048/Controller/M2SettingsDetailViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// M2SettingsDetailViewController.h
// m2048
//
// Created by Danqing on 3/24/14.
// Copyright (c) 2014 Danqing. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface M2SettingsDetailViewController : UITableViewController

@property (nonatomic, strong) NSArray *options;
@property (nonatomic, strong) NSString *footer;

@end
73 changes: 73 additions & 0 deletions m2048/Controller/M2SettingsDetailViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// M2SettingsDetailViewController.m
// m2048
//
// Created by Danqing on 3/24/14.
// Copyright (c) 2014 Danqing. All rights reserved.
//

#import "M2SettingsDetailViewController.h"

@interface M2SettingsDetailViewController ()

@end

@implementation M2SettingsDetailViewController

- (id)initWithStyle:(UITableViewStyle)style
{
if (self = [super initWithStyle:style]) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.tintColor = [GSTATE scoreBoardColor];
}

- (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.options.count;
}

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
return self.footer;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Settings Detail Cell"];

cell.textLabel.text = [self.options objectAtIndex:indexPath.row];
cell.accessoryType = ([Settings integerForKey:self.title] == indexPath.row) ?
UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
cell.tintColor = [GSTATE scoreBoardColor];

return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[Settings setInteger:indexPath.row forKey:self.title];
[self.tableView reloadData];
GSTATE.needRefresh = YES;
}

@end
2 changes: 1 addition & 1 deletion m2048/Controller/M2SettingsViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

#import <UIKit/UIKit.h>

@interface M2SettingsViewController : UIViewController
@interface M2SettingsViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>

@end
125 changes: 108 additions & 17 deletions m2048/Controller/M2SettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,134 @@
//

#import "M2SettingsViewController.h"
#import "M2SettingsDetailViewController.h"

@interface M2SettingsViewController ()

@end

@implementation M2SettingsViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
@implementation M2SettingsViewController {
IBOutlet UITableView *_tableView;
NSArray *_options;
NSArray *_optionSelections;
NSArray *_optionsNotes;
}


# pragma mark - Set up

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
[self commonInit];
}
return self;
}


- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
if (self = [super initWithCoder:aDecoder]) {
[self commonInit];
}
return self;
}


- (void)commonInit
{
_options = @[@"Game Type", @"Board Size", @"Theme"];

_optionSelections = @[@[@"Powers of 2", @"Powers of 3", @"Fibonacci"],
@[@"3 x 3", @"4 x 4", @"5 x 5"],
@[@"Default", @"Cool", @"Yale Blue"]];

_optionsNotes = @[@"For Fibonacci games, a tile can be joined with a tile that is one level above or below it, but not to one equal to it.",
@"The smaller the board is, the harder! For 5 x 5 board, two tiles will be added every round.",
@"Choose your favorite appearance and get your own feeling of 2048!"];
}


- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[super viewDidLoad];
self.navigationController.navigationBar.tintColor = [GSTATE scoreBoardColor];
// Do any additional setup after loading the view.
}

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[_tableView reloadData];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

/*
#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.
if ([segue.identifier isEqualToString:@"Settings Detail Segue"]) {
M2SettingsDetailViewController *sdvc = segue.destinationViewController;

NSInteger index = [_tableView indexPathForSelectedRow].row;
sdvc.title = [_options objectAtIndex:index];
sdvc.options = [_optionSelections objectAtIndex:index];
sdvc.footer = [_optionsNotes objectAtIndex:index];
}
}

# pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return section ? 1 : _options.count;
}


- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
if (section) return @"";
return @"Please note: Changing the settings above would restart the game.";
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Settings Cell"];

if (indexPath.section) {
cell.textLabel.text = @"About 2048";
cell.detailTextLabel.text = @"";
} else {
cell.textLabel.text = [_options objectAtIndex:indexPath.row];

NSInteger index = [Settings integerForKey:[_options objectAtIndex:indexPath.row]];
cell.detailTextLabel.text = [[_optionSelections objectAtIndex:indexPath.row] objectAtIndex:index];
cell.detailTextLabel.textColor = [GSTATE scoreBoardColor];
}

return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section) {
[self performSegueWithIdentifier:@"About Segue" sender:nil];
} else {
[self performSegueWithIdentifier:@"Settings Detail Segue" sender:nil];
}
}
*/

@end
4 changes: 4 additions & 0 deletions m2048/Controller/M2ViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@

@interface M2ViewController : UIViewController

- (void)updateScore:(NSInteger)score;

- (void)endGame:(BOOL)won;

@end
Loading

0 comments on commit bf38ed8

Please sign in to comment.