From 1161e4255bbb7f53b1a7fa0f134e2f0ea3c777eb Mon Sep 17 00:00:00 2001 From: Peter Luo Date: Sat, 22 Aug 2020 13:17:55 +0800 Subject: [PATCH] Bugfix: Breaklet score board not working --- Breaklet/Breaklet.xcodeproj/project.pbxproj | 8 +++---- ...out.entitlements => Breaklet.entitlements} | 0 Breaklet/Breaklet/Score.swift | 24 ++++++++----------- .../Breaklet/SpriteNodes/ScoreBoardNode.swift | 7 ++++++ 4 files changed, 21 insertions(+), 18 deletions(-) rename Breaklet/Breaklet/{Breakout.entitlements => Breaklet.entitlements} (100%) diff --git a/Breaklet/Breaklet.xcodeproj/project.pbxproj b/Breaklet/Breaklet.xcodeproj/project.pbxproj index ff5eac9..ce58eee 100644 --- a/Breaklet/Breaklet.xcodeproj/project.pbxproj +++ b/Breaklet/Breaklet.xcodeproj/project.pbxproj @@ -40,7 +40,7 @@ B372CBA5247FD15A008DEA68 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; B372CBA8247FD15A008DEA68 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; B372CBAA247FD15A008DEA68 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - B372CBAB247FD15A008DEA68 /* Breakout.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Breakout.entitlements; sourceTree = ""; }; + B372CBAB247FD15A008DEA68 /* Breaklet.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Breaklet.entitlements; sourceTree = ""; }; B372CBB1247FD1FF008DEA68 /* BlockSpriteNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockSpriteNode.swift; sourceTree = ""; }; B372CBB3247FD25C008DEA68 /* NSColorExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSColorExtension.swift; sourceTree = ""; }; B372CBB5247FDB80008DEA68 /* PaddleSpriteNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaddleSpriteNode.swift; sourceTree = ""; }; @@ -99,7 +99,7 @@ B39B4480247FE54C00C35D59 /* SpriteNodes */, B372CBA5247FD15A008DEA68 /* Assets.xcassets */, B372CBAA247FD15A008DEA68 /* Info.plist */, - B372CBAB247FD15A008DEA68 /* Breakout.entitlements */, + B372CBAB247FD15A008DEA68 /* Breaklet.entitlements */, ); path = Breaklet; sourceTree = ""; @@ -335,7 +335,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_ENTITLEMENTS = Breakout/Breakout.entitlements; + CODE_SIGN_ENTITLEMENTS = Breaklet/Breaklet.entitlements; CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; @@ -356,7 +356,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_ENTITLEMENTS = Breakout/Breakout.entitlements; + CODE_SIGN_ENTITLEMENTS = Breaklet/Breaklet.entitlements; CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; diff --git a/Breaklet/Breaklet/Breakout.entitlements b/Breaklet/Breaklet/Breaklet.entitlements similarity index 100% rename from Breaklet/Breaklet/Breakout.entitlements rename to Breaklet/Breaklet/Breaklet.entitlements diff --git a/Breaklet/Breaklet/Score.swift b/Breaklet/Breaklet/Score.swift index fc6bfd5..ef143a0 100644 --- a/Breaklet/Breaklet/Score.swift +++ b/Breaklet/Breaklet/Score.swift @@ -52,25 +52,21 @@ class ScoreBoard: NSObject { } func insert(_ score: Score) { - guard scores.count >= 10 else { + if (score >= scores.last!) || scores.count<=10 { scores.append(score) - return - } - if score >= scores.last! { - scores.append(score) - scores.sort() - scores.removeLast() + scores.sort { (lhs, rhs) -> Bool in + return lhs.value > rhs.value + } + if scores.count > 10 { + scores.removeLast() + } + print(scores) } } func saveToUserDefaults() { - for i in 0..<10 { - guard i < scores.count else { - for indexToRemove in i..<10 { - UserDefaults.standard.removeObject(forKey: "HighScore_\(indexToRemove)") - } - return - } + for i in 0..