Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added answer grid

  • Loading branch information...
commit 76359a19c4da51de81ccfbf42f1a524f9ee2d663 1 parent c157495
@debreuil authored
View
8 WordGrid.xcodeproj/project.pbxproj
@@ -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;
};
View
BIN  ...xcodeproj/project.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown
View
36 WordGrid.xcodeproj/xcuserdata/admin.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
@@ -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
13 WordGrid/AnswerGrid.h
@@ -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
172 WordGrid/AnswerGrid.m
@@ -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
26 WordGrid/GameVC.h
@@ -1,22 +1,25 @@
#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;
}
@@ -24,5 +27,6 @@
- (void) setOrientation;
- (void) testWordComplete;
- (IBAction)onDone:(id)sender;
+- (IBAction)onAnswerTileClick:(id)sender;
@end
View
42 WordGrid/GameVC.m
@@ -19,6 +19,12 @@ - (void)onDone:(id)sender
{
NSLog(@"done");
}
+- (IBAction)onAnswerTileClick:(id)sender
+{
+ Tile *t = (Tile *) sender;
+ [tileGrid insertTile:t At:t.gridIndex];
+ [tileGrid layoutGrid:YES];
+}
- (void) tileSelected:(NSNotification *)notification
{
@@ -27,11 +33,16 @@ - (void) tileSelected:(NSNotification *)notification
if(t.isSelectable)
{
- Tile *at = [answerTiles objectAtIndex:answerIndex];
+ Tile *at = [answerGrid getNextTile];//[answerTiles objectAtIndex:answerIndex];
+ CGRect orgFrame = at.frame;//CGRectInset(at.frame, 0, 0);
at.hidden = NO;
- at.frame = CGRectOffset(t.frame, tileGrid.frame.origin.x, tileGrid.frame.origin.y);
- [at setLetter:t.letter];
- [at setSelected:YES];
+ at.frame = CGRectMake( -answerGrid.frame.origin.x + tileGrid.frame.origin.x + t.frame.origin.x,
+ -answerGrid.frame.origin.y + tileGrid.frame.origin.y + t.frame.origin.y,
+ t.frame.size.width,
+ t.frame.size.height);
+ NSLog(@"org: %f %f", at.frame.origin.x, at.frame.origin.y);
+ //[at setLetter:t.letter];
+ [answerGrid setNextTileUsingTile:t];
[UIView
animateWithDuration:0.3
@@ -39,7 +50,7 @@ - (void) tileSelected:(NSNotification *)notification
options: UIViewAnimationCurveEaseOut
animations:^
{
- at.frame = [[answerFrames objectAtIndex:answerIndex] CGRectValue];
+ at.frame = orgFrame;//[[answerFrames objectAtIndex:answerIndex] CGRectValue];
}
completion:^(BOOL finished)
{
@@ -51,29 +62,29 @@ - (void) tileSelected:(NSNotification *)notification
];
[answerRefs addObject:t];
- answerIndex++;
- if(answerIndex < 4)
+
+ if([answerGrid atWordBoundry])
{
- [tileGrid setSelectableAroundIndex:lastSelectedTileIndex];
+ [tileGrid setAllIsSelectable:NO];
}
else
{
- [tileGrid setAllIsSelectable:NO];
+ [tileGrid setSelectableAroundIndex:lastSelectedTileIndex];
}
}
}
- (void) testWordComplete
{
- if(answerIndex > 3)
+ if([answerGrid atWordBoundry]) //answerIndex > 3)
{
- answerIndex = 0;
[tileGrid resetGrid];
+ /*
for (Tile *t in answerTiles)
{
t.hidden = YES;
}
-
+ */
[tileGrid removeTilesAndDrop:answerRefs];
[answerRefs removeAllObjects];
@@ -93,8 +104,8 @@ - (void)viewDidLoad
{
[super viewDidLoad];
- answerIndex = 0;
- answerRefs = [[NSMutableArray alloc] initWithCapacity:4];
+ answerRefs = [[NSMutableArray alloc] initWithCapacity:20];
+ /*
answerTiles = [[NSArray alloc] initWithObjects:letter0, letter1, letter2, letter3, nil];
answerFrames = [[NSArray alloc] initWithObjects:
[NSValue valueWithCGRect:letter0.frame],
@@ -106,6 +117,7 @@ - (void)viewDidLoad
{
t.hidden = YES;
}
+ */
[[NSNotificationCenter defaultCenter]
addObserver:self
@@ -140,7 +152,7 @@ - (void) setOrientation
{
bkgV.hidden = NO;
bkgH.hidden = YES;
- tileGrid.frame = CGRectMake(50, 220, tf.size.width, tf.size.height);
+ tileGrid.frame = CGRectMake(50, 180, tf.size.width, tf.size.height);
}
else if (io == UIInterfaceOrientationLandscapeLeft ||
io == UIInterfaceOrientationLandscapeRight)
View
238 WordGrid/GameView.xib
@@ -59,7 +59,7 @@
<string key="NSFrameSize">{1024, 768}</string>
<reference key="NSSuperview" ref="191373211"/>
<reference key="NSWindow"/>
- <reference key="NSNextKeyView" ref="265072754"/>
+ <reference key="NSNextKeyView"/>
<bool key="IBUIUserInteractionEnabled">NO</bool>
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
<object class="NSCustomResource" key="IBUIImage">
@@ -71,79 +71,17 @@
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">1316</int>
<object class="NSPSMatrix" key="NSFrameMatrix"/>
- <string key="NSFrame">{{47, 209}, {675, 525}}</string>
+ <string key="NSFrame">{{47, 180}, {675, 525}}</string>
<reference key="NSSuperview" ref="191373211"/>
<reference key="NSWindow"/>
- <reference key="NSNextKeyView" ref="1029336070"/>
+ <reference key="NSNextKeyView" ref="248888508"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">1</int>
- <bytes key="NSRGB">MCAwIDAgMC4yNgA</bytes>
+ <bytes key="NSRGB">MCAwIDAgMC4wOAA</bytes>
</object>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
</object>
- <object class="IBUIView" id="265072754">
- <reference key="NSNextResponder" ref="191373211"/>
- <int key="NSvFlags">1316</int>
- <object class="NSPSMatrix" key="NSFrameMatrix"/>
- <string key="NSFrame">{{337, 38}, {80, 80}}</string>
- <reference key="NSSuperview" ref="191373211"/>
- <reference key="NSWindow"/>
- <reference key="NSNextKeyView" ref="55290387"/>
- <object class="NSColor" key="IBUIBackgroundColor">
- <int key="NSColorSpace">3</int>
- <bytes key="NSWhite">MQA</bytes>
- <object class="NSColorSpace" key="NSCustomColorSpace" id="129539257">
- <int key="NSID">2</int>
- </object>
- </object>
- <string key="targetRuntimeIdentifier">IBIPadFramework</string>
- </object>
- <object class="IBUIView" id="55290387">
- <reference key="NSNextResponder" ref="191373211"/>
- <int key="NSvFlags">1316</int>
- <object class="NSPSMatrix" key="NSFrameMatrix"/>
- <string key="NSFrame">{{427, 38}, {80, 80}}</string>
- <reference key="NSSuperview" ref="191373211"/>
- <reference key="NSWindow"/>
- <reference key="NSNextKeyView" ref="532140706"/>
- <object class="NSColor" key="IBUIBackgroundColor">
- <int key="NSColorSpace">3</int>
- <bytes key="NSWhite">MQA</bytes>
- <reference key="NSCustomColorSpace" ref="129539257"/>
- </object>
- <string key="targetRuntimeIdentifier">IBIPadFramework</string>
- </object>
- <object class="IBUIView" id="532140706">
- <reference key="NSNextResponder" ref="191373211"/>
- <int key="NSvFlags">1316</int>
- <object class="NSPSMatrix" key="NSFrameMatrix"/>
- <string key="NSFrame">{{517, 38}, {80, 80}}</string>
- <reference key="NSSuperview" ref="191373211"/>
- <reference key="NSWindow"/>
- <reference key="NSNextKeyView" ref="16606554"/>
- <object class="NSColor" key="IBUIBackgroundColor">
- <int key="NSColorSpace">3</int>
- <bytes key="NSWhite">MQA</bytes>
- <reference key="NSCustomColorSpace" ref="129539257"/>
- </object>
- <string key="targetRuntimeIdentifier">IBIPadFramework</string>
- </object>
- <object class="IBUIView" id="16606554">
- <reference key="NSNextResponder" ref="191373211"/>
- <int key="NSvFlags">1316</int>
- <object class="NSPSMatrix" key="NSFrameMatrix"/>
- <string key="NSFrame">{{608, 38}, {80, 80}}</string>
- <reference key="NSSuperview" ref="191373211"/>
- <reference key="NSWindow"/>
- <reference key="NSNextKeyView" ref="1016526659"/>
- <object class="NSColor" key="IBUIBackgroundColor">
- <int key="NSColorSpace">3</int>
- <bytes key="NSWhite">MQA</bytes>
- <reference key="NSCustomColorSpace" ref="129539257"/>
- </object>
- <string key="targetRuntimeIdentifier">IBIPadFramework</string>
- </object>
<object class="IBUIButton" id="1029336070">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">-2147482332</int>
@@ -180,6 +118,20 @@
<int key="NSfFlags">16</int>
</object>
</object>
+ <object class="IBUIView" id="248888508">
+ <reference key="NSNextResponder" ref="191373211"/>
+ <int key="NSvFlags">292</int>
+ <string key="NSFrame">{{129, 726}, {608, 146}}</string>
+ <reference key="NSSuperview" ref="191373211"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="1029336070"/>
+ <string key="NSReuseIdentifierKey">_NS:212</string>
+ <object class="NSColor" key="IBUIBackgroundColor">
+ <int key="NSColorSpace">1</int>
+ <bytes key="NSRGB">MCAwIDAgMC4wNwA</bytes>
+ </object>
+ <string key="targetRuntimeIdentifier">IBIPadFramework</string>
+ </object>
</array>
<string key="NSFrame">{{0, 20}, {768, 1004}}</string>
<reference key="NSSuperview"/>
@@ -188,7 +140,9 @@
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MQA</bytes>
- <reference key="NSCustomColorSpace" ref="129539257"/>
+ <object class="NSColorSpace" key="NSCustomColorSpace">
+ <int key="NSID">2</int>
+ </object>
</object>
<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics">
<int key="IBUIStatusBarStyle">2</int>
@@ -232,43 +186,19 @@
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
- <string key="label">letter0</string>
- <reference key="source" ref="372490531"/>
- <reference key="destination" ref="265072754"/>
- </object>
- <int key="connectionID">15</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBCocoaTouchOutletConnection" key="connection">
- <string key="label">letter1</string>
- <reference key="source" ref="372490531"/>
- <reference key="destination" ref="55290387"/>
- </object>
- <int key="connectionID">16</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBCocoaTouchOutletConnection" key="connection">
- <string key="label">letter2</string>
- <reference key="source" ref="372490531"/>
- <reference key="destination" ref="532140706"/>
- </object>
- <int key="connectionID">17</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBCocoaTouchOutletConnection" key="connection">
- <string key="label">letter3</string>
+ <string key="label">tileGrid</string>
<reference key="source" ref="372490531"/>
- <reference key="destination" ref="16606554"/>
+ <reference key="destination" ref="1016526659"/>
</object>
- <int key="connectionID">18</int>
+ <int key="connectionID">19</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
- <string key="label">tileGrid</string>
+ <string key="label">answerGrid</string>
<reference key="source" ref="372490531"/>
- <reference key="destination" ref="1016526659"/>
+ <reference key="destination" ref="248888508"/>
</object>
- <int key="connectionID">19</int>
+ <int key="connectionID">21</int>
</object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
@@ -285,12 +215,9 @@
<array class="NSMutableArray" key="children">
<reference ref="158756890"/>
<reference ref="312021246"/>
- <reference ref="55290387"/>
- <reference ref="265072754"/>
- <reference ref="1016526659"/>
- <reference ref="532140706"/>
- <reference ref="16606554"/>
<reference ref="1029336070"/>
+ <reference ref="248888508"/>
+ <reference ref="1016526659"/>
</array>
<reference key="parent" ref="0"/>
</object>
@@ -324,32 +251,13 @@
<reference key="parent" ref="191373211"/>
</object>
<object class="IBObjectRecord">
- <int key="objectID">7</int>
- <reference key="object" ref="55290387"/>
- <reference key="parent" ref="191373211"/>
- <string key="objectName">Letter1</string>
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">8</int>
- <reference key="object" ref="16606554"/>
- <reference key="parent" ref="191373211"/>
- <string key="objectName">Letter3</string>
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">9</int>
- <reference key="object" ref="265072754"/>
- <reference key="parent" ref="191373211"/>
- <string key="objectName">Letter0</string>
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">10</int>
- <reference key="object" ref="532140706"/>
+ <int key="objectID">5</int>
+ <reference key="object" ref="1029336070"/>
<reference key="parent" ref="191373211"/>
- <string key="objectName">Letter2</string>
</object>
<object class="IBObjectRecord">
- <int key="objectID">5</int>
- <reference key="object" ref="1029336070"/>
+ <int key="objectID">20</int>
+ <reference key="object" ref="248888508"/>
<reference key="parent" ref="191373211"/>
</object>
</array>
@@ -360,10 +268,8 @@
<string key="-2.CustomClassName">UIResponder</string>
<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
- <string key="10.CustomClassName">Tile</string>
- <string key="10.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
- <reference key="10.IBUserGuides" ref="0"/>
- <boolean value="NO" key="10.showNotes"/>
+ <string key="20.CustomClassName">AnswerGrid</string>
+ <string key="20.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="3.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<reference key="3.IBUserGuides" ref="0"/>
<boolean value="NO" key="3.showNotes"/>
@@ -377,52 +283,52 @@
<string key="6.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<reference key="6.IBUserGuides" ref="0"/>
<boolean value="NO" key="6.showNotes"/>
- <string key="7.CustomClassName">Tile</string>
- <string key="7.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
- <reference key="7.IBUserGuides" ref="0"/>
- <boolean value="NO" key="7.showNotes"/>
- <string key="8.CustomClassName">Tile</string>
- <string key="8.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
- <reference key="8.IBUserGuides" ref="0"/>
- <boolean value="NO" key="8.showNotes"/>
- <string key="9.CustomClassName">Tile</string>
- <string key="9.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
- <reference key="9.IBUserGuides" ref="0"/>
- <boolean value="NO" key="9.showNotes"/>
</dictionary>
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
- <int key="maxID">19</int>
+ <int key="maxID">21</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
<object class="IBPartialClassDescription">
+ <string key="className">AnswerGrid</string>
+ <string key="superclassName">TileGrid</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">./Classes/AnswerGrid.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
<string key="className">GameVC</string>
<string key="superclassName">UIViewController</string>
- <object class="NSMutableDictionary" key="actions">
- <string key="NS.key.0">onDone:</string>
- <string key="NS.object.0">id</string>
- </object>
- <object class="NSMutableDictionary" key="actionInfosByName">
- <string key="NS.key.0">onDone:</string>
- <object class="IBActionInfo" key="NS.object.0">
+ <dictionary class="NSMutableDictionary" key="actions">
+ <string key="onAnswerTileClick:">id</string>
+ <string key="onDone:">id</string>
+ </dictionary>
+ <dictionary class="NSMutableDictionary" key="actionInfosByName">
+ <object class="IBActionInfo" key="onAnswerTileClick:">
+ <string key="name">onAnswerTileClick:</string>
+ <string key="candidateClassName">id</string>
+ </object>
+ <object class="IBActionInfo" key="onDone:">
<string key="name">onDone:</string>
<string key="candidateClassName">id</string>
</object>
- </object>
+ </dictionary>
<dictionary class="NSMutableDictionary" key="outlets">
+ <string key="answerGrid">AnswerGrid</string>
<string key="bkgH">UIView</string>
<string key="bkgV">UIView</string>
<string key="btDone">UIButton</string>
- <string key="letter0">Tile</string>
- <string key="letter1">Tile</string>
- <string key="letter2">Tile</string>
- <string key="letter3">Tile</string>
<string key="tileGrid">TileGrid</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
+ <object class="IBToOneOutletInfo" key="answerGrid">
+ <string key="name">answerGrid</string>
+ <string key="candidateClassName">AnswerGrid</string>
+ </object>
<object class="IBToOneOutletInfo" key="bkgH">
<string key="name">bkgH</string>
<string key="candidateClassName">UIView</string>
@@ -435,22 +341,6 @@
<string key="name">btDone</string>
<string key="candidateClassName">UIButton</string>
</object>
- <object class="IBToOneOutletInfo" key="letter0">
- <string key="name">letter0</string>
- <string key="candidateClassName">Tile</string>
- </object>
- <object class="IBToOneOutletInfo" key="letter1">
- <string key="name">letter1</string>
- <string key="candidateClassName">Tile</string>
- </object>
- <object class="IBToOneOutletInfo" key="letter2">
- <string key="name">letter2</string>
- <string key="candidateClassName">Tile</string>
- </object>
- <object class="IBToOneOutletInfo" key="letter3">
- <string key="name">letter3</string>
- <string key="candidateClassName">Tile</string>
- </object>
<object class="IBToOneOutletInfo" key="tileGrid">
<string key="name">tileGrid</string>
<string key="candidateClassName">TileGrid</string>
@@ -462,14 +352,6 @@
</object>
</object>
<object class="IBPartialClassDescription">
- <string key="className">Tile</string>
- <string key="superclassName">UIView</string>
- <object class="IBClassDescriptionSource" key="sourceIdentifier">
- <string key="majorKey">IBProjectSource</string>
- <string key="minorKey">./Classes/Tile.h</string>
- </object>
- </object>
- <object class="IBPartialClassDescription">
<string key="className">TileGrid</string>
<string key="superclassName">UIView</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
View
17 WordGrid/GridProtocol.h
@@ -0,0 +1,17 @@
+#import <UIKit/UIKit.h>
+
+@protocol GridProtocol
+
+- (void) setup;
+- (void) createGrid;
+- (void) resetGrid;
+- (void) layoutGrid:(Boolean) useAnimation;
+- (int) getTileIndexFromMousePoint:(CGPoint) point;
+- (Tile *) getTileFromPoint:(CGPoint) p;
+- (void) hoverTileAtPoint:(CGPoint) point;
+- (void) removeTilesAndDrop:(NSArray *) indexes;
+- (void) removeTile:(int) index;
+- (void) setAllIsSelectable:(Boolean) sel;
+
+
+@end
View
13 WordGrid/Tile.h
@@ -1,22 +1,35 @@
#import <UIKit/UIKit.h>
+extern NSString * const LETTERS;
+
@interface Tile : UIView
{
UIImage *image;
NSString *letter;
+ NSString *correctLetter;
Boolean isHovering;
Boolean selected;
Boolean isSelectable;
int gridIndex;
CGRect animatingFrom;
+ int resultIndex;
+ Boolean isResultTile;
+ CGRect scaleNormalRect;
+ CGRect scaleUpRect;
+ int originalIndex;
+
}
@property int gridIndex;
+@property int originalIndex;
@property (nonatomic, retain) NSString *letter;
+@property (nonatomic, retain) NSString *correctLetter;
@property (nonatomic) Boolean isHovering;
@property (nonatomic) Boolean selected;
@property (nonatomic) Boolean isSelectable;
@property (nonatomic) CGRect animatingFrom;
+@property int resultIndex;
+@property (nonatomic) Boolean isResultTile;
- (void)setup;
View
10 WordGrid/Tile.m
@@ -3,16 +3,20 @@
@implementation Tile
static NSArray *imageStates;
-static CGRect scaleNormalRect;
-static CGRect scaleUpRect;
static float hoverScale = 1.5;
@synthesize gridIndex;
+@synthesize originalIndex;
@synthesize letter;
+@synthesize correctLetter;
@synthesize isHovering;
@synthesize selected;
@synthesize isSelectable;
@synthesize animatingFrom;
+@synthesize resultIndex;
+@synthesize isResultTile;
+
+NSString * const LETTERS = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ (void) load
{
@@ -56,6 +60,8 @@ - (void) setup
image = [imageStates objectAtIndex:0];
letter = @"";
isSelectable = YES;
+ isResultTile = NO;
+ resultIndex = -1;
animatingFrom = CGRectNull;
View
17 WordGrid/TileGrid.h
@@ -1,6 +1,7 @@
#import <UIKit/UIKit.h>
+#import "GridProtocol.h"
-@interface TileGrid : UIView
+@interface TileGrid : UIView <GridProtocol>
{
int gw;
int gh;
@@ -14,18 +15,10 @@
Boolean hasGap;
}
-- (void) createGrid;
+- (void) setup;
- (void) createLetters;
-- (void) layoutGrid:(Boolean) useAnimation;
-- (void) resetGrid;
-- (int) getTileIndexFromMousePoint:(CGPoint) point;
-- (Tile *) getTileFromPoint:(CGPoint) p;
-- (void) hoverTileAtPoint:(CGPoint) point;
-- (void) removeTilesAndDrop:(NSArray *) indexes;
-- (void) removeTile:(int) index;
+- (void) insertTile:(Tile *)tile At:(int) index;
- (void) checkForVerticalGaps;
-
--(void) setAllIsSelectable:(Boolean) sel;
--(void) setSelectableAroundIndex:(int) index;
+- (void) setSelectableAroundIndex:(int) index;
@end
View
23 WordGrid/TileGrid.m
@@ -3,7 +3,7 @@
@implementation TileGrid
-static NSString *letters = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+//static NSString *letters = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
-(id)init
{
@@ -15,7 +15,7 @@ - (id)initWithCoder:(NSCoder *)aDecoder
self = [super initWithCoder:aDecoder];
if(self)
{
- [self createGrid];
+ [self setup];
}
return self;
}
@@ -24,18 +24,22 @@ - (id)initWithFrame:(CGRect)frame
self = [super initWithFrame:frame];
if (self)
{
- [self createGrid];
+ [self setup];
}
return self;
}
--(void) createGrid
-{
+- (void) setup
+{
gw = 9;
gh = 7;
margin = 4;
+ [self createGrid];
+}
+
+-(void) createGrid
+{
lastHoverTileIndex = -1;
-
Tile *tile;
tiles = [NSMutableArray arrayWithCapacity:gw * gh];
float tw = (self.bounds.size.width - margin * (gw - 2)) / gw;
@@ -116,11 +120,16 @@ - (void) createLetters
{
for (Tile* t in tiles)
{
- NSString *s = [letters substringWithRange:[letters rangeOfComposedCharacterSequenceAtIndex:arc4random()%[letters length]]];
+ NSString *s = [LETTERS substringWithRange:[LETTERS rangeOfComposedCharacterSequenceAtIndex:arc4random()%[LETTERS length]]];
[t setLetter:s];
}
}
+- (void) insertTile:(Tile *)tile At:(int) index
+{
+ [tiles replaceObjectAtIndex:index withObject:tile];
+}
+
- (int) getTileIndexFromMousePoint:(CGPoint) point
{
int tileIndex = -1;

0 comments on commit 76359a1

Please sign in to comment.
Something went wrong with that request. Please try again.