#pragma mark-Read cached data
-(void) Getcaches {
Self.maxnum = 0;
SELF.MAXNUM1 = 0;//Max value
Self.score = 0;//Current Score
Self.hisscore = 0;
Self.hisscore1 = 0;//Historical Highest score
Self. SOUNDZT = 1;
Self.twofour = [Nsarray arraywithobjects:@ "2", @ "2", @ "4", @ "2", @ "2", @ "4", @ "2", @ "2", @ "2", @ "2", nil];
Get Data
Self.numbers = [[Nsmutablearray alloc]init];
Self. Scoresarray = [[Nsmutablearray alloc]init];
Self.datearrary = [[Nsmutablearray alloc]init];
if (args = = 2) {//Reset
[[Nsuserdefaults Standarduserdefaults] removeobjectforkey:@ "datadict"];
[[Nsuserdefaults standarduserdefaults] synchronize];
}
Nsdictionary *dict = [[Nsuserdefaults standarduserdefaults] objectforkey:@ "datadict"];
if (dict = = nil) {
Self. Datadict = [Nsmutabledictionary dictionary];
} else {
Self. Datadict = [Nsmutabledictionary dictionarywithdictionary:dict];
Self.numbers = [self. Datadict objectforkey:@ "Numbers"];
NSLog (@ "%@", self.numbers);
Self. Scoresarray = [self. Datadict objectforkey:@ "Scoresarray"];
Self.datearrary = [self. Datadict objectforkey:@ "Datearrary"];
Self.maxnum = [[Self.numbers objectatindex:0] intvalue];
SELF.MAXNUM1 = [[Self.numbers objectatindex:0] intvalue];
Self.hisscore = [[Self.numbers objectatindex:1] intvalue];
Self.hisscore1 = [[Self.numbers objectatindex:1] intvalue];
Self. SOUNDZT = [[Self.numbers objectatindex:2] intvalue];
}
}
#pragma mark-Set gestures
-(void) Setswipegesture {
Uiswipegesturerecognizer * Recoginzer;
Recoginzer = [[Uiswipegesturerecognizer alloc]initwithtarget:self Action: @selector (Handleswipefrom:)];
[Recoginzer Setdirection:uiswipegesturerecognizerdirectionup];
[Self.view Addgesturerecognizer:recoginzer];
Recoginzer = [[Uiswipegesturerecognizer alloc]initwithtarget:self Action: @selector (Handleswipefrom:)];
[Recoginzer Setdirection:uiswipegesturerecognizerdirectiondown];
[Self.view Addgesturerecognizer:recoginzer];
Recoginzer = [[Uiswipegesturerecognizer alloc]initwithtarget:self Action: @selector (Handleswipefrom:)];
[Recoginzer Setdirection:uiswipegesturerecognizerdirectionleft];
[Self.view Addgesturerecognizer:recoginzer];
Recoginzer = [[Uiswipegesturerecognizer alloc]initwithtarget:self Action: @selector (Handleswipefrom:)];
[Recoginzer Setdirection:uiswipegesturerecognizerdirectionright];
[Self.view Addgesturerecognizer:recoginzer];
}
#pragma mark-button button function
-(void) btn
{
if (self. SOUNDZT) {
[Self playSound];
}
Rootviewcontroller * ROOTVC = [[Rootviewcontroller alloc]init];
Rootvc.title = @ "Menu";
Rootvc.delegate = self;
Rootvc.soundzt = self. SOUNDZT;
[Self.navigationcontroller PUSHVIEWCONTROLLER:ROOTVC Animated:yes];
}
#pragma mark-List
-(void) PHB
{
if (self. SOUNDZT) {
[Self playSound];
}
Scoreviewcontroller * SCOREVC = [[Scoreviewcontroller alloc]init];
Scorevc.title = @ "Leaderboard";
Scorevc.array = self. Scoresarray;
Scorevc.datearray = self.datearrary;
[Self.navigationcontroller PUSHVIEWCONTROLLER:SCOREVC Animated:yes];
}
#pragma mark-ranking
-(void) sortscores
{
Date processing
NSDate * date = [NSDate date];
NSDateFormatter * Dateformatter = [[NSDateFormatter alloc]init];
[Dateformatter setdateformat:@ "Yyyy-mm-dd HH:mm:ss"];
NSString * today = [Dateformatter stringfromdate:date];
NSString * temp = [[NSString alloc]init];
if (self. Scoresarray = = nil) {
Self. Scoresarray = [[Nsmutablearray alloc]init];
Self.datearrary = [[Nsmutablearray alloc]init];
}
if ([Self. Scoresarray Count] < 10) {
[Self. Scoresarray addobject:[nsstring stringwithformat:@ "%d", Self.score]];
[Self.datearrary Addobject:today];
}else {
for (int i = 0; i < [self. Scoresarray Count]-1; i++) {
for (int j = i+1 J < [self. Scoresarray Count]; J + +) {
if ([[Self. Scoresarray objectatindex:i] intvalue] > [self. Scoresarray Objectatindex:j] Intvalue]) {
temp = [self. Scoresarray OBJECTATINDEX:I];
[Self. Scoresarray replaceobjectatindex:i withobject:[self. Scoresarray Objectatindex:j]];
[Self. Scoresarray Replaceobjectatindex:j Withobject:temp];
temp = [Self.datearrary objectatindex:i];
[Self.datearrary replaceobjectatindex:i withobject:[self.datearrary Objectatindex:j]];
[Self.datearrary replaceobjectatindex:j withobject:temp];
}
}
}
if (Self.score > [Self. Scoresarray objectatindex:0] Intvalue]) {
[Self. Scoresarray replaceobjectatindex:0 withobject:[nsstring stringwithformat:@ "%d", Self.score]];
[Self.datearrary replaceobjectatindex:0 Withobject:today];
}
}
}
#pragma mark-label gets and set//Get the label value
-(int) Geti: (int) i j: (int) J
{
int value = 0;
Uilabel * LABEL;
if (i = = 0) {
if (j = = 0) {
label = Lab0_0;
}else if (j = = 1) {
label = Lab0_1;
}else if (j = = 2) {
label = Lab0_2;
}else if (j = = 3) {
label = Lab0_3;
}
}else if (i = = 1) {
if (j = = 0) {
label = LAB1_0;
}else if (j = = 1) {
label = Lab1_1;
}else if (j = = 2) {
label = Lab1_2;
}else if (j = = 3) {
label = Lab1_3;
}
}else if (i = = 2) {
if (j = = 0) {
label = LAB2_0;
}else if (j = = 1) {
label = Lab2_1;
}else if (j = = 2) {
label = Lab2_2;
}else if (j = = 3) {
label = Lab2_3;
}
}else if (i = = 3) {
if (j = = 0) {
label = LAB3_0;
}else if (j = = 1) {
label = Lab3_1;
}else if (j = = 2) {
label = Lab3_2;
}else if (j = = 3) {
label = Lab3_3;
}
}
Value = [Label.text intvalue];
return value;
}
#pragma mark-Set the label value
-(void) SETI: (int) i j: (int) J V: (int) value
{
Uilabel * temp = [self getlabeli:i j:j];
if (value!= 0) {
Temp.text = [NSString stringwithformat:@ "%d", value];
}else{
Temp.text = @ "";
}
if (self.maxnum!= 0) {
Self.labMax.text = [NSString stringwithformat:@ "%d", self.maxnum];
}else{
Self.labMax.text = @ "";
}
if (self.score!= 0) {
Self.labScore.text = [NSString stringwithformat:@ "Score \n%d", Self.score];
}else{
Self.labScore.text = @ "score \ n";
}
Self.hisscore = self.score > Self.hisscore?self.score:self.hisscore;
if (self.hisscore!= 0) {
Self.labHisScore.text = [NSString stringwithformat:@ "Historical highest achievement \n%d", Self.hisscore];
}else{
Self.labHisScore.text = @ "Historical Highest score \ n";
}
if ((Self.maxnum > Self.maxnum1 | | | self.hisscore > Self.hisscore1)
&& Self.hisscore!= self.lasthisscore) {
Archive
Self.numbers = [Nsmutablearray arraywithobjects:[nsstring stringwithformat:@ '%d ', self.maxnum],[nsstring stringwithformat:@ "%d", self.hisscore],[nsstring stringwithformat:@ "%d", self. SOUNDZT], nil];
[Self. Datadict setObject:self.numbers forkey:@ "Numbers"];
[[Nsuserdefaults Standarduserdefaults] setobject:self. Datadict forkey:@ "Datadict"];
Self.lasthisscore = Self.hisscore;
}
[Self setbackcolorv:[self geti:i j:j] label:temp];
}
Get label
-(Uilabel *) Getlabeli: (int) i j: (int) J