i 在你试图尽可能分得点的场合,我正在尝试制定一份高分清单。 我在这样做时,如果将分数定为2、2、3、4等,就算出你知道的分数。 但是,使用单体字体的计算方法是:
display score code: Code:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [paths objectAtIndex:0];
NSString *path = [documentPath stringByAppendingPathComponent:@"highscore.save"];
NSMutableDictionary* myDict = [[NSMutableDictionary alloc] init];
myDict = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
NSString *nssScore1 = [myDict objectForKey:@"Score1"];
NSString *nssName1 = [myDict objectForKey:@"Name1"];
NSString *nssScore2 = [myDict objectForKey:@"Score2"];
NSString *nssName2 = [myDict objectForKey:@"Name2"];
NSString *nssScore3 = [myDict objectForKey:@"Score3"];
NSString *nssName3 = [myDict objectForKey:@"Name3"];
NSString *nssScore4 = [myDict objectForKey:@"Score4"];
NSString *nssName4 = [myDict objectForKey:@"Name4"];
NSString *nssScore5 = [myDict objectForKey:@"Score5"];
NSString *nssName5 = [myDict objectForKey:@"Name5"];
NSString *nssScore6 = [myDict objectForKey:@"Score6"];
NSString *nssName6 = [myDict objectForKey:@"Name6"];
NSString *nssScore7 = [myDict objectForKey:@"Score7"];
NSString *nssName7 = [myDict objectForKey:@"Name7"];
NSString *nssScore8 = [myDict objectForKey:@"Score8"];
NSString *nssName8 = [myDict objectForKey:@"Name8"];
NSString *nssScore9 = [myDict objectForKey:@"Score9"];
NSString *nssName9 = [myDict objectForKey:@"Name9"];
NSString *nssScore10 = [myDict objectForKey:@"Score10"];
NSString *nssName10 = [myDict objectForKey:@"Name10"];
highestscore = [nssScore1 intValue];
score1i = [nssScore1 intValue];
score2i = [nssScore2 intValue];
score3i = [nssScore3 intValue];
score4i = [nssScore4 intValue];
score5i = [nssScore5 intValue];
score6i = [nssScore6 intValue];
score7i = [nssScore7 intValue];
score8i = [nssScore8 intValue];
score9i = [nssScore9 intValue];
score10i = [nssScore10 intValue];
if(score1i > 0){
NSString *str1 = [NSString stringWithFormat:@"1. %@ | %i points", nssName1, score1i];
score1.text = str1;
} else {
score1.text = @"No Scores available yet";
}
if(score2i > 0){
NSString *str2 = [NSString stringWithFormat:@"2. %@ | %i points", nssName2, score2i];
score2.text = str2;
} else {
[score2 setHidden:1];
}
if(score3i > 0){
NSString *str3 = [NSString stringWithFormat:@"3. %@ | %i points", nssName3, score3i];
score3.text = str3;
} else {
[score3 setHidden:1];
}
if(score4i > 0){
NSString *str4 = [NSString stringWithFormat:@"4. %@ | %i points", nssName4, score4i];
score4.text = str4;
} else {
[score4 setHidden:1];
}
if(score5i > 0){
NSString *str5 = [NSString stringWithFormat:@"5. %@ | %i points", nssName5, score5i];
score5.text = str5;
} else {
[score5 setHidden:1];
}
if(score6i > 0){
NSString *str6 = [NSString stringWithFormat:@"6. %@ | %i points", nssName6, score6i];
score6.text = str6;
} else {
[score6 setHidden:1];
}
if(score7i > 0){
NSString *str7 = [NSString stringWithFormat:@"7. %@ | %i points", nssName7, score7i];
score7.text = str7;
} else {
[score7 setHidden:1];
}
if(score8i > 0){
NSString *str8 = [NSString stringWithFormat:@"8. %@ | %i points", nssName8, score8i];
score8.text = str8;
} else {
[score8 setHidden:1];
}
if(score9i > 0){
NSString *str9 = [NSString stringWithFormat:@"9. %@ | %i points", nssName9, score9i];
score9.text = str9;
} else {
[score9 setHidden:1];
}
if(score10i > 0){
NSString *str10 = [NSString stringWithFormat:@"10. %@ | %i points", nssName10, score10i];
score10.text = str10;
} else {
[score10 setHidden:1];
}
除记分法外:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [paths objectAtIndex:0];
NSString *path = [documentPath stringByAppendingPathComponent:@"highscore.save"];
NSMutableDictionary* myDict1 = [[NSMutableDictionary alloc] init];
myDict1 = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
NSString *nssScore1 = [myDict1 objectForKey:@"Score1"];
NSString *nssName1 = [myDict1 objectForKey:@"Name1"];
NSString *nssScore2 = [myDict1 objectForKey:@"Score2"];
NSString *nssName2 = [myDict1 objectForKey:@"Name2"];
NSString *nssScore3 = [myDict1 objectForKey:@"Score3"];
NSString *nssName3 = [myDict1 objectForKey:@"Name3"];
NSString *nssScore4 = [myDict1 objectForKey:@"Score4"];
NSString *nssName4 = [myDict1 objectForKey:@"Name4"];
NSString *nssScore5 = [myDict1 objectForKey:@"Score5"];
NSString *nssName5 = [myDict1 objectForKey:@"Name5"];
NSString *nssScore6 = [myDict1 objectForKey:@"Score6"];
NSString *nssName6 = [myDict1 objectForKey:@"Name6"];
NSString *nssScore7 = [myDict1 objectForKey:@"Score7"];
NSString *nssName7 = [myDict1 objectForKey:@"Name7"];
NSString *nssScore8 = [myDict1 objectForKey:@"Score8"];
NSString *nssName8 = [myDict1 objectForKey:@"Name8"];
NSString *nssScore9 = [myDict1 objectForKey:@"Score9"];
NSString *nssName9 = [myDict1 objectForKey:@"Name9"];
self.String = textname.text;
NSString *nameString = String;
NSString *nssHighScore = [NSString stringWithFormat:@"%i", highestscore];
NSString *nssIdentifier = [NSString stringWithFormat:@"%@", nameString];
NSMutableDictionary* myDict = [[NSMutableDictionary alloc] init];
[myDict setObject:nssIdentifier forKey:@"Name1"];
[myDict setObject:nssHighScore forKey:@"Score1"];
[myDict setObject:nssName1 forKey:@"Name2"];
[myDict setObject:nssScore1 forKey:@"Score2"];
if(nssScore2 > 0){
[myDict setObject:nssName2 forKey:@"Name3"];
[myDict setObject:nssScore2 forKey:@"Score3"];
}
if(nssScore3 > 0){
[myDict setObject:nssName3 forKey:@"Name4"];
[myDict setObject:nssScore3 forKey:@"Score4"];
}
if(nssScore4 > 0){
[myDict setObject:nssName4 forKey:@"Name5"];
[myDict setObject:nssScore4 forKey:@"Score5"];
}
if(nssScore5 > 0){
[myDict setObject:nssName5 forKey:@"Name6"];
[myDict setObject:nssScore5 forKey:@"Score6"];
}
if(nssScore6 > 0){
[myDict setObject:nssName6 forKey:@"Name7"];
[myDict setObject:nssScore6 forKey:@"Score7"];
}
if(nssScore7 > 0){
[myDict setObject:nssName7 forKey:@"Name8"];
[myDict setObject:nssScore7 forKey:@"Score8"];
}
if(nssScore8 > 0){
[myDict setObject:nssName8 forKey:@"Name9"];
[myDict setObject:nssScore8 forKey:@"Score9"];
}
if(nssScore9 > 0){
[myDict setObject:nssName9 forKey:@"Name10"];
[myDict setObject:nssScore9 forKey:@"Score10"];
}
NSArray *paths1 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath1 = [paths1 objectAtIndex:0];
NSString *path1 = [documentPath1 stringByAppendingPathComponent:@"highscore.save"];
[NSKeyedArchiver archiveRootObject:myDict toFile:path1];
如今,已经拯救了1号高分,取代了原来的第1号,但前一个数字刚刚消失,另一个(3、4、5等)没有显示。 你们能够发现错误或遗漏的东西? 感谢!