Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implemented view to update markers upon column click

  • Loading branch information...
commit 9f137e507b1b065df123582ea738838ae92f21a7 1 parent 425c2df
Jamie Ly authored
BIN  Assets/a.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  Assets/b.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 ConnectFour.xcodeproj/project.pbxproj
View
@@ -32,6 +32,8 @@
6D181E5F15F53A8C005050B5 /* GamePlayTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D181E5E15F53A8C005050B5 /* GamePlayTests.m */; };
6D181E6315F53BA5005050B5 /* Move.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D181E6215F53BA5005050B5 /* Move.m */; };
6D181E6615F53E18005050B5 /* NSArray+Repeat.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D181E6515F53E18005050B5 /* NSArray+Repeat.m */; };
+ 6D49D9C215F5895F004359C4 /* a.png in Resources */ = {isa = PBXBuildFile; fileRef = 6D49D9C015F5895F004359C4 /* a.png */; };
+ 6D49D9C315F5895F004359C4 /* b.png in Resources */ = {isa = PBXBuildFile; fileRef = 6D49D9C115F5895F004359C4 /* b.png */; };
6D756FFB15F535D90040AD61 /* BoardTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D756FFA15F535D90040AD61 /* BoardTests.m */; };
6D756FFE15F536470040AD61 /* GameTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D756FFD15F536470040AD61 /* GameTests.m */; };
6D75700115F5368B0040AD61 /* Game.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D75700015F5368B0040AD61 /* Game.m */; };
@@ -91,6 +93,8 @@
6D181E6215F53BA5005050B5 /* Move.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Move.m; path = Models/Move.m; sourceTree = "<group>"; };
6D181E6415F53E18005050B5 /* NSArray+Repeat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSArray+Repeat.h"; path = "Categories/NSArray+Repeat.h"; sourceTree = "<group>"; };
6D181E6515F53E18005050B5 /* NSArray+Repeat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSArray+Repeat.m"; path = "Categories/NSArray+Repeat.m"; sourceTree = "<group>"; };
+ 6D49D9C015F5895F004359C4 /* a.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = a.png; sourceTree = "<group>"; };
+ 6D49D9C115F5895F004359C4 /* b.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = b.png; sourceTree = "<group>"; };
6D756FF915F535D90040AD61 /* BoardTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BoardTests.h; sourceTree = "<group>"; };
6D756FFA15F535D90040AD61 /* BoardTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BoardTests.m; sourceTree = "<group>"; };
6D756FFC15F536470040AD61 /* GameTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GameTests.h; sourceTree = "<group>"; };
@@ -137,6 +141,8 @@
6D0299F015F57230006FD886 /* Assets */ = {
isa = PBXGroup;
children = (
+ 6D49D9C015F5895F004359C4 /* a.png */,
+ 6D49D9C115F5895F004359C4 /* b.png */,
6D0299F115F57230006FD886 /* empty.png */,
);
path = Assets;
@@ -352,6 +358,8 @@
6D0C950E15F451990057E8FB /* MainStoryboard_iPhone.storyboard in Resources */,
6D0C951115F451990057E8FB /* MainStoryboard_iPad.storyboard in Resources */,
6D0299F215F57230006FD886 /* empty.png in Resources */,
+ 6D49D9C215F5895F004359C4 /* a.png in Resources */,
+ 6D49D9C315F5895F004359C4 /* b.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
17 ConnectFour/Controllers/BoardViewController.m
View
@@ -8,6 +8,7 @@
#import "BoardViewController.h"
#import "JLSize.h"
+#import "Move.h"
#import "Game.h"
#import "Board.h"
#import "JLIndex.h"
@@ -48,10 +49,18 @@ - (void) setupGame {
}
- (void) boardView:(BoardView *)_boardView didSelectColumn:(NSUInteger)column {
- // do something
- NSString *message = [NSString stringWithFormat:@"Column %d selected", column];
- [[[UIAlertView alloc] initWithTitle:@"Alert" message:message
- delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
+ Move *move = [Move moveWithColumn: column];
+ if([game move: move]) {
+ [boardView updateIndex: game.lastIndex];
+ }
+ else {
+ [[[UIAlertView alloc] initWithTitle:@"Alert"
+ message: @"That column is full."
+ delegate:nil
+ cancelButtonTitle:@"OK"
+ otherButtonTitles:nil]
+ show];
+ }
}
@end
2  ConnectFour/Models/Game.h
View
@@ -17,11 +17,13 @@
Board *board;
NSArray *directions;
Marker *activeMarker;
+ JLIndex *lastIndex;
}
@property (nonatomic, strong) Board *board;
@property (nonatomic, strong) NSArray *directions;
@property (nonatomic, strong) Marker *activeMarker;
+@property (nonatomic, strong) JLIndex *lastIndex;
- (BOOL) move: (Move*) _move;
- (Marker*) markerAtIndex: (JLIndex*) index;
5 ConnectFour/Models/Game.m
View
@@ -26,6 +26,7 @@ @implementation Game
@synthesize board;
@synthesize directions;
@synthesize activeMarker;
+@synthesize lastIndex;
- (Game*) init {
self = [super init];
@@ -54,8 +55,8 @@ - (BOOL) move: (Move*) _move {
return NO; // @todo, throw exception?
}
- JLIndex *moveIndex = [JLIndex indexWithRow:r andColumn:_move.column];
- [board moveWithMarker: activeMarker atIndex: moveIndex];
+ lastIndex = [JLIndex indexWithRow:r andColumn:_move.column];
+ [board moveWithMarker: activeMarker atIndex: lastIndex];
[self toggleActiveMarker];
return YES;
4 ConnectFour/Views/BoardView.h
View
@@ -9,6 +9,8 @@
#import <UIKit/UIKit.h>
@class Board;
+@class JLIndex;
+
@protocol BoardViewDelegate;
@interface BoardView : UIView {
@@ -28,7 +30,7 @@
@property (nonatomic, strong) id<BoardViewDelegate> delegate;
- (id) initWithFrame: (CGRect) frame andBoard: (Board*) _board;
-
+- (void) updateIndex: (JLIndex*) index;
@end
@protocol BoardViewDelegate <NSObject>
21 ConnectFour/Views/BoardView.m
View
@@ -8,6 +8,7 @@
#import "BoardView.h"
#import "Board.h"
+#import "Marker.h"
#import "JLSize.h"
#import "JLIndex.h"
#import "IndexView.h"
@@ -84,4 +85,24 @@ - (void)handleTap:(UITapGestureRecognizer *)recognizer {
[delegate boardView: self didSelectColumn: indexView.index.column];
}
}
+
+- (void) updateIndex: (JLIndex*) index {
+ NSUInteger i = [board indexToInt: index];
+
+ Marker *marker = [board markerAtIndex: index];
+ UIImage *newImage = nil;
+ if(marker == Marker.A) {
+ newImage = imageA;
+ }
+ else if(marker == Marker.B) {
+ newImage = imageB;
+ }
+ else {
+ newImage = imageEmpty; // this shouldn't happen
+ }
+
+ IndexView *iv = [positionViews objectAtIndex: i];
+ iv.image = newImage;
+}
+
@end
Please sign in to comment.
Something went wrong with that request. Please try again.