From 0ba8b774566c68084c701976782fc1cc9e906eb9 Mon Sep 17 00:00:00 2001 From: Mesfin Date: Sat, 27 Jun 2015 16:37:38 -0400 Subject: [PATCH 01/23] Added implementation of some methods --- TodoList/TodoList/main.m | 122 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 120 insertions(+), 2 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 187be40..42b8d3f 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -8,10 +8,128 @@ #import +@class ListManager; +@class ListItem; +@class List; + +@interface ListManager : NSObject + +-(void) printCommands; +-(void) run; +-(void) addList; +-(void) deleteList:(int)index; +-(void) printLists; + + +@end + +@implementation ListManager{ + NSMutableArray *_toDoLists; +} + + + +@end + + + + + +@interface ListItem : NSObject + +-(instancetype)initWithDefaultAndName:(NSString *)name; + +@property NSInteger priority; +@property NSString *itemName; +@property BOOL completed; + +-(void)changeBool; + +@end + +@implementation ListItem + +- (instancetype) initWithDefaultAndName:(NSString *)name{ + + if(self = [super init]){ + self.priority = 1; + self.completed = NO; + self.itemName = name; + + return self; + } + return nil; +} + +-(void)changeBool{ + self.completed = YES; +} + +@end + +@interface List : NSObject + +@property NSString *listName; + + +-(void) addItem:(ListItem *)item; +-(void) printItems; +-(void) deleteItem:(int)index; +-(void) editItem:(int)index; +-(void) markCompleted:(int)index; +-(void) setPriority:(int)value; +-(void) active; +-(void) inActive; +-(void) run; +-(void) printCommandsActive:(BOOL)active inActive:(BOOL)inActive; + +@end + +@implementation List{ + NSMutableArray *_items; +} +-(void) addItem:(ListItem *)item{ + + if(_items == nil){ + _items = [[NSMutableArray alloc]init]; + } + char temp[256]; + printf("\n Add description: "); + scanf("%255[^\n]%*c",temp); + fpurge(stdin); + NSString *name = [NSString stringWithCString:temp encoding:NSASCIIStringEncoding]; + ListItem *li = [[ListItem alloc] initWithDefaultAndName:name]; + + [_items addObject:li]; +} + +-(void) deleteItem:(int)index{ + NSInteger arraySize = [_items count]; + if(index < 1 || index > arraySize){ + NSString *c = [NSString stringWithFormat:@"%@",index<1? @"Must be greater than or equal to 1":@"out of bounds"]; + printf("%s",[c UTF8String]); + return; + } + [_items removeObjectAtIndex:index]; + +} + +-(void) markCompleted:(int)index{ + NSInteger arraySize = [_items count]; + if(index < 1 || index > arraySize){ + NSString *c = [NSString stringWithFormat:@"%@",index<1? @"Must be greater than or equal to 1":@"out of bounds"]; + printf("%s",[c UTF8String]); + return; + } + + [[_items objectAtIndex:index-1] changeBool]; +} + +@end + int main(int argc, const char * argv[]) { @autoreleasepool { - // insert code here... - NSLog(@"Hello, World!"); + } return 0; } From 0a4291ff74656f07fcececc7af7d868af3eedb2f Mon Sep 17 00:00:00 2001 From: Mesfin Date: Sat, 27 Jun 2015 16:54:27 -0400 Subject: [PATCH 02/23] Exctract classes --- TodoList/TodoList.xcodeproj/project.pbxproj | 19 ++++ TodoList/TodoList/List.h | 30 +++++ TodoList/TodoList/List.m | 53 +++++++++ TodoList/TodoList/ListItem.h | 19 ++++ TodoList/TodoList/ListItem.m | 29 +++++ TodoList/TodoList/ListManager.h | 20 ++++ TodoList/TodoList/ListManager.m | 18 +++ TodoList/TodoList/main.m | 119 -------------------- 8 files changed, 188 insertions(+), 119 deletions(-) create mode 100644 TodoList/TodoList/List.h create mode 100644 TodoList/TodoList/List.m create mode 100644 TodoList/TodoList/ListItem.h create mode 100644 TodoList/TodoList/ListItem.m create mode 100644 TodoList/TodoList/ListManager.h create mode 100644 TodoList/TodoList/ListManager.m diff --git a/TodoList/TodoList.xcodeproj/project.pbxproj b/TodoList/TodoList.xcodeproj/project.pbxproj index 17baea5..fc8f531 100644 --- a/TodoList/TodoList.xcodeproj/project.pbxproj +++ b/TodoList/TodoList.xcodeproj/project.pbxproj @@ -8,6 +8,9 @@ /* Begin PBXBuildFile section */ 8D9789F71B3C9A7F007CF4CF /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D9789F61B3C9A7F007CF4CF /* main.m */; }; + DCEB15821B3F4371004FA257 /* ListManager.m in Sources */ = {isa = PBXBuildFile; fileRef = DCEB15811B3F4371004FA257 /* ListManager.m */; }; + DCEB15851B3F437B004FA257 /* ListItem.m in Sources */ = {isa = PBXBuildFile; fileRef = DCEB15841B3F437B004FA257 /* ListItem.m */; }; + DCEB15881B3F4386004FA257 /* List.m in Sources */ = {isa = PBXBuildFile; fileRef = DCEB15871B3F4386004FA257 /* List.m */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -25,6 +28,12 @@ /* Begin PBXFileReference section */ 8D9789F31B3C9A7F007CF4CF /* TodoList */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = TodoList; sourceTree = BUILT_PRODUCTS_DIR; }; 8D9789F61B3C9A7F007CF4CF /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + DCEB15801B3F4371004FA257 /* ListManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ListManager.h; sourceTree = ""; }; + DCEB15811B3F4371004FA257 /* ListManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ListManager.m; sourceTree = ""; }; + DCEB15831B3F437B004FA257 /* ListItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ListItem.h; sourceTree = ""; }; + DCEB15841B3F437B004FA257 /* ListItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ListItem.m; sourceTree = ""; }; + DCEB15861B3F4386004FA257 /* List.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = List.h; sourceTree = ""; }; + DCEB15871B3F4386004FA257 /* List.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = List.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -58,6 +67,12 @@ isa = PBXGroup; children = ( 8D9789F61B3C9A7F007CF4CF /* main.m */, + DCEB15831B3F437B004FA257 /* ListItem.h */, + DCEB15841B3F437B004FA257 /* ListItem.m */, + DCEB15861B3F4386004FA257 /* List.h */, + DCEB15871B3F4386004FA257 /* List.m */, + DCEB15801B3F4371004FA257 /* ListManager.h */, + DCEB15811B3F4371004FA257 /* ListManager.m */, ); path = TodoList; sourceTree = ""; @@ -119,6 +134,9 @@ buildActionMask = 2147483647; files = ( 8D9789F71B3C9A7F007CF4CF /* main.m in Sources */, + DCEB15881B3F4386004FA257 /* List.m in Sources */, + DCEB15821B3F4371004FA257 /* ListManager.m in Sources */, + DCEB15851B3F437B004FA257 /* ListItem.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -235,6 +253,7 @@ 8D9789FC1B3C9A7F007CF4CF /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/TodoList/TodoList/List.h b/TodoList/TodoList/List.h new file mode 100644 index 0000000..5581437 --- /dev/null +++ b/TodoList/TodoList/List.h @@ -0,0 +1,30 @@ +// +// List.h +// TodoList +// +// Created by Mesfin Bekele Mekonnen on 6/27/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import + + +@class ListItem; + +@interface List : NSObject + +@property NSString *listName; + + +-(void) addItem:(ListItem *)item; +-(void) printItems; +-(void) deleteItem:(int)index; +-(void) editItem:(int)index; +-(void) markCompleted:(int)index; +-(void) setPriority:(int)value; +-(void) active; +-(void) inActive; +-(void) run; +-(void) printCommandsActive:(BOOL)active inActive:(BOOL)inActive; + +@end diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m new file mode 100644 index 0000000..1af943e --- /dev/null +++ b/TodoList/TodoList/List.m @@ -0,0 +1,53 @@ +// +// List.m +// TodoList +// +// Created by Mesfin Bekele Mekonnen on 6/27/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import "List.h" +#import "ListItem.h" + +@implementation List { + NSMutableArray *_items; +} + +-(void) addItem:(ListItem *)item{ + + if(_items == nil){ + _items = [[NSMutableArray alloc]init]; + } + char temp[256]; + printf("\n Add description: "); + scanf("%255[^\n]%*c",temp); + fpurge(stdin); + NSString *name = [NSString stringWithCString:temp encoding:NSASCIIStringEncoding]; + ListItem *li = [[ListItem alloc] initWithDefaultAndName:name]; + + [_items addObject:li]; +} + +-(void) deleteItem:(int)index{ + NSInteger arraySize = [_items count]; + if(index < 1 || index > arraySize){ + NSString *c = [NSString stringWithFormat:@"%@",index<1? @"Must be greater than or equal to 1":@"out of bounds"]; + printf("%s",[c UTF8String]); + return; + } + [_items removeObjectAtIndex:index]; + +} + +-(void) markCompleted:(int)index{ + NSInteger arraySize = [_items count]; + if(index < 1 || index > arraySize){ + NSString *c = [NSString stringWithFormat:@"%@",index<1? @"Must be greater than or equal to 1":@"out of bounds"]; + printf("%s",[c UTF8String]); + return; + } + + [[_items objectAtIndex:index-1] changeBool]; +} + +@end diff --git a/TodoList/TodoList/ListItem.h b/TodoList/TodoList/ListItem.h new file mode 100644 index 0000000..054b16c --- /dev/null +++ b/TodoList/TodoList/ListItem.h @@ -0,0 +1,19 @@ +// +// ListItem.h +// TodoList +// +// Created by Mesfin Bekele Mekonnen on 6/27/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import + +@interface ListItem : NSObject +-(instancetype)initWithDefaultAndName:(NSString *)name; + +@property NSInteger priority; +@property NSString *itemName; +@property BOOL completed; + +-(void)changeBool; +@end diff --git a/TodoList/TodoList/ListItem.m b/TodoList/TodoList/ListItem.m new file mode 100644 index 0000000..f132878 --- /dev/null +++ b/TodoList/TodoList/ListItem.m @@ -0,0 +1,29 @@ +// +// ListItem.m +// TodoList +// +// Created by Mesfin Bekele Mekonnen on 6/27/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import "ListItem.h" + +@implementation ListItem + +- (instancetype) initWithDefaultAndName:(NSString *)name{ + + if(self = [super init]){ + self.priority = 1; + self.completed = NO; + self.itemName = name; + + return self; + } + return nil; +} + +-(void)changeBool{ + self.completed = YES; +} + +@end diff --git a/TodoList/TodoList/ListManager.h b/TodoList/TodoList/ListManager.h new file mode 100644 index 0000000..b54385a --- /dev/null +++ b/TodoList/TodoList/ListManager.h @@ -0,0 +1,20 @@ +// +// ListManager.h +// TodoList +// +// Created by Mesfin Bekele Mekonnen on 6/27/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import + +@interface ListManager : NSObject + +-(void) printCommands; +-(void) run; +-(void) addList; +-(void) deleteList:(int)index; +-(void) printLists; +-(void) printCommands; + +@end diff --git a/TodoList/TodoList/ListManager.m b/TodoList/TodoList/ListManager.m new file mode 100644 index 0000000..807c652 --- /dev/null +++ b/TodoList/TodoList/ListManager.m @@ -0,0 +1,18 @@ +// +// ListManager.m +// TodoList +// +// Created by Mesfin Bekele Mekonnen on 6/27/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import "ListManager.h" + +@implementation ListManager + +-(void) printCommands{ + + +} + +@end diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 42b8d3f..bed28da 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -8,125 +8,6 @@ #import -@class ListManager; -@class ListItem; -@class List; - -@interface ListManager : NSObject - --(void) printCommands; --(void) run; --(void) addList; --(void) deleteList:(int)index; --(void) printLists; - - -@end - -@implementation ListManager{ - NSMutableArray *_toDoLists; -} - - - -@end - - - - - -@interface ListItem : NSObject - --(instancetype)initWithDefaultAndName:(NSString *)name; - -@property NSInteger priority; -@property NSString *itemName; -@property BOOL completed; - --(void)changeBool; - -@end - -@implementation ListItem - -- (instancetype) initWithDefaultAndName:(NSString *)name{ - - if(self = [super init]){ - self.priority = 1; - self.completed = NO; - self.itemName = name; - - return self; - } - return nil; -} - --(void)changeBool{ - self.completed = YES; -} - -@end - -@interface List : NSObject - -@property NSString *listName; - - --(void) addItem:(ListItem *)item; --(void) printItems; --(void) deleteItem:(int)index; --(void) editItem:(int)index; --(void) markCompleted:(int)index; --(void) setPriority:(int)value; --(void) active; --(void) inActive; --(void) run; --(void) printCommandsActive:(BOOL)active inActive:(BOOL)inActive; - -@end - -@implementation List{ - NSMutableArray *_items; -} --(void) addItem:(ListItem *)item{ - - if(_items == nil){ - _items = [[NSMutableArray alloc]init]; - } - char temp[256]; - printf("\n Add description: "); - scanf("%255[^\n]%*c",temp); - fpurge(stdin); - NSString *name = [NSString stringWithCString:temp encoding:NSASCIIStringEncoding]; - ListItem *li = [[ListItem alloc] initWithDefaultAndName:name]; - - [_items addObject:li]; -} - --(void) deleteItem:(int)index{ - NSInteger arraySize = [_items count]; - if(index < 1 || index > arraySize){ - NSString *c = [NSString stringWithFormat:@"%@",index<1? @"Must be greater than or equal to 1":@"out of bounds"]; - printf("%s",[c UTF8String]); - return; - } - [_items removeObjectAtIndex:index]; - -} - --(void) markCompleted:(int)index{ - NSInteger arraySize = [_items count]; - if(index < 1 || index > arraySize){ - NSString *c = [NSString stringWithFormat:@"%@",index<1? @"Must be greater than or equal to 1":@"out of bounds"]; - printf("%s",[c UTF8String]); - return; - } - - [[_items objectAtIndex:index-1] changeBool]; -} - -@end - int main(int argc, const char * argv[]) { @autoreleasepool { From 543d94c73f2970e5554ee72866a69d4cb1984f95 Mon Sep 17 00:00:00 2001 From: Varindra Date: Sat, 27 Jun 2015 17:03:59 -0400 Subject: [PATCH 03/23] printfunction --- TodoList/TodoList/List.m | 12 +++++++++++- TodoList/TodoList/ListItem.h | 7 +++---- TodoList/TodoList/ListItem.m | 3 --- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m index 1af943e..fb9c102 100644 --- a/TodoList/TodoList/List.m +++ b/TodoList/TodoList/List.m @@ -47,7 +47,17 @@ -(void) markCompleted:(int)index{ return; } - [[_items objectAtIndex:index-1] changeBool]; + ListItem *item = [_items objectAtIndex:index-1]; + item.completed = YES; } +-(void) printItems{ + int i =1; + for(ListItem *li in _items){ + printf("%d. %s\n",i,[li.itemName UTF8String]); + i++; + } + } + + @end diff --git a/TodoList/TodoList/ListItem.h b/TodoList/TodoList/ListItem.h index 054b16c..e195731 100644 --- a/TodoList/TodoList/ListItem.h +++ b/TodoList/TodoList/ListItem.h @@ -11,9 +11,8 @@ @interface ListItem : NSObject -(instancetype)initWithDefaultAndName:(NSString *)name; -@property NSInteger priority; -@property NSString *itemName; -@property BOOL completed; +@property (nonatomic) NSInteger priority; +@property (nonatomic) NSString *itemName; +@property (nonatomic) BOOL completed; --(void)changeBool; @end diff --git a/TodoList/TodoList/ListItem.m b/TodoList/TodoList/ListItem.m index f132878..d5e5fdc 100644 --- a/TodoList/TodoList/ListItem.m +++ b/TodoList/TodoList/ListItem.m @@ -22,8 +22,5 @@ - (instancetype) initWithDefaultAndName:(NSString *)name{ return nil; } --(void)changeBool{ - self.completed = YES; -} @end From c9c2536522345d365494336aba34c96d3d4b1d03 Mon Sep 17 00:00:00 2001 From: Mesfin Date: Sat, 27 Jun 2015 17:04:16 -0400 Subject: [PATCH 04/23] made changes --- TodoList/TodoList/List.h | 2 +- TodoList/TodoList/List.m | 4 ++-- TodoList/TodoList/ListItem.h | 8 ++++---- TodoList/TodoList/ListItem.m | 4 ---- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/TodoList/TodoList/List.h b/TodoList/TodoList/List.h index 5581437..940bb0f 100644 --- a/TodoList/TodoList/List.h +++ b/TodoList/TodoList/List.h @@ -13,7 +13,7 @@ @interface List : NSObject -@property NSString *listName; +@property (nonatomic) NSString *listName; -(void) addItem:(ListItem *)item; diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m index 1af943e..b75915d 100644 --- a/TodoList/TodoList/List.m +++ b/TodoList/TodoList/List.m @@ -46,8 +46,8 @@ -(void) markCompleted:(int)index{ printf("%s",[c UTF8String]); return; } - - [[_items objectAtIndex:index-1] changeBool]; + ListItem *item = [_items objectAtIndex:index-1]; + item.completed = YES; } @end diff --git a/TodoList/TodoList/ListItem.h b/TodoList/TodoList/ListItem.h index 054b16c..4618f43 100644 --- a/TodoList/TodoList/ListItem.h +++ b/TodoList/TodoList/ListItem.h @@ -11,9 +11,9 @@ @interface ListItem : NSObject -(instancetype)initWithDefaultAndName:(NSString *)name; -@property NSInteger priority; -@property NSString *itemName; -@property BOOL completed; +@property (nonatomic) NSInteger priority; +@property (nonatomic) NSString *itemName; +@property (nonatomic) BOOL completed; + --(void)changeBool; @end diff --git a/TodoList/TodoList/ListItem.m b/TodoList/TodoList/ListItem.m index f132878..3eb56e7 100644 --- a/TodoList/TodoList/ListItem.m +++ b/TodoList/TodoList/ListItem.m @@ -22,8 +22,4 @@ - (instancetype) initWithDefaultAndName:(NSString *)name{ return nil; } --(void)changeBool{ - self.completed = YES; -} - @end From 212a741eb4802bec75f62ad18dd879b204e9b179 Mon Sep 17 00:00:00 2001 From: Mesfin Date: Sun, 28 Jun 2015 00:15:47 -0400 Subject: [PATCH 05/23] Added set priortiy and print Commands methods --- TodoList/TodoList/List.h | 6 +++--- TodoList/TodoList/List.m | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/TodoList/TodoList/List.h b/TodoList/TodoList/List.h index 940bb0f..2c74fa5 100644 --- a/TodoList/TodoList/List.h +++ b/TodoList/TodoList/List.h @@ -16,15 +16,15 @@ @property (nonatomic) NSString *listName; --(void) addItem:(ListItem *)item; +-(void) addItem; -(void) printItems; -(void) deleteItem:(int)index; -(void) editItem:(int)index; -(void) markCompleted:(int)index; --(void) setPriority:(int)value; +-(void) setPriority:(int)index; -(void) active; -(void) inActive; -(void) run; --(void) printCommandsActive:(BOOL)active inActive:(BOOL)inActive; +-(void) printCommands; @end diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m index f450f5e..d6f2961 100644 --- a/TodoList/TodoList/List.m +++ b/TodoList/TodoList/List.m @@ -13,7 +13,7 @@ @implementation List { NSMutableArray *_items; } --(void) addItem:(ListItem *)item{ +-(void) addItem{ if(_items == nil){ _items = [[NSMutableArray alloc]init]; @@ -59,5 +59,24 @@ -(void) printItems{ } } +-(void) setPriority:(int)index{ + NSInteger arraySize = [_items count]; + if(index <1 || index >arraySize){ + NSString *c = [NSString stringWithFormat:@"%@",index<1? @"Must be greater than or equal to 1":@"Highest priority level is 4."]; + printf("%s",[c UTF8String]); + return; + } + int newValue; + printf("Enter a priorty value, 1-4"); + scanf("%d",&newValue); + ListItem *li = [_items objectAtIndex:index - 1]; + li.priority = newValue; +} +-(void) printCommands{ + printf("a|add e|edit\n"); + printf("d|delete p|set priority\n"); + printf("c|mark completed a|active\n"); + printf("i|inactive"); +} @end From ca1312b8d8d937469dcb471a7eb89114b2ee418f Mon Sep 17 00:00:00 2001 From: Varindra Date: Sat, 27 Jun 2015 17:37:59 -0400 Subject: [PATCH 06/23] additional methods --- TodoList/TodoList/List.m | 42 ++++++++++++++++++++++++++++++++++++ TodoList/TodoList/ListItem.h | 3 --- TodoList/TodoList/ListItem.m | 3 --- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m index d6f2961..6dff07f 100644 --- a/TodoList/TodoList/List.m +++ b/TodoList/TodoList/List.m @@ -73,6 +73,48 @@ -(void) setPriority:(int)index{ li.priority = newValue; } +-(void) editItem:(int)index{ + char newName [256]; + printf("New description: "); + scanf("%255[^\n]%*c",newName); + fpurge(stdin); + ListItem *li = [_items objectAtIndex:index-1]; + li.itemName = [NSString stringWithCString:newName encoding:NSASCIIStringEncoding]; +} + +-(void) active{ + int i = 1; + printf("\n"); + for(ListItem * li in _items){ + if(!li.completed){ + printf("%d. %s\n",i, [li.itemName UTF8String]); + } + } +} + +-(void) inActive{ + int i = 1; + printf("\n"); + for(ListItem * li in _items){ + if(li.completed){ + printf("%d. %s\n",i, [li.itemName UTF8String]); + } + } +} + +-(void) run{ + while(YES){ + char holder[256]; + [self printItems]; + //[self printCommandActive:..:inactive + scanf("%255[^\n]%*c",holder); + NSString *checker = [NSString stringWithCString:holder encoding:NSASCIIStringEncoding]; + if([checker isEqualToString:@"e"] || [checker isEqualToString:@"E"]){ + + } + } +} + -(void) printCommands{ printf("a|add e|edit\n"); printf("d|delete p|set priority\n"); diff --git a/TodoList/TodoList/ListItem.h b/TodoList/TodoList/ListItem.h index 500f2b0..4618f43 100644 --- a/TodoList/TodoList/ListItem.h +++ b/TodoList/TodoList/ListItem.h @@ -14,9 +14,6 @@ @property (nonatomic) NSInteger priority; @property (nonatomic) NSString *itemName; @property (nonatomic) BOOL completed; -<<<<<<< HEAD -======= ->>>>>>> 543d94c73f2970e5554ee72866a69d4cb1984f95 @end diff --git a/TodoList/TodoList/ListItem.m b/TodoList/TodoList/ListItem.m index c08f15c..d5e5fdc 100644 --- a/TodoList/TodoList/ListItem.m +++ b/TodoList/TodoList/ListItem.m @@ -22,8 +22,5 @@ - (instancetype) initWithDefaultAndName:(NSString *)name{ return nil; } -<<<<<<< HEAD -======= ->>>>>>> 543d94c73f2970e5554ee72866a69d4cb1984f95 @end From a086a3d5ae190339053a143fc51586bb39eb4548 Mon Sep 17 00:00:00 2001 From: Varindra Date: Sun, 28 Jun 2015 10:10:45 -0400 Subject: [PATCH 07/23] listmaster Run --- TodoList/TodoList/List.m | 97 ++++++++++++++++++++++++++++++--- TodoList/TodoList/ListManager.m | 59 +++++++++++++++++++- 2 files changed, 146 insertions(+), 10 deletions(-) diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m index 6dff07f..f3de993 100644 --- a/TodoList/TodoList/List.m +++ b/TodoList/TodoList/List.m @@ -82,14 +82,15 @@ -(void) editItem:(int)index{ li.itemName = [NSString stringWithCString:newName encoding:NSASCIIStringEncoding]; } + -(void) active{ - int i = 1; - printf("\n"); - for(ListItem * li in _items){ - if(!li.completed){ - printf("%d. %s\n",i, [li.itemName UTF8String]); + int i = 1; + printf("\n"); + for(ListItem * li in _items){ + if(!li.completed){ + printf("%d. %s\n",i, [li.itemName UTF8String]); + } } - } } -(void) inActive{ @@ -106,12 +107,94 @@ -(void) run{ while(YES){ char holder[256]; [self printItems]; - //[self printCommandActive:..:inactive + //[self printCommands scanf("%255[^\n]%*c",holder); NSString *checker = [NSString stringWithCString:holder encoding:NSASCIIStringEncoding]; + if([checker isEqualToString:@"e"] || [checker isEqualToString:@"E"]){ + int d; + printf("/nIndex number? "); + scanf("%d",&d); + fpurge(stdin); + NSInteger arraySize = [_items count]; + if(d < 1 || d > arraySize){ + NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1":@"out of bounds"]; + printf("%s",[c UTF8String]); + continue; + } + [self editItem:d]; + continue; + } + + if([checker isEqualToString:@"d"] || [checker isEqualToString:@"D"]){ + int d; + printf("/nIndex number? "); + scanf("%d",&d); + fpurge(stdin); + NSInteger arraySize = [_items count]; + if(d < 1 || d > arraySize){ + NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1":@"out of bounds"]; + printf("%s",[c UTF8String]); + continue; + } + [self deleteItem:d]; + continue; + } + + if([checker isEqualToString:@"c"] || [checker isEqualToString:@"C"]){ + int d; + printf("/nIndex number? "); + scanf("%d",&d); + fpurge(stdin); + NSInteger arraySize = [_items count]; + if(d < 1 || d > arraySize){ + NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1":@"out of bounds"]; + printf("%s",[c UTF8String]); + continue; + } + [self markCompleted:d]; + continue; + } + + if([checker isEqualToString:@"p"] || [checker isEqualToString:@"P"]){ + int d; + printf("/nIndex number? "); + scanf("%d",&d); + fpurge(stdin); + NSInteger arraySize = [_items count]; + if(d < 1 || d > arraySize){ + NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1":@"out of bounds"]; + printf("%s",[c UTF8String]); + continue; + } + [self setPriority:d]; + continue; } + + if([checker isEqualToString:@"a"] || [checker isEqualToString:@"A"]){ + + [self addItem]; + continue; + } + + if([checker isEqualToString:@"act"] || [checker isEqualToString:@"ACT"]){ + + [self active]; + continue; + } + + if([checker isEqualToString:@"i"] || [checker isEqualToString:@"i"]){ + + [self inActive]; + continue; + } + + if([checker isEqualToString:@"q"] || [checker isEqualToString:@"Q"]){ + + break; + } + } } diff --git a/TodoList/TodoList/ListManager.m b/TodoList/TodoList/ListManager.m index 807c652..9903b8f 100644 --- a/TodoList/TodoList/ListManager.m +++ b/TodoList/TodoList/ListManager.m @@ -7,12 +7,65 @@ // #import "ListManager.h" +#import "List.h" +#import "ListItem.h" -@implementation ListManager +@class List; + +@implementation ListManager{ + NSMutableArray +} -(void) printCommands{ - - } +-(void) run{ + while(YES){ + char userIn[256]; + //[self printLists] + //[self printCommands] + scanf("%255[^\n]%*c",userIn); + NSString *userString = [NSString stringWithCString:userIn encoding:NSASCIIStringEncoding]; + + if([userString isEqualToString:@"a"] || [userString isEqualToString:@"A"]){ + + [self addList]; + continue; + } + + if([userString isEqualToString:@"d"] || [userString isEqualToString:@"D"]){ + int d; + printf("/nList Number? "); + scanf("%d",&d); + fpurge(stdin); + NSInteger arraySize = [//_items count]; + if(d < 1 || d > arraySize){ + NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1":@"out of bounds"]; + printf("%s",[c UTF8String]); + continue; + } + [self addList]; + continue; + } + + if([userString isEqualToString:@"v"] || [userString isEqualToString:@"V"]){ + int d; + printf("/nIndex number? "); + scanf("%d",&d); + fpurge(stdin); + NSInteger arraySize = [//_items count]; + if(d < 1 || d > arraySize){ + NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1":@"out of bounds"]; + printf("%s",[c UTF8String]); + continue; + } + List* temp = [//_items objectAtIndex:d-1] ; + //[temp run] + continue; + } + + + + } + } @end From 90b86e1d683822d916d9870b902a6238108a0ede Mon Sep 17 00:00:00 2001 From: Varindra Date: Sun, 28 Jun 2015 10:27:25 -0400 Subject: [PATCH 08/23] ListManager run and array added --- TodoList/TodoList/ListManager.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/TodoList/TodoList/ListManager.m b/TodoList/TodoList/ListManager.m index 9903b8f..4e905eb 100644 --- a/TodoList/TodoList/ListManager.m +++ b/TodoList/TodoList/ListManager.m @@ -13,7 +13,7 @@ @class List; @implementation ListManager{ - NSMutableArray + NSMutableArray *_listArray; } -(void) printCommands{ @@ -37,7 +37,7 @@ -(void) run{ printf("/nList Number? "); scanf("%d",&d); fpurge(stdin); - NSInteger arraySize = [//_items count]; + NSInteger arraySize = [_listArray count]; if(d < 1 || d > arraySize){ NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1":@"out of bounds"]; printf("%s",[c UTF8String]); @@ -52,14 +52,14 @@ -(void) run{ printf("/nIndex number? "); scanf("%d",&d); fpurge(stdin); - NSInteger arraySize = [//_items count]; + NSInteger arraySize = [_listArray count]; if(d < 1 || d > arraySize){ NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1":@"out of bounds"]; printf("%s",[c UTF8String]); continue; } - List* temp = [//_items objectAtIndex:d-1] ; - //[temp run] + List* temp = [_listArray objectAtIndex:d-1] ; + [temp run]; continue; } From 9aec721ede1ec20809ca91c861aea1c93bfabad8 Mon Sep 17 00:00:00 2001 From: Mesfin Date: Sun, 28 Jun 2015 10:41:19 -0400 Subject: [PATCH 09/23] Added deletelist and addList methods --- TodoList/TodoList/List.h | 1 + TodoList/TodoList/List.m | 20 ++++++++++++++----- TodoList/TodoList/ListManager.h | 1 - TodoList/TodoList/ListManager.m | 34 ++++++++++++++++++++++++++++++++- 4 files changed, 49 insertions(+), 7 deletions(-) diff --git a/TodoList/TodoList/List.h b/TodoList/TodoList/List.h index 2c74fa5..b565999 100644 --- a/TodoList/TodoList/List.h +++ b/TodoList/TodoList/List.h @@ -15,6 +15,7 @@ @property (nonatomic) NSString *listName; +-(instancetype)initWithName:(NSString *)name; -(void) addItem; -(void) printItems; diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m index f3de993..0185fa0 100644 --- a/TodoList/TodoList/List.m +++ b/TodoList/TodoList/List.m @@ -13,6 +13,15 @@ @implementation List { NSMutableArray *_items; } +- (instancetype) initWithName:(NSString *)name{ + + if(self = [super init]){ + self.listName = name; + return self; + } + return nil; +} + -(void) addItem{ if(_items == nil){ @@ -107,7 +116,7 @@ -(void) run{ while(YES){ char holder[256]; [self printItems]; - //[self printCommands + [self printCommands]; scanf("%255[^\n]%*c",holder); NSString *checker = [NSString stringWithCString:holder encoding:NSASCIIStringEncoding]; @@ -178,13 +187,13 @@ -(void) run{ continue; } - if([checker isEqualToString:@"act"] || [checker isEqualToString:@"ACT"]){ + if([checker isEqualToString:@"t"] || [checker isEqualToString:@"T"]){ [self active]; continue; } - if([checker isEqualToString:@"i"] || [checker isEqualToString:@"i"]){ + if([checker isEqualToString:@"i"] || [checker isEqualToString:@"I"]){ [self inActive]; continue; @@ -201,7 +210,8 @@ -(void) run{ -(void) printCommands{ printf("a|add e|edit\n"); printf("d|delete p|set priority\n"); - printf("c|mark completed a|active\n"); - printf("i|inactive"); + printf("c|mark completed t|active\n"); + printf("i|inactive q|quit\n"); + } @end diff --git a/TodoList/TodoList/ListManager.h b/TodoList/TodoList/ListManager.h index b54385a..69dddd0 100644 --- a/TodoList/TodoList/ListManager.h +++ b/TodoList/TodoList/ListManager.h @@ -10,7 +10,6 @@ @interface ListManager : NSObject --(void) printCommands; -(void) run; -(void) addList; -(void) deleteList:(int)index; diff --git a/TodoList/TodoList/ListManager.m b/TodoList/TodoList/ListManager.m index 4e905eb..e81a384 100644 --- a/TodoList/TodoList/ListManager.m +++ b/TodoList/TodoList/ListManager.m @@ -17,7 +17,36 @@ @implementation ListManager{ } -(void) printCommands{ + + printf("a|add v|view\n"); + printf("d|delete q|quit\n"); +} + +-(void)addList{ + if(_listArray == nil){ + _listArray = [[NSMutableArray alloc]init]; + } + char temp[256]; + printf("\n Add title of Todo-List: "); + scanf("%255[^\n]%*c",temp); + fpurge(stdin); + NSString *name = [NSString stringWithCString:temp encoding:NSASCIIStringEncoding]; + List *li = [[List alloc] initWithName:name]; + + [_listArray addObject:li]; +} + +-(void) deleteList:(int)index{ + NSInteger arraySize = [_listArray count]; + if(index < 1 || index > arraySize){ + NSString *c = [NSString stringWithFormat:@"%@",index<1? @"Must be greater than or equal to 1":@"out of bounds"]; + printf("%s",[c UTF8String]); + return; + } + [_listArray removeObjectAtIndex:index]; + } + -(void) run{ while(YES){ char userIn[256]; @@ -62,7 +91,10 @@ -(void) run{ [temp run]; continue; } - + if([userString isEqualToString:@"q"] || [userString isEqualToString:@"Q"]){ + + break; + } } From 2f9f4e10446c1dacda0cdec4c56d97b5008153cd Mon Sep 17 00:00:00 2001 From: Varindra Date: Sun, 28 Jun 2015 10:41:10 -0400 Subject: [PATCH 10/23] listManager with printLists --- TodoList/TodoList/List.m | 4 +++- TodoList/TodoList/ListManager.m | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m index 0185fa0..4ec6199 100644 --- a/TodoList/TodoList/List.m +++ b/TodoList/TodoList/List.m @@ -212,6 +212,8 @@ -(void) printCommands{ printf("d|delete p|set priority\n"); printf("c|mark completed t|active\n"); printf("i|inactive q|quit\n"); - + printf("c|mark completed a|active\n"); + printf("i|inactive q|quit\n"); + } @end diff --git a/TodoList/TodoList/ListManager.m b/TodoList/TodoList/ListManager.m index e81a384..8c9f3e9 100644 --- a/TodoList/TodoList/ListManager.m +++ b/TodoList/TodoList/ListManager.m @@ -47,6 +47,14 @@ -(void) deleteList:(int)index{ } +-(void) printLists{ + int i =1; + for(List *l in _listArray){ + printf("%d. %s\n",i, [l.listName UTF8String]); + } +} + + -(void) run{ while(YES){ char userIn[256]; From 315b26ba11e332ce73e0841c15541b05514c0740 Mon Sep 17 00:00:00 2001 From: Varindra Date: Sun, 28 Jun 2015 10:44:27 -0400 Subject: [PATCH 11/23] listmanager complete --- TodoList/TodoList/ListManager.m | 1 + 1 file changed, 1 insertion(+) diff --git a/TodoList/TodoList/ListManager.m b/TodoList/TodoList/ListManager.m index 8c9f3e9..cd165bb 100644 --- a/TodoList/TodoList/ListManager.m +++ b/TodoList/TodoList/ListManager.m @@ -51,6 +51,7 @@ -(void) printLists{ int i =1; for(List *l in _listArray){ printf("%d. %s\n",i, [l.listName UTF8String]); + i++; } } From ede3b43d3b56c810194576d97d4ff9991c588c58 Mon Sep 17 00:00:00 2001 From: Mesfin Date: Sun, 28 Jun 2015 11:03:12 -0400 Subject: [PATCH 12/23] Debugged some methods --- TodoList/TodoList/List.m | 49 +++++++++++++++++---------------- TodoList/TodoList/ListManager.m | 21 ++++++-------- TodoList/TodoList/main.m | 11 +++++++- 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m index 4ec6199..bf11cb3 100644 --- a/TodoList/TodoList/List.m +++ b/TodoList/TodoList/List.m @@ -55,18 +55,19 @@ -(void) markCompleted:(int)index{ printf("%s",[c UTF8String]); return; } - + ListItem *item = [_items objectAtIndex:index-1]; item.completed = YES; } -(void) printItems{ - int i =1; - for(ListItem *li in _items){ - printf("%d. %s\n",i,[li.itemName UTF8String]); - i++; - } + int i =1; + for(ListItem *li in _items){ + printf("%d. %s\n",i,[li.itemName UTF8String]); + i++; } + printf("\n"); +} -(void) setPriority:(int)index{ NSInteger arraySize = [_items count]; @@ -93,13 +94,13 @@ -(void) editItem:(int)index{ -(void) active{ - int i = 1; - printf("\n"); - for(ListItem * li in _items){ - if(!li.completed){ - printf("%d. %s\n",i, [li.itemName UTF8String]); - } + int i = 1; + printf("\n"); + for(ListItem * li in _items){ + if(!li.completed){ + printf("%d. %s\n",i, [li.itemName UTF8String]); } + } } -(void) inActive{ @@ -122,7 +123,7 @@ -(void) run{ if([checker isEqualToString:@"e"] || [checker isEqualToString:@"E"]){ int d; - printf("/nIndex number? "); + printf("\nIndex number? "); scanf("%d",&d); fpurge(stdin); NSInteger arraySize = [_items count]; @@ -131,7 +132,7 @@ -(void) run{ printf("%s",[c UTF8String]); continue; } - [self editItem:d]; + [self editItem:d-1]; continue; } @@ -146,7 +147,7 @@ -(void) run{ printf("%s",[c UTF8String]); continue; } - [self deleteItem:d]; + [self deleteItem:d-1]; continue; } @@ -180,7 +181,7 @@ -(void) run{ [self setPriority:d]; continue; } - + if([checker isEqualToString:@"a"] || [checker isEqualToString:@"A"]){ [self addItem]; @@ -203,17 +204,17 @@ -(void) run{ break; } - + } } -(void) printCommands{ - printf("a|add e|edit\n"); - printf("d|delete p|set priority\n"); - printf("c|mark completed t|active\n"); - printf("i|inactive q|quit\n"); - printf("c|mark completed a|active\n"); - printf("i|inactive q|quit\n"); - + printf("a|add e|edit\n"); + printf("d|delete p|set priority\n"); + printf("c|mark completed t|active\n"); + printf("i|inactive q|quit\n"); + printf("c|mark completed a|active\n"); + printf("i|inactive q|quit\n"); + } @end diff --git a/TodoList/TodoList/ListManager.m b/TodoList/TodoList/ListManager.m index cd165bb..e215a47 100644 --- a/TodoList/TodoList/ListManager.m +++ b/TodoList/TodoList/ListManager.m @@ -30,6 +30,7 @@ -(void)addList{ printf("\n Add title of Todo-List: "); scanf("%255[^\n]%*c",temp); fpurge(stdin); + printf("\n"); NSString *name = [NSString stringWithCString:temp encoding:NSASCIIStringEncoding]; List *li = [[List alloc] initWithName:name]; @@ -37,12 +38,7 @@ -(void)addList{ } -(void) deleteList:(int)index{ - NSInteger arraySize = [_listArray count]; - if(index < 1 || index > arraySize){ - NSString *c = [NSString stringWithFormat:@"%@",index<1? @"Must be greater than or equal to 1":@"out of bounds"]; - printf("%s",[c UTF8String]); - return; - } + [_listArray removeObjectAtIndex:index]; } @@ -53,14 +49,15 @@ -(void) printLists{ printf("%d. %s\n",i, [l.listName UTF8String]); i++; } + printf("\n"); } -(void) run{ while(YES){ char userIn[256]; - //[self printLists] - //[self printCommands] + [self printLists]; + [self printCommands]; scanf("%255[^\n]%*c",userIn); NSString *userString = [NSString stringWithCString:userIn encoding:NSASCIIStringEncoding]; @@ -72,22 +69,22 @@ -(void) run{ if([userString isEqualToString:@"d"] || [userString isEqualToString:@"D"]){ int d; - printf("/nList Number? "); + printf("\nList Number? "); scanf("%d",&d); fpurge(stdin); NSInteger arraySize = [_listArray count]; if(d < 1 || d > arraySize){ - NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1":@"out of bounds"]; + NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1\n":@"out of bounds\n"]; printf("%s",[c UTF8String]); continue; } - [self addList]; + [self deleteList:d-1]; continue; } if([userString isEqualToString:@"v"] || [userString isEqualToString:@"V"]){ int d; - printf("/nIndex number? "); + printf("\nIndex number? "); scanf("%d",&d); fpurge(stdin); NSInteger arraySize = [_listArray count]; diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index bed28da..037b9a1 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -7,10 +7,19 @@ // #import - +#import "ListItem.h" +#import "ListManager.h" +#import "List.h" int main(int argc, const char * argv[]) { @autoreleasepool { + printf("Welcome to your To-do List app!"); + printf("\n\n*******************************\n"); + + + ListManager *lm = [[ListManager alloc]init]; + + [lm run]; } return 0; } From 6eaea3ff74b7bee94e6280831ff92c079c53fa76 Mon Sep 17 00:00:00 2001 From: Varindra Date: Sun, 28 Jun 2015 11:03:31 -0400 Subject: [PATCH 13/23] latest model --- TodoList/TodoList/main.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 037b9a1..9c00d1b 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -7,9 +7,12 @@ // #import -#import "ListItem.h" + #import "ListManager.h" #import "List.h" +#import "ListItem.h" + + int main(int argc, const char * argv[]) { @autoreleasepool { From 95d599747068b5feb38df9435557e1d890c6d5ca Mon Sep 17 00:00:00 2001 From: Varindra Date: Sun, 28 Jun 2015 11:40:03 -0400 Subject: [PATCH 14/23] done..i think --- TodoList/TodoList/List.m | 82 +++++++++++++++++++-------------- TodoList/TodoList/ListManager.m | 1 + 2 files changed, 48 insertions(+), 35 deletions(-) diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m index bf11cb3..9727db6 100644 --- a/TodoList/TodoList/List.m +++ b/TodoList/TodoList/List.m @@ -38,25 +38,14 @@ -(void) addItem{ } -(void) deleteItem:(int)index{ - NSInteger arraySize = [_items count]; - if(index < 1 || index > arraySize){ - NSString *c = [NSString stringWithFormat:@"%@",index<1? @"Must be greater than or equal to 1":@"out of bounds"]; - printf("%s",[c UTF8String]); - return; - } + [_items removeObjectAtIndex:index]; } -(void) markCompleted:(int)index{ - NSInteger arraySize = [_items count]; - if(index < 1 || index > arraySize){ - NSString *c = [NSString stringWithFormat:@"%@",index<1? @"Must be greater than or equal to 1":@"out of bounds"]; - printf("%s",[c UTF8String]); - return; - } - - ListItem *item = [_items objectAtIndex:index-1]; + + ListItem *item = [_items objectAtIndex:index]; item.completed = YES; } @@ -70,16 +59,13 @@ -(void) printItems{ } -(void) setPriority:(int)index{ - NSInteger arraySize = [_items count]; - if(index <1 || index >arraySize){ - NSString *c = [NSString stringWithFormat:@"%@",index<1? @"Must be greater than or equal to 1":@"Highest priority level is 4."]; - printf("%s",[c UTF8String]); - return; - } int newValue; - printf("Enter a priorty value, 1-4"); + + printf("Enter a priority value, 1-4: "); scanf("%d",&newValue); - ListItem *li = [_items objectAtIndex:index - 1]; + fpurge(stdin); + + ListItem *li = [_items objectAtIndex:index]; li.priority = newValue; } @@ -88,7 +74,7 @@ -(void) editItem:(int)index{ printf("New description: "); scanf("%255[^\n]%*c",newName); fpurge(stdin); - ListItem *li = [_items objectAtIndex:index-1]; + ListItem *li = [_items objectAtIndex:index]; li.itemName = [NSString stringWithCString:newName encoding:NSASCIIStringEncoding]; } @@ -99,6 +85,17 @@ -(void) active{ for(ListItem * li in _items){ if(!li.completed){ printf("%d. %s\n",i, [li.itemName UTF8String]); + i++; + } + } + while(YES){ + char exitKey[256]; + printf("To exit press q: "); + scanf("%255[^\n]%*c",exitKey); + NSString *c = [NSString stringWithCString:exitKey encoding:NSASCIIStringEncoding]; + if ([c isEqualToString:@"q"] || [c isEqualToString:@"Q"]){ + printf("\n\n\n"); + break; } } } @@ -109,6 +106,17 @@ -(void) inActive{ for(ListItem * li in _items){ if(li.completed){ printf("%d. %s\n",i, [li.itemName UTF8String]); + i++; + } + } + while(YES){ + char exitKey[256]; + printf("To exit press q: "); + scanf("%255[^\n]%*c",exitKey); + NSString *c = [NSString stringWithCString:exitKey encoding:NSASCIIStringEncoding]; + if ([c isEqualToString:@"q"] || [c isEqualToString:@"Q"]){ + printf("\n\n\n"); + break; } } } @@ -118,7 +126,10 @@ -(void) run{ char holder[256]; [self printItems]; [self printCommands]; + printf("\n:"); scanf("%255[^\n]%*c",holder); + fpurge(stdin); + NSString *checker = [NSString stringWithCString:holder encoding:NSASCIIStringEncoding]; if([checker isEqualToString:@"e"] || [checker isEqualToString:@"E"]){ @@ -126,9 +137,10 @@ -(void) run{ printf("\nIndex number? "); scanf("%d",&d); fpurge(stdin); + printf("\n"); NSInteger arraySize = [_items count]; if(d < 1 || d > arraySize){ - NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1":@"out of bounds"]; + NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1\n":@"out of bounds\n"]; printf("%s",[c UTF8String]); continue; } @@ -138,12 +150,13 @@ -(void) run{ if([checker isEqualToString:@"d"] || [checker isEqualToString:@"D"]){ int d; - printf("/nIndex number? "); + printf("\nIndex number? "); scanf("%d",&d); fpurge(stdin); + printf("\n"); NSInteger arraySize = [_items count]; if(d < 1 || d > arraySize){ - NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1":@"out of bounds"]; + NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1\n":@"out of bounds\n"]; printf("%s",[c UTF8String]); continue; } @@ -153,32 +166,33 @@ -(void) run{ if([checker isEqualToString:@"c"] || [checker isEqualToString:@"C"]){ int d; - printf("/nIndex number? "); + printf("\nIndex number? "); scanf("%d",&d); fpurge(stdin); + printf("\n"); NSInteger arraySize = [_items count]; if(d < 1 || d > arraySize){ - NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1":@"out of bounds"]; + NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1\n":@"out of bounds\n"]; printf("%s",[c UTF8String]); continue; } - [self markCompleted:d]; + [self markCompleted:d-1]; continue; } if([checker isEqualToString:@"p"] || [checker isEqualToString:@"P"]){ int d; - printf("/nIndex number? "); + printf("\nIndex number? "); scanf("%d",&d); fpurge(stdin); NSInteger arraySize = [_items count]; if(d < 1 || d > arraySize){ - NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1":@"out of bounds"]; + NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1\n":@"out of bounds\n"]; printf("%s",[c UTF8String]); continue; } - [self setPriority:d]; + [self setPriority:d-1]; continue; } @@ -201,7 +215,7 @@ -(void) run{ } if([checker isEqualToString:@"q"] || [checker isEqualToString:@"Q"]){ - + printf("\n\n\n"); break; } @@ -213,8 +227,6 @@ -(void) printCommands{ printf("d|delete p|set priority\n"); printf("c|mark completed t|active\n"); printf("i|inactive q|quit\n"); - printf("c|mark completed a|active\n"); - printf("i|inactive q|quit\n"); } @end diff --git a/TodoList/TodoList/ListManager.m b/TodoList/TodoList/ListManager.m index e215a47..740b814 100644 --- a/TodoList/TodoList/ListManager.m +++ b/TodoList/TodoList/ListManager.m @@ -58,6 +58,7 @@ -(void) run{ char userIn[256]; [self printLists]; [self printCommands]; + printf("\n:"); scanf("%255[^\n]%*c",userIn); NSString *userString = [NSString stringWithCString:userIn encoding:NSASCIIStringEncoding]; From caa4128f1ee3592fcc1e76d736524cbade346957 Mon Sep 17 00:00:00 2001 From: Mesfin Date: Sun, 28 Jun 2015 11:40:37 -0400 Subject: [PATCH 15/23] Edit some methods --- TodoList/TodoList/List.m | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m index 9727db6..2d677e7 100644 --- a/TodoList/TodoList/List.m +++ b/TodoList/TodoList/List.m @@ -38,14 +38,14 @@ -(void) addItem{ } -(void) deleteItem:(int)index{ - - [_items removeObjectAtIndex:index]; + [_items removeObjectAtIndex:index]; } -(void) markCompleted:(int)index{ ListItem *item = [_items objectAtIndex:index]; + item.completed = YES; } @@ -60,11 +60,11 @@ -(void) printItems{ -(void) setPriority:(int)index{ int newValue; - + printf("Enter a priority value, 1-4: "); scanf("%d",&newValue); fpurge(stdin); - + ListItem *li = [_items objectAtIndex:index]; li.priority = newValue; } @@ -227,6 +227,5 @@ -(void) printCommands{ printf("d|delete p|set priority\n"); printf("c|mark completed t|active\n"); printf("i|inactive q|quit\n"); - } @end From e06269789f8fed36af1cb05cbd77ddbfbd62d7c3 Mon Sep 17 00:00:00 2001 From: Mesfin Date: Sun, 28 Jun 2015 23:28:41 -0400 Subject: [PATCH 16/23] Added priority and due date --- TodoList/TodoList/List.h | 7 ++ TodoList/TodoList/List.m | 157 +++++++++++++++++++++++++++++--- TodoList/TodoList/ListItem.h | 6 +- TodoList/TodoList/ListItem.m | 14 +++ TodoList/TodoList/ListManager.m | 4 +- 5 files changed, 172 insertions(+), 16 deletions(-) diff --git a/TodoList/TodoList/List.h b/TodoList/TodoList/List.h index b565999..abc3e38 100644 --- a/TodoList/TodoList/List.h +++ b/TodoList/TodoList/List.h @@ -15,6 +15,10 @@ @property (nonatomic) NSString *listName; +@property (nonatomic) int id; +@property (nonatomic) BOOL viewPriority; +@property (nonatomic) BOOL viewByDueDate; + -(instancetype)initWithName:(NSString *)name; -(void) addItem; @@ -27,5 +31,8 @@ -(void) inActive; -(void) run; -(void) printCommands; +-(void) printItemsByPriority; +-(void) printByDueDate; +-(void) setDate:(int)index; @end diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m index 2d677e7..57e505f 100644 --- a/TodoList/TodoList/List.m +++ b/TodoList/TodoList/List.m @@ -33,7 +33,8 @@ -(void) addItem{ fpurge(stdin); NSString *name = [NSString stringWithCString:temp encoding:NSASCIIStringEncoding]; ListItem *li = [[ListItem alloc] initWithDefaultAndName:name]; - + li.idNumber=self.id; + self.id+=1; [_items addObject:li]; } @@ -43,13 +44,46 @@ -(void) deleteItem:(int)index{ } -(void) markCompleted:(int)index{ - + ListItem *item = [_items objectAtIndex:index]; - + item.completed = YES; } +-(void) setDate:(int)index{ + ListItem *item = [_items objectAtIndex:index]; + + item.hasDate = YES; + + char array[256]; + printf("Enter date mm/dd/yyyy: "); + scanf("%255[^\n]%*c",array); + fpurge(stdin); + + NSString *info = [NSString stringWithCString:array encoding:NSASCIIStringEncoding]; + + NSArray *parts = [info componentsSeparatedByString:@"/"]; + + NSDateComponents *c = [[NSDateComponents alloc]init]; + + NSInteger a = [parts[0] integerValue]; + NSInteger b = [[parts[1] description] integerValue]; + NSInteger d = [[parts[2] description] integerValue]; + + [c setDay:b]; + [c setMonth:a]; + [c setYear:d]; + + NSCalendar *calendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; + + NSDate *date = [calendar dateFromComponents:c]; + item.date = date; +} + -(void) printItems{ + NSSortDescriptor *sortingMethod = [[NSSortDescriptor alloc] initWithKey:@"idNumber" ascending:YES]; + + [_items sortUsingDescriptors:@[sortingMethod]]; int i =1; for(ListItem *li in _items){ printf("%d. %s\n",i,[li.itemName UTF8String]); @@ -57,14 +91,62 @@ -(void) printItems{ } printf("\n"); } +-(void) printItemsByPriority{ + int i=1; + char *p1 = " *"; + char *p2 = " **"; + char *p3 = " ***"; + char *p4 = "****"; + + NSSortDescriptor *sortingMethod = [[NSSortDescriptor alloc] initWithKey:@"priority" ascending:NO]; + + [_items sortUsingDescriptors:@[sortingMethod]]; + + for (ListItem *li in _items) { + if(li.priority == 1){ + printf("%d. %s %s\n",i,p1,[li.itemName UTF8String]); + } + if (li.priority == 2) { + printf("%d. %s %s\n",i,p2,[li.itemName UTF8String]); + } + if (li.priority == 3) { + printf("%d. %s %s\n",i,p3,[li.itemName UTF8String]); + } + if (li.priority == 4) { + printf("%d. %s %s\n",i,p4,[li.itemName UTF8String]); + } + i++; + } + printf("\n"); +} + +-(void) printByDueDate{ + int i =1; + NSSortDescriptor *sortingMethod = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:YES]; + + [_items sortUsingDescriptors:@[sortingMethod]]; + for(ListItem *li in _items){ + if(li.hasDate){ + unsigned unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay; + NSCalendar *gregorian = [NSCalendar currentCalendar]; + NSDateComponents *component = [gregorian components:unitFlags fromDate:li.date]; + printf("%d. %s |%d/%d/%d\n",i,[li.itemName UTF8String],(int)[component month], (int)[component day], (int)[component year]); + } + else{ + printf("%d. %s\n",i,[li.itemName UTF8String]); + } + i++; + } + printf("\n"); +} -(void) setPriority:(int)index{ int newValue; - + printf("Enter a priority value, 1-4: "); scanf("%d",&newValue); fpurge(stdin); - + ListItem *li = [_items objectAtIndex:index]; li.priority = newValue; } @@ -124,12 +206,20 @@ -(void) inActive{ -(void) run{ while(YES){ char holder[256]; - [self printItems]; + if (self.viewPriority == NO && self.viewByDueDate == NO){ + [self printItems]; + } + if(self.viewPriority){ + [self printItemsByPriority]; + } + if(self.viewByDueDate){ + [self printByDueDate]; + } [self printCommands]; printf("\n:"); scanf("%255[^\n]%*c",holder); fpurge(stdin); - + NSString *checker = [NSString stringWithCString:holder encoding:NSASCIIStringEncoding]; if([checker isEqualToString:@"e"] || [checker isEqualToString:@"E"]){ @@ -164,7 +254,7 @@ -(void) run{ continue; } - if([checker isEqualToString:@"c"] || [checker isEqualToString:@"C"]){ + if([checker isEqualToString:@"d"] || [checker isEqualToString:@"D"]){ int d; printf("\nIndex number? "); scanf("%d",&d); @@ -176,7 +266,23 @@ -(void) run{ printf("%s",[c UTF8String]); continue; } - [self markCompleted:d-1]; + [self deleteItem:d-1]; + continue; + } + + if([checker isEqualToString:@"sd"] || [checker isEqualToString:@"SD"]){ + int d; + printf("\nIndex number? "); + scanf("%d",&d); + fpurge(stdin); + printf("\n"); + NSInteger arraySize = [_items count]; + if(d < 1 || d > arraySize){ + NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1\n":@"out of bounds\n"]; + printf("%s",[c UTF8String]); + continue; + } + [self setDate:d-1]; continue; } @@ -202,6 +308,11 @@ -(void) run{ continue; } + if([checker isEqualToString:@"t"] || [checker isEqualToString:@"T"]){ + + [self active]; + continue; + } if([checker isEqualToString:@"t"] || [checker isEqualToString:@"T"]){ [self active]; @@ -218,14 +329,34 @@ -(void) run{ printf("\n\n\n"); break; } + if([checker isEqualToString:@"vp"] || [checker isEqualToString:@"VP"]){ + if(self.viewPriority){ + self.viewPriority=NO; + } + else{ + self.viewPriority = YES; + } + continue; + } + if([checker isEqualToString:@"vd"] || [checker isEqualToString:@"VD"]){ + if(self.viewByDueDate){ + self.viewPriority=NO; + } + else{ + self.viewByDueDate = YES; + } + continue; + } } } -(void) printCommands{ - printf("a|add e|edit\n"); - printf("d|delete p|set priority\n"); - printf("c|mark completed t|active\n"); - printf("i|inactive q|quit\n"); + printf(" a|add e|edit sd|set due date\n"); + printf(" d|delete p|set priority c|mark completed\n"); + printf(" t|active i|inactive q|quit\n"); + printf("vp|View by priority(ON/OFF) vd|View by date(ON/OFF)\n"); + + } @end diff --git a/TodoList/TodoList/ListItem.h b/TodoList/TodoList/ListItem.h index 4618f43..35d65f6 100644 --- a/TodoList/TodoList/ListItem.h +++ b/TodoList/TodoList/ListItem.h @@ -11,9 +11,11 @@ @interface ListItem : NSObject -(instancetype)initWithDefaultAndName:(NSString *)name; -@property (nonatomic) NSInteger priority; +@property (nonatomic) int priority; @property (nonatomic) NSString *itemName; @property (nonatomic) BOOL completed; - +@property (nonatomic) int idNumber; +@property (nonatomic) NSDate* date; +@property (nonatomic) BOOL hasDate; @end diff --git a/TodoList/TodoList/ListItem.m b/TodoList/TodoList/ListItem.m index d5e5fdc..317de64 100644 --- a/TodoList/TodoList/ListItem.m +++ b/TodoList/TodoList/ListItem.m @@ -16,6 +16,20 @@ - (instancetype) initWithDefaultAndName:(NSString *)name{ self.priority = 1; self.completed = NO; self.itemName = name; + self.hasDate = NO; + + NSDateComponents *c = [[NSDateComponents alloc]init]; + + [c setDay:30]; + [c setMonth:12]; + [c setYear:3000]; + + NSCalendar *calendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar]; + + NSDate *date = [calendar dateFromComponents:c]; + + self.date = date; + return self; } diff --git a/TodoList/TodoList/ListManager.m b/TodoList/TodoList/ListManager.m index 740b814..f469738 100644 --- a/TodoList/TodoList/ListManager.m +++ b/TodoList/TodoList/ListManager.m @@ -33,7 +33,9 @@ -(void)addList{ printf("\n"); NSString *name = [NSString stringWithCString:temp encoding:NSASCIIStringEncoding]; List *li = [[List alloc] initWithName:name]; - + li.id = 0; + li.viewByDueDate = NO; + li.viewPriority = NO; [_listArray addObject:li]; } From c60160eecb8aca34faa8ba92f73d3d80288ed9dc Mon Sep 17 00:00:00 2001 From: Varindra Date: Mon, 29 Jun 2015 15:39:36 -0400 Subject: [PATCH 17/23] bugfixes --- TodoList/TodoList/List.m | 17 ++++++++--------- TodoList/TodoList/ListItem.m | 2 +- TodoList/TodoList/ListManager.m | 1 + 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m index 57e505f..aeacb61 100644 --- a/TodoList/TodoList/List.m +++ b/TodoList/TodoList/List.m @@ -254,7 +254,7 @@ -(void) run{ continue; } - if([checker isEqualToString:@"d"] || [checker isEqualToString:@"D"]){ + if([checker isEqualToString:@"c"] || [checker isEqualToString:@"C"]){ int d; printf("\nIndex number? "); scanf("%d",&d); @@ -266,7 +266,7 @@ -(void) run{ printf("%s",[c UTF8String]); continue; } - [self deleteItem:d-1]; + [self markCompleted:d-1]; continue; } @@ -313,11 +313,7 @@ -(void) run{ [self active]; continue; } - if([checker isEqualToString:@"t"] || [checker isEqualToString:@"T"]){ - - [self active]; - continue; - } + if([checker isEqualToString:@"i"] || [checker isEqualToString:@"I"]){ @@ -334,16 +330,19 @@ -(void) run{ self.viewPriority=NO; } else{ + self.viewByDueDate = NO; self.viewPriority = YES; } continue; } if([checker isEqualToString:@"vd"] || [checker isEqualToString:@"VD"]){ if(self.viewByDueDate){ - self.viewPriority=NO; + + self.viewByDueDate=NO; } else{ self.viewByDueDate = YES; + self.viewPriority=NO; } continue; } @@ -356,7 +355,7 @@ -(void) printCommands{ printf(" d|delete p|set priority c|mark completed\n"); printf(" t|active i|inactive q|quit\n"); printf("vp|View by priority(ON/OFF) vd|View by date(ON/OFF)\n"); - + printf("\n\n\n\n\n\n\n\n\n"); } @end diff --git a/TodoList/TodoList/ListItem.m b/TodoList/TodoList/ListItem.m index 317de64..84df76b 100644 --- a/TodoList/TodoList/ListItem.m +++ b/TodoList/TodoList/ListItem.m @@ -24,7 +24,7 @@ - (instancetype) initWithDefaultAndName:(NSString *)name{ [c setMonth:12]; [c setYear:3000]; - NSCalendar *calendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar]; + NSCalendar *calendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; NSDate *date = [calendar dateFromComponents:c]; diff --git a/TodoList/TodoList/ListManager.m b/TodoList/TodoList/ListManager.m index f469738..a1e549f 100644 --- a/TodoList/TodoList/ListManager.m +++ b/TodoList/TodoList/ListManager.m @@ -20,6 +20,7 @@ -(void) printCommands{ printf("a|add v|view\n"); printf("d|delete q|quit\n"); + printf("\n\n\n\n\n\n\n"); } -(void)addList{ From 853162149736fdfb36f68a90c72d578e007be59a Mon Sep 17 00:00:00 2001 From: Varindra Date: Wed, 1 Jul 2015 00:19:23 -0400 Subject: [PATCH 18/23] TicTacToe and ToDo list refactoring --- TicTacToe/TicTacToe.xcodeproj/project.pbxproj | 13 + TicTacToe/TicTacToe/DecisionMaker.h | 21 ++ TicTacToe/TicTacToe/DecisionMaker.m | 233 ++++++++++++++++++ TicTacToe/TicTacToe/TwoD.h | 22 ++ TicTacToe/TicTacToe/TwoD.m | 72 ++++++ TicTacToe/TicTacToe/main.m | 4 + TodoList/TodoList/List.h | 3 + TodoList/TodoList/List.m | 106 ++++---- TodoList/TodoList/ListManager.h | 2 + TodoList/TodoList/ListManager.m | 52 ++-- 10 files changed, 452 insertions(+), 76 deletions(-) create mode 100644 TicTacToe/TicTacToe/DecisionMaker.h create mode 100644 TicTacToe/TicTacToe/DecisionMaker.m create mode 100644 TicTacToe/TicTacToe/TwoD.h create mode 100644 TicTacToe/TicTacToe/TwoD.m diff --git a/TicTacToe/TicTacToe.xcodeproj/project.pbxproj b/TicTacToe/TicTacToe.xcodeproj/project.pbxproj index 71ad89c..0a77fdd 100644 --- a/TicTacToe/TicTacToe.xcodeproj/project.pbxproj +++ b/TicTacToe/TicTacToe.xcodeproj/project.pbxproj @@ -8,6 +8,8 @@ /* Begin PBXBuildFile section */ 8D9789E41B3C9A70007CF4CF /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D9789E31B3C9A70007CF4CF /* main.m */; }; + C74DA2BD1B43A04500D7ABEE /* TwoD.m in Sources */ = {isa = PBXBuildFile; fileRef = C74DA2BC1B43A04500D7ABEE /* TwoD.m */; }; + C74DA2C01B43A06500D7ABEE /* DecisionMaker.m in Sources */ = {isa = PBXBuildFile; fileRef = C74DA2BF1B43A06500D7ABEE /* DecisionMaker.m */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -25,6 +27,10 @@ /* Begin PBXFileReference section */ 8D9789E01B3C9A70007CF4CF /* TicTacToe */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = TicTacToe; sourceTree = BUILT_PRODUCTS_DIR; }; 8D9789E31B3C9A70007CF4CF /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + C74DA2BB1B43A04500D7ABEE /* TwoD.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TwoD.h; sourceTree = ""; }; + C74DA2BC1B43A04500D7ABEE /* TwoD.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TwoD.m; sourceTree = ""; }; + C74DA2BE1B43A06500D7ABEE /* DecisionMaker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DecisionMaker.h; sourceTree = ""; }; + C74DA2BF1B43A06500D7ABEE /* DecisionMaker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DecisionMaker.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -58,6 +64,10 @@ isa = PBXGroup; children = ( 8D9789E31B3C9A70007CF4CF /* main.m */, + C74DA2BB1B43A04500D7ABEE /* TwoD.h */, + C74DA2BC1B43A04500D7ABEE /* TwoD.m */, + C74DA2BE1B43A06500D7ABEE /* DecisionMaker.h */, + C74DA2BF1B43A06500D7ABEE /* DecisionMaker.m */, ); path = TicTacToe; sourceTree = ""; @@ -119,6 +129,8 @@ buildActionMask = 2147483647; files = ( 8D9789E41B3C9A70007CF4CF /* main.m in Sources */, + C74DA2BD1B43A04500D7ABEE /* TwoD.m in Sources */, + C74DA2C01B43A06500D7ABEE /* DecisionMaker.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -235,6 +247,7 @@ 8D9789E91B3C9A70007CF4CF /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/TicTacToe/TicTacToe/DecisionMaker.h b/TicTacToe/TicTacToe/DecisionMaker.h new file mode 100644 index 0000000..484f528 --- /dev/null +++ b/TicTacToe/TicTacToe/DecisionMaker.h @@ -0,0 +1,21 @@ +// +// DecisionMaker.h +// TicTacToe +// +// Created by Varindra Hart on 7/1/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import +#import "TwoD.h" + +@interface DecisionMaker : NSObject +@property (nonatomic)TwoD *board; +@property (nonatomic) BOOL twoPlayer; +-(BOOL)checker:(int)winVal; +-(void)makeMove:(int)counter; +-(void)makeBoard; +-(void)printBoard; +-(void)run; +-(BOOL)hasNextMove; +@end diff --git a/TicTacToe/TicTacToe/DecisionMaker.m b/TicTacToe/TicTacToe/DecisionMaker.m new file mode 100644 index 0000000..fb9babe --- /dev/null +++ b/TicTacToe/TicTacToe/DecisionMaker.m @@ -0,0 +1,233 @@ +// +// DecisionMaker.m +// TicTacToe +// +// Created by Varindra Hart on 7/1/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import "DecisionMaker.h" +#import "TwoD.h" +@implementation DecisionMaker{ + int win ; + int lose; +} + +-(BOOL)checker:(int)winVal{ + for (int i=0;i<[self.board count];i++ ) { + if(i==0 || i ==[self.board count]-1){ + if ([self.board diagonalSum:i]==winVal){ + return YES; + } + } + if([self.board rowSum:i]==winVal || [self.board columnSum:i]==winVal){ + return YES; + } + } + return NO; +} + +-(void)makeMove:(int)counter{ + char holder[256]; + if(!self.twoPlayer && counter%2==1){ + printf("Your turn. Enter location seperated by a comma with no spaces: "); + + } + int playerNumber = counter%2==1? 1:2; + if(self.twoPlayer){ + printf("Player %d: Choose a position seperated by a comma (no spaces!): ",playerNumber); + } + if((!self.twoPlayer && counter%2==1) || self.twoPlayer){ + while(YES){ + + scanf("%255[^\n]%*c",holder); + fpurge(stdin); + printf("\n"); + NSString *c = [NSString stringWithCString:holder encoding:NSASCIIStringEncoding]; + for(int i = 0; i<[c length]; i++){ + if(!isdigit([c characterAtIndex:i]) && [c characterAtIndex:i]!=','){ + printf("Invalid position\nTry again: "); + + continue; + } + } + NSArray *parts = [c componentsSeparatedByString:@","]; + if([parts count]!=2){ + printf("Invalid position\nTry again: "); + + continue; + } + for(int i =0; i<[parts count]; i++){ + if([parts[i] intValue]<1 || [parts[i] intValue]>[self.board count]){ + printf("Invalid position\nTry again: "); + continue; + } + } + int row = [parts[0] intValue]-1; + int col = [parts[1] intValue]-1; + NSString *xo = counter%2==1? [NSString stringWithFormat:@"1"]:[NSString stringWithFormat:@"-1"]; + if([[self.board objectAtRow:row column:col] isEqualToString:@"0"]){ + [self.board setObject:xo atRow:row column:col]; + break; + } + else{ + printf("Position already taken\nTry again: "); + continue; + } + } + } + + if(!self.twoPlayer && counter%2==0){ + while(YES){ + int rowPC = arc4random_uniform([self.board count]); + int colPC = arc4random_uniform([self.board count]); + NSString *pcString = @"-1"; + if([[self.board objectAtRow:rowPC column:colPC] isEqualToString:@"0"]){ + [self.board setObject:pcString atRow:rowPC column:colPC]; + break; + } + else{ + continue; + } + } + } +} +-(void)makeBoard{ + int i; + while(YES){ + printf("Board size: "); + scanf("%d",&i); + fpurge(stdin); + if(3<=i && i<=10){ + break; + } + } + TwoD *gameBoard = [[TwoD alloc] initWithRows:i columns:i]; + self.board = gameBoard; + win = [self.board count]; + lose = -1*win; + char singlePlayer[256]; + printf("Two Player? Answering anything other than YES or NO will default to playing the PC: "); + scanf("%255[^\n]%*c",singlePlayer); + NSString *c = [NSString stringWithCString:singlePlayer encoding:NSASCIIStringEncoding]; + if([c isEqualToString:@"YES"]){ + self.twoPlayer=YES; + } + else{ + self.twoPlayer=NO; + } +} + +-(void)printBoard{ + int i = (int)[self.board count]; + NSString *dashed = @""; + for (int l =0; l + +@interface TwoD : NSObject{ +NSMutableArray *Rows; +} +-(instancetype)initWithRows:(int)rows columns:(int)columns; +-(id)objectAtRow:(int)row column:(int)column; +-(void)setObject:(NSString *)object atRow:(int)row column:(int)column; +-(int)count; +-(int)rowSum:(int)rowNumber; +-(int)columnSum:(int)columnNumber; +-(int)diagonalSum:(int)topCorner; + +@end \ No newline at end of file diff --git a/TicTacToe/TicTacToe/TwoD.m b/TicTacToe/TicTacToe/TwoD.m new file mode 100644 index 0000000..35730a9 --- /dev/null +++ b/TicTacToe/TicTacToe/TwoD.m @@ -0,0 +1,72 @@ +// +// TwoD.m +// TicTacToe +// +// Created by Varindra Hart on 7/1/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import "TwoD.h" + + +@implementation TwoD{ + int count; + +} +-(instancetype)initWithRows:(int)rows columns:(int)columns{ + if(self =[self init]){ + Rows = [[NSMutableArray alloc] initWithCapacity:rows]; + for(int i=0; i < columns; i++){ + NSMutableArray *a = [NSMutableArray arrayWithCapacity:columns]; + [Rows insertObject:a atIndex:i]; + for(int j=0; j +#import "DecisionMaker.h" +#import "TwoD.h" int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... NSLog(@"Hello, World!"); + DecisionMaker *c = [[DecisionMaker alloc] init]; + [c run]; } return 0; } diff --git a/TodoList/TodoList/List.h b/TodoList/TodoList/List.h index abc3e38..ea4b6ba 100644 --- a/TodoList/TodoList/List.h +++ b/TodoList/TodoList/List.h @@ -35,4 +35,7 @@ -(void) printByDueDate; -(void) setDate:(int)index; +-(BOOL) outOfBounds:(int)index; +-(int) getIndex; + @end diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m index aeacb61..acc772b 100644 --- a/TodoList/TodoList/List.m +++ b/TodoList/TodoList/List.m @@ -61,14 +61,24 @@ -(void) setDate:(int)index{ fpurge(stdin); NSString *info = [NSString stringWithCString:array encoding:NSASCIIStringEncoding]; - + for(int i = 0; i < [info length]; i++){ + if((!isdigit([info characterAtIndex:i])&& [info characterAtIndex:i]!='/') ||(ispunct([info characterAtIndex:i]) && [info characterAtIndex:i]!='/')){ + printf("\nInvalid date!\n"); + return; + } + } NSArray *parts = [info componentsSeparatedByString:@"/"]; NSDateComponents *c = [[NSDateComponents alloc]init]; - NSInteger a = [parts[0] integerValue]; - NSInteger b = [[parts[1] description] integerValue]; - NSInteger d = [[parts[2] description] integerValue]; + int a = [parts[0] intValue]; + int b = [parts[1] intValue]; + int d = [parts[2] intValue]; + + if((a<1 || a>12) || (b<1 || b>31) || (d<0) || (a==2 && b>28 && d%4!=0) || (a==2 && b>29 && d%4==0) || ((a==4||a==6||a==9||a==11) && b>30) || [parts count]!=3){ + printf("\nInvalid Date!\n"); + return; + } [c setDay:b]; [c setMonth:a]; @@ -82,7 +92,7 @@ -(void) setDate:(int)index{ -(void) printItems{ NSSortDescriptor *sortingMethod = [[NSSortDescriptor alloc] initWithKey:@"idNumber" ascending:YES]; - + [_items sortUsingDescriptors:@[sortingMethod]]; int i =1; for(ListItem *li in _items){ @@ -130,7 +140,7 @@ -(void) printByDueDate{ unsigned unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay; NSCalendar *gregorian = [NSCalendar currentCalendar]; NSDateComponents *component = [gregorian components:unitFlags fromDate:li.date]; - printf("%d. %s |%d/%d/%d\n",i,[li.itemName UTF8String],(int)[component month], (int)[component day], (int)[component year]); + printf("%d. %s | %d/%d/%d\n",i,[li.itemName UTF8String],(int)[component month], (int)[component day], (int)[component year]); } else{ printf("%d. %s\n",i,[li.itemName UTF8String]); @@ -203,6 +213,25 @@ -(void) inActive{ } } +-(BOOL) outOfBounds:(int)index{ + NSInteger arraySize = [_items count]; + if(index < 1 || index > arraySize){ + NSString *c = [NSString stringWithFormat:@"%@",index<1? @"Must be greater than or equal to 1\n":@"out of bounds\n"]; + printf("%s",[c UTF8String]); + return YES; + } + return NO; +} + +-(int) getIndex{ + int d; + printf("\nIndex number? "); + scanf("%d",&d); + fpurge(stdin); + printf("\n"); + return d; +} + -(void) run{ while(YES){ char holder[256]; @@ -223,31 +252,20 @@ -(void) run{ NSString *checker = [NSString stringWithCString:holder encoding:NSASCIIStringEncoding]; if([checker isEqualToString:@"e"] || [checker isEqualToString:@"E"]){ - int d; - printf("\nIndex number? "); - scanf("%d",&d); - fpurge(stdin); - printf("\n"); - NSInteger arraySize = [_items count]; - if(d < 1 || d > arraySize){ - NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1\n":@"out of bounds\n"]; - printf("%s",[c UTF8String]); + int d = [self getIndex]; + + if([self outOfBounds:d]){ continue; } + [self editItem:d-1]; continue; } if([checker isEqualToString:@"d"] || [checker isEqualToString:@"D"]){ - int d; - printf("\nIndex number? "); - scanf("%d",&d); - fpurge(stdin); - printf("\n"); - NSInteger arraySize = [_items count]; - if(d < 1 || d > arraySize){ - NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1\n":@"out of bounds\n"]; - printf("%s",[c UTF8String]); + int d = [self getIndex]; + + if([self outOfBounds:d]){ continue; } [self deleteItem:d-1]; @@ -255,15 +273,9 @@ -(void) run{ } if([checker isEqualToString:@"c"] || [checker isEqualToString:@"C"]){ - int d; - printf("\nIndex number? "); - scanf("%d",&d); - fpurge(stdin); - printf("\n"); - NSInteger arraySize = [_items count]; - if(d < 1 || d > arraySize){ - NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1\n":@"out of bounds\n"]; - printf("%s",[c UTF8String]); + int d = [self getIndex]; + + if([self outOfBounds:d]){ continue; } [self markCompleted:d-1]; @@ -271,15 +283,9 @@ -(void) run{ } if([checker isEqualToString:@"sd"] || [checker isEqualToString:@"SD"]){ - int d; - printf("\nIndex number? "); - scanf("%d",&d); - fpurge(stdin); - printf("\n"); - NSInteger arraySize = [_items count]; - if(d < 1 || d > arraySize){ - NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1\n":@"out of bounds\n"]; - printf("%s",[c UTF8String]); + int d = [self getIndex]; + + if([self outOfBounds:d]){ continue; } [self setDate:d-1]; @@ -287,17 +293,11 @@ -(void) run{ } if([checker isEqualToString:@"p"] || [checker isEqualToString:@"P"]){ - int d; - printf("\nIndex number? "); - scanf("%d",&d); - fpurge(stdin); - NSInteger arraySize = [_items count]; - if(d < 1 || d > arraySize){ - NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1\n":@"out of bounds\n"]; - printf("%s",[c UTF8String]); + int d = [self getIndex]; + + if([self outOfBounds:d]){ continue; } - [self setPriority:d-1]; continue; } @@ -313,7 +313,7 @@ -(void) run{ [self active]; continue; } - + if([checker isEqualToString:@"i"] || [checker isEqualToString:@"I"]){ @@ -354,7 +354,7 @@ -(void) printCommands{ printf(" a|add e|edit sd|set due date\n"); printf(" d|delete p|set priority c|mark completed\n"); printf(" t|active i|inactive q|quit\n"); - printf("vp|View by priority(ON/OFF) vd|View by date(ON/OFF)\n"); + printf("vp|View by priority(ON/OFF) vd|View by date(ON/OFF)\n"); printf("\n\n\n\n\n\n\n\n\n"); } diff --git a/TodoList/TodoList/ListManager.h b/TodoList/TodoList/ListManager.h index 69dddd0..a35e7d7 100644 --- a/TodoList/TodoList/ListManager.h +++ b/TodoList/TodoList/ListManager.h @@ -15,5 +15,7 @@ -(void) deleteList:(int)index; -(void) printLists; -(void) printCommands; +-(BOOL) outOfBounds:(int)index; +-(int) getIndex; @end diff --git a/TodoList/TodoList/ListManager.m b/TodoList/TodoList/ListManager.m index a1e549f..6ce40dd 100644 --- a/TodoList/TodoList/ListManager.m +++ b/TodoList/TodoList/ListManager.m @@ -18,8 +18,8 @@ @implementation ListManager{ -(void) printCommands{ - printf("a|add v|view\n"); - printf("d|delete q|quit\n"); + printf("a|add v|view\n"); + printf("d|delete q|quit\n"); printf("\n\n\n\n\n\n\n"); } @@ -55,6 +55,24 @@ -(void) printLists{ printf("\n"); } +-(BOOL) outOfBounds:(int)index{ + NSInteger arraySize = [_listArray count]; + if(index < 1 || index > arraySize){ + NSString *c = [NSString stringWithFormat:@"%@",index<1? @"Must be greater than or equal to 1\n":@"out of bounds\n"]; + printf("%s",[c UTF8String]); + return YES; + } + return NO; +} + +-(int) getIndex{ + int d; + printf("\nIndex number? "); + scanf("%d",&d); + fpurge(stdin); + printf("\n"); + return d; +} -(void) run{ while(YES){ @@ -66,20 +84,15 @@ -(void) run{ NSString *userString = [NSString stringWithCString:userIn encoding:NSASCIIStringEncoding]; if([userString isEqualToString:@"a"] || [userString isEqualToString:@"A"]){ - + [self addList]; continue; } - + if([userString isEqualToString:@"d"] || [userString isEqualToString:@"D"]){ - int d; - printf("\nList Number? "); - scanf("%d",&d); - fpurge(stdin); - NSInteger arraySize = [_listArray count]; - if(d < 1 || d > arraySize){ - NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1\n":@"out of bounds\n"]; - printf("%s",[c UTF8String]); + int d = [self getIndex]; + + if([self outOfBounds:d]){ continue; } [self deleteList:d-1]; @@ -87,14 +100,9 @@ -(void) run{ } if([userString isEqualToString:@"v"] || [userString isEqualToString:@"V"]){ - int d; - printf("\nIndex number? "); - scanf("%d",&d); - fpurge(stdin); - NSInteger arraySize = [_listArray count]; - if(d < 1 || d > arraySize){ - NSString *c = [NSString stringWithFormat:@"%@",d<1? @"Must be greater than or equal to 1":@"out of bounds"]; - printf("%s",[c UTF8String]); + int d = [self getIndex]; + + if([self outOfBounds:d]){ continue; } List* temp = [_listArray objectAtIndex:d-1] ; @@ -105,9 +113,7 @@ -(void) run{ break; } - - - } } +} @end From fbe578201d199c537b990e8fce8525be2355621a Mon Sep 17 00:00:00 2001 From: Mesfin Date: Wed, 1 Jul 2015 16:42:58 -0400 Subject: [PATCH 19/23] Added the word list to list manager commands --- TicTacToe/TicTacToe/TwoD.m | 2 +- TodoList/TodoList/ListManager.m | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/TicTacToe/TicTacToe/TwoD.m b/TicTacToe/TicTacToe/TwoD.m index 35730a9..9231670 100644 --- a/TicTacToe/TicTacToe/TwoD.m +++ b/TicTacToe/TicTacToe/TwoD.m @@ -14,7 +14,7 @@ @implementation TwoD{ } -(instancetype)initWithRows:(int)rows columns:(int)columns{ - if(self =[self init]){ + if(self = [self init]){ Rows = [[NSMutableArray alloc] initWithCapacity:rows]; for(int i=0; i < columns; i++){ NSMutableArray *a = [NSMutableArray arrayWithCapacity:columns]; diff --git a/TodoList/TodoList/ListManager.m b/TodoList/TodoList/ListManager.m index 6ce40dd..03da3b2 100644 --- a/TodoList/TodoList/ListManager.m +++ b/TodoList/TodoList/ListManager.m @@ -18,8 +18,8 @@ @implementation ListManager{ -(void) printCommands{ - printf("a|add v|view\n"); - printf("d|delete q|quit\n"); + printf("a|Add List v|View List\n"); + printf("d|Delete List q|Quit\n"); printf("\n\n\n\n\n\n\n"); } From 5bd8bf15aa3a61d92693b30acad26712b4b81743 Mon Sep 17 00:00:00 2001 From: Varindra Date: Wed, 1 Jul 2015 22:00:02 -0400 Subject: [PATCH 20/23] edits --- TodoList/TodoList/List.m | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m index acc772b..b6f082a 100644 --- a/TodoList/TodoList/List.m +++ b/TodoList/TodoList/List.m @@ -53,7 +53,7 @@ -(void) markCompleted:(int)index{ -(void) setDate:(int)index{ ListItem *item = [_items objectAtIndex:index]; - item.hasDate = YES; + char array[256]; printf("Enter date mm/dd/yyyy: "); @@ -88,6 +88,7 @@ -(void) setDate:(int)index{ NSDate *date = [calendar dateFromComponents:c]; item.date = date; + item.hasDate = YES; } -(void) printItems{ @@ -184,6 +185,7 @@ -(void) active{ char exitKey[256]; printf("To exit press q: "); scanf("%255[^\n]%*c",exitKey); + fpurge(stdin); NSString *c = [NSString stringWithCString:exitKey encoding:NSASCIIStringEncoding]; if ([c isEqualToString:@"q"] || [c isEqualToString:@"Q"]){ printf("\n\n\n"); @@ -202,9 +204,10 @@ -(void) inActive{ } } while(YES){ - char exitKey[256]; + char exitKey[1]; printf("To exit press q: "); - scanf("%255[^\n]%*c",exitKey); + scanf("%1[^\n]%*c",exitKey); + fpurge(stdin); NSString *c = [NSString stringWithCString:exitKey encoding:NSASCIIStringEncoding]; if ([c isEqualToString:@"q"] || [c isEqualToString:@"Q"]){ printf("\n\n\n"); @@ -248,6 +251,7 @@ -(void) run{ printf("\n:"); scanf("%255[^\n]%*c",holder); fpurge(stdin); + printf("\n"); NSString *checker = [NSString stringWithCString:holder encoding:NSASCIIStringEncoding]; From 9b3768af24368412ba59f0e8916c142622ca4686 Mon Sep 17 00:00:00 2001 From: Varindra Date: Thu, 2 Jul 2015 16:47:58 -0400 Subject: [PATCH 21/23] no bugs..less bugs --- TodoList/TodoList/ListManager.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/TodoList/TodoList/ListManager.m b/TodoList/TodoList/ListManager.m index 03da3b2..3c45918 100644 --- a/TodoList/TodoList/ListManager.m +++ b/TodoList/TodoList/ListManager.m @@ -28,6 +28,7 @@ -(void)addList{ _listArray = [[NSMutableArray alloc]init]; } char temp[256]; + memset(temp, '\0',256); printf("\n Add title of Todo-List: "); scanf("%255[^\n]%*c",temp); fpurge(stdin); @@ -77,10 +78,12 @@ -(int) getIndex{ -(void) run{ while(YES){ char userIn[256]; + memset(userIn, '\0', 256); [self printLists]; [self printCommands]; printf("\n:"); scanf("%255[^\n]%*c",userIn); + fpurge(stdin); NSString *userString = [NSString stringWithCString:userIn encoding:NSASCIIStringEncoding]; if([userString isEqualToString:@"a"] || [userString isEqualToString:@"A"]){ @@ -95,6 +98,7 @@ -(void) run{ if([self outOfBounds:d]){ continue; } + [self deleteList:d-1]; continue; } From 4af0cfdf991cec7ca7a62bfe6c17d6f7bfcfdf01 Mon Sep 17 00:00:00 2001 From: Varindra Date: Thu, 2 Jul 2015 19:02:34 -0400 Subject: [PATCH 22/23] spaced out --- TodoList/TodoList/List.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m index b6f082a..1bd7b06 100644 --- a/TodoList/TodoList/List.m +++ b/TodoList/TodoList/List.m @@ -181,6 +181,7 @@ -(void) active{ i++; } } + printf("\n"); while(YES){ char exitKey[256]; printf("To exit press q: "); @@ -203,6 +204,7 @@ -(void) inActive{ i++; } } + printf("\n"); while(YES){ char exitKey[1]; printf("To exit press q: "); From e9e28061a1fdd17deb4234e85b958337d0771718 Mon Sep 17 00:00:00 2001 From: Varindra Date: Fri, 3 Jul 2015 01:35:54 -0400 Subject: [PATCH 23/23] tictactoe with hard difficulty if user board is size 3 --- TicTacToe/TicTacToe/DecisionMaker.h | 1 + TicTacToe/TicTacToe/DecisionMaker.m | 95 ++++++++++++++++++++++++++++- 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/TicTacToe/TicTacToe/DecisionMaker.h b/TicTacToe/TicTacToe/DecisionMaker.h index 484f528..9141464 100644 --- a/TicTacToe/TicTacToe/DecisionMaker.h +++ b/TicTacToe/TicTacToe/DecisionMaker.h @@ -12,6 +12,7 @@ @interface DecisionMaker : NSObject @property (nonatomic)TwoD *board; @property (nonatomic) BOOL twoPlayer; +@property (nonatomic) BOOL hardMode_ish; -(BOOL)checker:(int)winVal; -(void)makeMove:(int)counter; -(void)makeBoard; diff --git a/TicTacToe/TicTacToe/DecisionMaker.m b/TicTacToe/TicTacToe/DecisionMaker.m index fb9babe..ff1dbc4 100644 --- a/TicTacToe/TicTacToe/DecisionMaker.m +++ b/TicTacToe/TicTacToe/DecisionMaker.m @@ -77,7 +77,7 @@ -(void)makeMove:(int)counter{ } } - if(!self.twoPlayer && counter%2==0){ + if(!self.twoPlayer && counter%2==0 && self.hardMode_ish==NO){ while(YES){ int rowPC = arc4random_uniform([self.board count]); int colPC = arc4random_uniform([self.board count]); @@ -91,6 +91,84 @@ -(void)makeMove:(int)counter{ } } } + + if(!self.twoPlayer && counter%2==0 && self.hardMode_ish==YES){ + while(YES){ + // int rowPC = arc4random_uniform([self.board count]); + // int colPC = arc4random_uniform([self.board count]); + int whichRow=-1; + int whichCol=-1; + int whichDiag=-1; + for(int i= 0; i<3; i++){ + if([self.board rowSum:i]==2){ + whichRow =i; + break; + } + if([self.board columnSum:i]==2){ + whichCol =i; + break; + } + if(i==0 || i==2) { + if([self.board rowSum:i]==2){ + whichRow =i; + break; + } + } + } + + if(whichRow!=-1){ + for(int i= 0; i<3; i++){ + if([[self.board objectAtRow:whichRow column:i] isEqualTo:@"0"]){ + [self.board setObject:@"-1" atRow:whichRow column:i]; + } + } + break; + } + + if(whichCol!=-1){ + for(int i= 0; i<3; i++){ + if([[self.board objectAtRow:i column:whichCol] isEqualToString:@"0"]){ + [self.board setObject:@"-1" atRow:i column:whichCol]; + } + } + break; + } + + if(whichDiag!=-1){ + if(whichDiag==0){ + for(int i= 0; i<3; i++){ + if([[self.board objectAtRow:i column:i] isEqualToString:@"0"]){ + [self.board setObject:@"-1" atRow:i column:i]; + } + } + break; + } + + if(whichDiag==2){ + + for (int i= 0; i < 3; i++) { + if([[self.board objectAtRow:i column:whichDiag] isEqualToString:@"0"]){ + [self.board setObject:@"-1" atRow:i column:whichDiag]; + } + whichDiag--; + } + break; + } + } + + int rowPC = arc4random_uniform([self.board count]); + int colPC = arc4random_uniform([self.board count]); + + NSString *pcString = @"-1"; + if([[self.board objectAtRow:rowPC column:colPC] isEqualToString:@"0"]){ + [self.board setObject:pcString atRow:rowPC column:colPC]; + break; + } + else{ + continue; + } + } + } } -(void)makeBoard{ int i; @@ -116,6 +194,21 @@ -(void)makeBoard{ else{ self.twoPlayer=NO; } + self.hardMode_ish=NO; + + if(i==3){ + printf("hardish mode?\n y/n"); + char answer[256]; + memset(answer,'\0',1); + scanf("%255[^\n]%*c",answer); + fpurge(stdin); + if(answer[0]=='y'){ + self.hardMode_ish=YES; + } + + } + + } -(void)printBoard{