ここには、1 つのラウンドを完了したときに、スコアがデフォルトのスコア エントリまたは新しく配置されたハイ スコアよりも高い場合、そのデータを自分のデータと交換し、他のすべてを押し下げる機能があります。リストから最後のエントリを削除します。現在、これは 1 つの交換にすぎません。機能のためにハード コードして、後でリファクタリングします。
私の主な問題は、テキスト入力ビューを設定してプレーヤー名をキャプチャすると、プレーヤーが入力せずに実行がすぐに続行され、ゲームがクラッシュすることです。テキストを設定する行をコメントアウトしました。試行が失敗した場合に備えて、デフォルト値が設定されているためです。入力が取られている間、実行を少し待つにはどうすればよいですか? デリゲート メソッドを設定する必要がありますか? もしそうなら、私はまだ代表に少し混乱しています。動作するように設定できましたが、理解できないので、他の特別なカスタム タスクを実行することはできません。私はしばらくそれに取り組みましたが、それ以上はありません...
-(void)saveData:(ScoreKeep *)stats{
NSMutableDictionary *swap = [[NSMutableDictionary alloc]init];//used for swaping entries
NSString *filePath = [self pathOfFile];
NSLog(@"Writing to %@", filePath);
if ([[NSFileManager defaultManager]fileExistsAtPath:filePath]) {
NSLog(@"Loading previous dictionary to save...");
dataDictionary = [NSMutableDictionary dictionaryWithContentsOfFile:filePath];
if ([dataDictionary objectForKey:@"1"]) {
NSMutableDictionary *highScore = [dataDictionary objectForKey:@"1"];
if ([stats.score intValue] > [[highScore objectForKey:@"SCORE"] intValue]) {
NSLog(@"You Win! score: %@ highscore: %@", stats.score,[NSNumber numberWithInt:[[highScore objectForKey:@"SCORE"] intValue]] );
stats = [[ScoreKeep alloc] initWithNibName:@"Scorekeep" bundle:nil];
NSLog(@"Setting up name entry");
[self.view addSubview:stats.view]; //New view is added so that the player can input data(Assume it is complete);
//stats.nameTag = setName.nameTag;//This line is executed before the new view is dismissed causing an error to occur
[stats setupDictionary]; // It just goes down hill from here if the previous line is uncommented
[dataDictionary setObject:stats.sComponents forKey:@"1"];
}else {
NSLog(@"You Lose: %@ highscore: %@", stats.score,[NSNumber numberWithInt:[[highScore objectForKey:@"SCORE"] intValue]] );
}
NSLog(@"Got first place entry");
}else {
NSLog(@"Initilizing Score");
}
}else{
NSLog(@"Creating new dictionary to save...");
dataDictionary = [[NSMutableDictionary alloc]init];
}
[dataDictionary writeToFile:filePath atomically:YES];
}
助けていただければ幸いです。さらに情報が必要な場合は、喜んで提供します。ちなみに、ScoreKeep は、必要な値を設定して sComponents (メインの保存ファイルに入力する辞書) にパッケージ化できるように、辞書と辞書を作成する関数を含むオブジェクトです。
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@class omphalosUtility;
#pragma mark -
#pragma mark Saving data
#pragma mark -
static inline void poop(){
NSLog(@"POOP");
}
アプリとは独立して動作するユーティリティ ファイルを作成して、ファイルを更新し、必要に応じて保存などの他の汎用操作を実行できるようにします。それは私が取りたい方向への一歩です。