Permalink
Browse files

added answer grid

  • Loading branch information...
1 parent c157495 commit 76359a19c4da51de81ccfbf42f1a524f9ee2d663 @debreuil committed Dec 20, 2011
@@ -32,6 +32,7 @@
84827BDE149E67470098E408 /* GameVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 84827BDD149E67470098E408 /* GameVC.m */; };
84C9D8E2149E822700486E32 /* GameView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 84C9D8E1149E822700486E32 /* GameView.xib */; };
84C9D8E5149E8D6E00486E32 /* VTC_letterer_pro.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 84C9D8E4149E8D6E00486E32 /* VTC_letterer_pro.ttf */; };
+ 84D674DD149FBA6900782018 /* AnswerGrid.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D674DC149FBA6900782018 /* AnswerGrid.m */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -79,6 +80,9 @@
84827BDD149E67470098E408 /* GameVC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GameVC.m; sourceTree = "<group>"; };
84C9D8E1149E822700486E32 /* GameView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = GameView.xib; sourceTree = "<group>"; };
84C9D8E4149E8D6E00486E32 /* VTC_letterer_pro.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = VTC_letterer_pro.ttf; sourceTree = "<group>"; };
+ 84D674DB149FBA6900782018 /* AnswerGrid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AnswerGrid.h; sourceTree = "<group>"; };
+ 84D674DC149FBA6900782018 /* AnswerGrid.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AnswerGrid.m; sourceTree = "<group>"; };
+ 84D674DE149FBDF500782018 /* GridProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GridProtocol.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -199,10 +203,13 @@
84827BC4149E66C70098E408 /* Controls */ = {
isa = PBXGroup;
children = (
+ 84D674DE149FBDF500782018 /* GridProtocol.h */,
84827BC9149E67050098E408 /* Tile.h */,
84827BCA149E67050098E408 /* Tile.m */,
84827BCB149E67050098E408 /* TileGrid.h */,
84827BCC149E67050098E408 /* TileGrid.m */,
+ 84D674DB149FBA6900782018 /* AnswerGrid.h */,
+ 84D674DC149FBA6900782018 /* AnswerGrid.m */,
);
name = Controls;
sourceTree = "<group>";
@@ -338,6 +345,7 @@
84827BCD149E67050098E408 /* Tile.m in Sources */,
84827BCE149E67050098E408 /* TileGrid.m in Sources */,
84827BDE149E67470098E408 /* GameVC.m in Sources */,
+ 84D674DD149FBA6900782018 /* AnswerGrid.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -37,7 +37,7 @@
continueAfterRunningActions = "No"
isPathRelative = "1"
filePath = "WordGrid/TileGrid.m"
- timestampString = "345935158.46712"
+ timestampString = "346016984.549692"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "25"
@@ -51,13 +51,41 @@
continueAfterRunningActions = "No"
isPathRelative = "1"
filePath = "WordGrid/Tile.m"
- timestampString = "345935256.644764"
+ timestampString = "346056470.969154"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "149"
- endingLineNumber = "149"
+ startingLineNumber = "150"
+ endingLineNumber = "150"
landmarkName = "-drawRect:"
landmarkType = "5">
</FileBreakpoint>
+ <FileBreakpoint
+ shouldBeEnabled = "No"
+ ignoreCount = "0"
+ continueAfterRunningActions = "No"
+ isPathRelative = "1"
+ filePath = "WordGrid/TileGrid.m"
+ timestampString = "346016984.549692"
+ startingColumnNumber = "9223372036854775807"
+ endingColumnNumber = "9223372036854775807"
+ startingLineNumber = "34"
+ endingLineNumber = "34"
+ landmarkName = "-setup"
+ landmarkType = "5">
+ </FileBreakpoint>
+ <FileBreakpoint
+ shouldBeEnabled = "No"
+ ignoreCount = "0"
+ continueAfterRunningActions = "No"
+ isPathRelative = "1"
+ filePath = "WordGrid/GameVC.m"
+ timestampString = "346055919.877996"
+ startingColumnNumber = "9223372036854775807"
+ endingColumnNumber = "9223372036854775807"
+ startingLineNumber = "45"
+ endingLineNumber = "45"
+ landmarkName = "-tileSelected:"
+ landmarkType = "5">
+ </FileBreakpoint>
</FileBreakpoints>
</Bucket>
View
@@ -0,0 +1,13 @@
+#import <UIKit/UIKit.h>
+#import "TileGrid.h"
+
+@interface AnswerGrid : TileGrid
+{
+ NSString *answer;
+ NSArray *answerWords;
+}
+
+- (Tile *) getNextTile;
+- (void) setNextTileUsingTile:(Tile *)srcTile;
+- (BOOL) atWordBoundry;
+@end
View
@@ -0,0 +1,172 @@
+#import "Tile.h"
+#import "AnswerGrid.h"
+
+@implementation AnswerGrid
+
+int answerLength;
+int answerIndex;
+NSMutableArray *wordBoundries;
+
+- (void) setup
+{
+ answer = @"THE BIGGER THEY COME THE HARDER THEY FALL";
+ answerWords = [answer componentsSeparatedByString: @" "];
+ gw = 15;
+ gh = 3;
+ margin = 2;
+ answerIndex = 0;
+ [self createGrid];
+}
+
+- (void) createLetters
+{
+ wordBoundries = [[NSMutableArray alloc] init];
+ int wordIndex = 0;
+ int charIndex = 0;
+ NSString *curWord = [answerWords objectAtIndex:wordIndex];
+ NSString *curLetter;
+ BOOL complete = NO;
+ answerLength = 0;
+
+ for (Tile* t in tiles)
+ {
+ [t setIsSelectable:NO];
+
+ if(complete)
+ {
+ [t setHidden:YES];
+ }
+ else
+ {
+ [t setHidden:NO];
+
+ answerLength++;
+ curLetter = [curWord substringWithRange:[curWord rangeOfComposedCharacterSequenceAtIndex:charIndex]];
+ //[t setLetter:curLetter];
+ [t setCorrectLetter:curLetter];
+ [t setLetter:@""];
+
+ charIndex++;
+
+ if(charIndex >= [curWord length])
+ {
+ [wordBoundries addObject:[NSNumber numberWithInt:answerLength]];
+ wordIndex++;
+ charIndex = 0;
+ if(wordIndex < [answerWords count])
+ {
+ curWord = [answerWords objectAtIndex:wordIndex];
+ }
+ else
+ {
+ complete = YES;
+ }
+ }
+ }
+ }
+}
+
+- (void) layoutGrid:(Boolean)useAnimation
+{
+ Tile *tile = [tiles objectAtIndex:0];
+
+ float spcH = tile.bounds.size.width + margin;
+ float spcV = tile.bounds.size.height + margin;
+
+ float l = 0;
+ float t = 0;
+
+ CGRect fr = CGRectMake(l, t, tile.bounds.size.width, tile.bounds.size.height);
+
+ int wordIndex = 0;
+ int charIndex = 0;
+ NSString *curWord = [answerWords objectAtIndex:wordIndex];
+ BOOL complete = NO;
+
+ for (tile in tiles)
+ {
+ if(!complete)
+ {
+ tile.frame = fr;
+ fr.origin.x += spcH;
+ charIndex++;
+
+ if(charIndex >= [curWord length])
+ {
+ wordIndex++;
+ charIndex = 0;
+ fr.origin.x += spcH / 2;
+
+ if(wordIndex < [answerWords count])
+ {
+ curWord = [answerWords objectAtIndex:wordIndex];
+ if(fr.origin.x + [curWord length] * spcH > gw * spcH)
+ {
+ fr.origin.x = l;
+ fr.origin.y += spcV;
+ }
+ }
+ else
+ {
+ complete = YES;
+ }
+ }
+ }
+ }
+}
+
+- (Tile *) getNextTile
+{
+ Tile * result = nil;
+ if(answerIndex < answerLength)
+ {
+ result = [tiles objectAtIndex:answerIndex];
+ }
+ return result;
+}
+
+- (void) setNextTileUsingTile:(Tile *)srcTile
+{
+ if(answerIndex < answerLength)
+ {
+ Tile *newTile = [tiles objectAtIndex:answerIndex];
+ [newTile setLetter:[srcTile letter]];
+ [newTile setOriginalIndex:srcTile.gridIndex];
+ //[newTile setIsSelectable:YES];
+ [newTile setSelected:YES];
+
+ answerIndex++;
+ }
+}
+
+- (Tile *) removeCurrentTile
+{
+ Tile *result = nil;
+ if(answerIndex > 0)
+ {
+ result = [tiles objectAtIndex:answerIndex];
+ [result setLetter:@""];
+ [result setIsSelectable:NO];
+ answerIndex--;
+ [[tiles objectAtIndex:answerIndex] setIsSelectable:YES];
+ }
+ return result;
+}
+
+- (BOOL) atWordBoundry
+{
+ BOOL result = false;
+
+ for (NSNumber *n in wordBoundries)
+ {
+
+ if ([n integerValue] == answerIndex)
+ {
+ result = YES;
+ break;
+ }
+ }
+ return result;
+}
+
+@end
View
@@ -1,28 +1,32 @@
#import <UIKit/UIKit.h>
#import "Tile.h"
#import "TileGrid.h"
+#import "AnswerGrid.h"
@interface GameVC : UIViewController
{
- UIButton IBOutlet *btDone;
- UIView IBOutlet *bkgH;
- UIView IBOutlet *bkgV;
- TileGrid IBOutlet *tileGrid;
- Tile IBOutlet *letter0;
- Tile IBOutlet *letter1;
- Tile IBOutlet *letter2;
- Tile IBOutlet *letter3;
+ IBOutlet UIButton *btDone;
+ IBOutlet UIView *bkgH;
+ IBOutlet UIView *bkgV;
+ IBOutlet AnswerGrid *answerGrid;
+ IBOutlet TileGrid *tileGrid;
+
+ //Tile IBOutlet *letter0;
+ //Tile IBOutlet *letter1;
+ //Tile IBOutlet *letter2;
+ //Tile IBOutlet *letter3;
+ //NSArray* answerTiles;
+ //NSArray* answerFrames;
- NSArray* answerTiles;
- NSArray* answerFrames;
NSMutableArray* answerRefs;
- int answerIndex;
+ //int answerIndex;
int lastSelectedTileIndex;
}
- (void) tileSelected:(Tile *) t;
- (void) setOrientation;
- (void) testWordComplete;
- (IBAction)onDone:(id)sender;
+- (IBAction)onAnswerTileClick:(id)sender;
@end
Oops, something went wrong.

0 comments on commit 76359a1

Please sign in to comment.