Skip to content

Commit

Permalink
added answer grid
Browse files Browse the repository at this point in the history
  • Loading branch information
debreuil committed Dec 20, 2011
1 parent c157495 commit 76359a1
Show file tree
Hide file tree
Showing 13 changed files with 386 additions and 229 deletions.
8 changes: 8 additions & 0 deletions WordGrid.xcodeproj/project.pbxproj
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
84827BDE149E67470098E408 /* GameVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 84827BDD149E67470098E408 /* GameVC.m */; }; 84827BDE149E67470098E408 /* GameVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 84827BDD149E67470098E408 /* GameVC.m */; };
84C9D8E2149E822700486E32 /* GameView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 84C9D8E1149E822700486E32 /* GameView.xib */; }; 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 */; }; 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 */ /* End PBXBuildFile section */


/* Begin PBXContainerItemProxy section */ /* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -79,6 +80,9 @@
84827BDD149E67470098E408 /* GameVC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GameVC.m; sourceTree = "<group>"; }; 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>"; }; 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>"; }; 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 */ /* End PBXFileReference section */


/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -199,10 +203,13 @@
84827BC4149E66C70098E408 /* Controls */ = { 84827BC4149E66C70098E408 /* Controls */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
84D674DE149FBDF500782018 /* GridProtocol.h */,
84827BC9149E67050098E408 /* Tile.h */, 84827BC9149E67050098E408 /* Tile.h */,
84827BCA149E67050098E408 /* Tile.m */, 84827BCA149E67050098E408 /* Tile.m */,
84827BCB149E67050098E408 /* TileGrid.h */, 84827BCB149E67050098E408 /* TileGrid.h */,
84827BCC149E67050098E408 /* TileGrid.m */, 84827BCC149E67050098E408 /* TileGrid.m */,
84D674DB149FBA6900782018 /* AnswerGrid.h */,
84D674DC149FBA6900782018 /* AnswerGrid.m */,
); );
name = Controls; name = Controls;
sourceTree = "<group>"; sourceTree = "<group>";
Expand Down Expand Up @@ -338,6 +345,7 @@
84827BCD149E67050098E408 /* Tile.m in Sources */, 84827BCD149E67050098E408 /* Tile.m in Sources */,
84827BCE149E67050098E408 /* TileGrid.m in Sources */, 84827BCE149E67050098E408 /* TileGrid.m in Sources */,
84827BDE149E67470098E408 /* GameVC.m in Sources */, 84827BDE149E67470098E408 /* GameVC.m in Sources */,
84D674DD149FBA6900782018 /* AnswerGrid.m in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
Expand Down
Binary file not shown.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
continueAfterRunningActions = "No" continueAfterRunningActions = "No"
isPathRelative = "1" isPathRelative = "1"
filePath = "WordGrid/TileGrid.m" filePath = "WordGrid/TileGrid.m"
timestampString = "345935158.46712" timestampString = "346016984.549692"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "25" startingLineNumber = "25"
Expand All @@ -51,13 +51,41 @@
continueAfterRunningActions = "No" continueAfterRunningActions = "No"
isPathRelative = "1" isPathRelative = "1"
filePath = "WordGrid/Tile.m" filePath = "WordGrid/Tile.m"
timestampString = "345935256.644764" timestampString = "346056470.969154"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "149" startingLineNumber = "150"
endingLineNumber = "149" endingLineNumber = "150"
landmarkName = "-drawRect:" landmarkName = "-drawRect:"
landmarkType = "5"> landmarkType = "5">
</FileBreakpoint> </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> </FileBreakpoints>
</Bucket> </Bucket>
13 changes: 13 additions & 0 deletions WordGrid/AnswerGrid.h
Original file line number Original file line Diff line number Diff line change
@@ -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
172 changes: 172 additions & 0 deletions WordGrid/AnswerGrid.m
Original file line number Original file line Diff line number Diff line change
@@ -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
26 changes: 15 additions & 11 deletions WordGrid/GameVC.h
Original file line number Original file line Diff line number Diff line change
@@ -1,28 +1,32 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "Tile.h" #import "Tile.h"
#import "TileGrid.h" #import "TileGrid.h"
#import "AnswerGrid.h"


@interface GameVC : UIViewController @interface GameVC : UIViewController
{ {
UIButton IBOutlet *btDone; IBOutlet UIButton *btDone;
UIView IBOutlet *bkgH; IBOutlet UIView *bkgH;
UIView IBOutlet *bkgV; IBOutlet UIView *bkgV;
TileGrid IBOutlet *tileGrid; IBOutlet AnswerGrid *answerGrid;
Tile IBOutlet *letter0; IBOutlet TileGrid *tileGrid;
Tile IBOutlet *letter1;
Tile IBOutlet *letter2; //Tile IBOutlet *letter0;
Tile IBOutlet *letter3; //Tile IBOutlet *letter1;
//Tile IBOutlet *letter2;
//Tile IBOutlet *letter3;
//NSArray* answerTiles;
//NSArray* answerFrames;


NSArray* answerTiles;
NSArray* answerFrames;
NSMutableArray* answerRefs; NSMutableArray* answerRefs;
int answerIndex; //int answerIndex;
int lastSelectedTileIndex; int lastSelectedTileIndex;
} }


- (void) tileSelected:(Tile *) t; - (void) tileSelected:(Tile *) t;
- (void) setOrientation; - (void) setOrientation;
- (void) testWordComplete; - (void) testWordComplete;
- (IBAction)onDone:(id)sender; - (IBAction)onDone:(id)sender;
- (IBAction)onAnswerTileClick:(id)sender;


@end @end
Loading

0 comments on commit 76359a1

Please sign in to comment.