diff --git a/AchivementHelper.swift b/AchivementHelper.swift new file mode 100644 index 0000000..7e50d58 --- /dev/null +++ b/AchivementHelper.swift @@ -0,0 +1,346 @@ +// +// AchivementHelper.swift +// OhMyPlane +// +// Created by HS Song on 2016. 4. 25.. +// Copyright © 2016년 softdevstory. All rights reserved. +// + +import Foundation +import GameKit + + +enum Achievement: String { + case RedPlane50 + case RedPlane100 + case RedPlane150 + case RedPlaneBronzeMedal + case RedPlaneSilverMedal + case RedPlaneGoldMedal + case YellowPlane50 + case YellowPlane100 + case YellowPlane150 + case YellowPlaneBronzeMedal + case YellowPlaneSilverMedal + case YellowPlaneGoldMedal + case GreenPlane50 + case GreenPlane100 + case GreenPlane150 + case GreenPlaneBronzeMedal + case GreenPlaneSilverMedal + case GreenPlaneGoldMedal + case BluePlane50 + case BluePlane100 + case BluePlane150 + case BluePlaneBronzeMedal + case BluePlaneSilverMedal + case BluePlaneGoldMedal + case GoldMedal5 + case GoldMedal10 + case GoldMedal15 + case SilverMedal10 + case SilverMedal15 + case SilverMedal20 + case BronzeMedal10 + case BronzeMedal15 + case BronzeMedal20 + case Flight50 + case Flight100 + case Flight150 + case CreditWatch + + private func getPercentage(gameStatistic: GameStatistics, maxValue: Double) -> Double { + let percent: Double = Double(gameStatistic.getValue()) / maxValue + if percent > 1.0 { + return 1.0 + } + + return percent + } + + var gkAchievement: GKAchievement { + let bundleId = NSBundle.mainBundle().bundleIdentifier! + let achievement = GKAchievement(identifier: "\(bundleId).\(self.rawValue)") + + switch self { + case RedPlane50: + achievement.percentComplete = getPercentage(GameStatistics.flightCountRedPlane, maxValue: 50.0) + case RedPlane100: + achievement.percentComplete = getPercentage(GameStatistics.flightCountRedPlane, maxValue: 100.0) + case RedPlane150: + achievement.percentComplete = getPercentage(GameStatistics.flightCountRedPlane, maxValue: 150.0) + + case YellowPlane50: + achievement.percentComplete = getPercentage(GameStatistics.flightCountYellowPlane, maxValue: 50.0) + case YellowPlane100: + achievement.percentComplete = getPercentage(GameStatistics.flightCountYellowPlane, maxValue: 100.0) + case YellowPlane150: + achievement.percentComplete = getPercentage(GameStatistics.flightCountYellowPlane, maxValue: 150.0) + + case GreenPlane50: + achievement.percentComplete = getPercentage(GameStatistics.flightCountGreenPlane, maxValue: 50.0) + case GreenPlane100: + achievement.percentComplete = getPercentage(GameStatistics.flightCountGreenPlane, maxValue: 100.0) + case GreenPlane150: + achievement.percentComplete = getPercentage(GameStatistics.flightCountGreenPlane, maxValue: 150.0) + + case BluePlane50: + achievement.percentComplete = getPercentage(GameStatistics.flightCountBluePlane, maxValue: 50.0) + case BluePlane100: + achievement.percentComplete = getPercentage(GameStatistics.flightCountBluePlane, maxValue: 100.0) + case BluePlane150: + achievement.percentComplete = getPercentage(GameStatistics.flightCountBluePlane, maxValue: 150.0) + + case GoldMedal5: + achievement.percentComplete = getPercentage(GameStatistics.goldMedalCount, maxValue: 5.0) + case GoldMedal10: + achievement.percentComplete = getPercentage(GameStatistics.goldMedalCount, maxValue: 10.0) + case GoldMedal15: + achievement.percentComplete = getPercentage(GameStatistics.goldMedalCount, maxValue: 15.0) + + case SilverMedal10: + achievement.percentComplete = getPercentage(GameStatistics.silverMedalCount, maxValue: 10.0) + case SilverMedal15: + achievement.percentComplete = getPercentage(GameStatistics.silverMedalCount, maxValue: 15.0) + case SilverMedal20: + achievement.percentComplete = getPercentage(GameStatistics.silverMedalCount, maxValue: 20.0) + + case BronzeMedal10: + achievement.percentComplete = getPercentage(GameStatistics.bronzeMedalCount, maxValue: 10.0) + case BronzeMedal15: + achievement.percentComplete = getPercentage(GameStatistics.bronzeMedalCount, maxValue: 15.0) + case BronzeMedal20: + achievement.percentComplete = getPercentage(GameStatistics.bronzeMedalCount, maxValue: 20.0) + + case Flight50: + achievement.percentComplete = getPercentage(GameStatistics.flightCount, maxValue: 50.0) + case Flight100: + achievement.percentComplete = getPercentage(GameStatistics.flightCount, maxValue: 100.0) + case Flight150: + achievement.percentComplete = getPercentage(GameStatistics.flightCount, maxValue: 150.0) + + default: + break + } + + return achievement + } +} + +class AchievementHelper { + static let sharedInstance = AchievementHelper() + + private init() { + // for singleton pattern + } + + func creditWatchAchievement() -> GKAchievement { + let achievement = Achievement.CreditWatch.gkAchievement + + achievement.percentComplete = 100.0 + achievement.showsCompletionBanner = true + + return achievement + } + + func createAchievements(planeType: PlaneType, medalType: Rank) -> [GKAchievement] { + var achievements: [GKAchievement] = [] + + let flight = flightAchievements() + achievements.appendContentsOf(flight) + + let planeFlight = planeFlightAchievements(planeType) + achievements.appendContentsOf(planeFlight) + + if medalType != .None { + let medal = medalAchievements(medalType) + achievements.appendContentsOf(medal) + + if let planeMedal = planeMedalAchievement(planeType, medalType: medalType) { + achievements.append(planeMedal) + } + } + + return achievements + } + + private func planeMedalAchievement(planeType: PlaneType, medalType: Rank) -> GKAchievement? { + var achievement: GKAchievement? = nil + + switch planeType { + case .Red: + switch medalType { + case .Gold: + achievement = Achievement.RedPlaneGoldMedal.gkAchievement + case .Silver: + achievement = Achievement.RedPlaneSilverMedal.gkAchievement + case .Bronze: + achievement = Achievement.RedPlaneBronzeMedal.gkAchievement + default: break + } + + case .Blue: + switch medalType { + case .Gold: + achievement = Achievement.BluePlaneGoldMedal.gkAchievement + case .Silver: + achievement = Achievement.BluePlaneSilverMedal.gkAchievement + case .Bronze: + achievement = Achievement.BluePlaneBronzeMedal.gkAchievement + default: break + } + + case .Green: + switch medalType { + case .Gold: + achievement = Achievement.GreenPlaneGoldMedal.gkAchievement + case .Silver: + achievement = Achievement.GreenPlaneSilverMedal.gkAchievement + case .Bronze: + achievement = Achievement.GreenPlaneBronzeMedal.gkAchievement + default: break + } + + case .Yellow: + switch medalType { + case .Gold: + achievement = Achievement.YellowPlaneGoldMedal.gkAchievement + case .Silver: + achievement = Achievement.YellowPlaneGoldMedal.gkAchievement + case .Bronze: + achievement = Achievement.YellowPlaneGoldMedal.gkAchievement + default: break + } + } + + if achievement != nil { + achievement!.percentComplete = 100.0 + achievement!.showsCompletionBanner = true + } + + return achievement + } + + private func goldMedalAchievements() -> [GKAchievement] { + var achievements: [GKAchievement] = [] + + achievements.append(Achievement.GoldMedal5.gkAchievement) + achievements.append(Achievement.GoldMedal10.gkAchievement) + achievements.append(Achievement.GoldMedal15.gkAchievement) + + return achievements + } + + private func silverMedalAchievements() -> [GKAchievement] { + var achievements: [GKAchievement] = [] + + achievements.append(Achievement.SilverMedal10.gkAchievement) + achievements.append(Achievement.SilverMedal15.gkAchievement) + achievements.append(Achievement.SilverMedal20.gkAchievement) + + return achievements + } + + private func bronzeMedalAchievements() -> [GKAchievement] { + var achievements: [GKAchievement] = [] + + achievements.append(Achievement.BronzeMedal10.gkAchievement) + achievements.append(Achievement.BronzeMedal15.gkAchievement) + achievements.append(Achievement.BronzeMedal20.gkAchievement) + + return achievements + } + + private func medalAchievements(medalType: Rank) -> [GKAchievement] { + var achievements: [GKAchievement] = [] + + guard medalType != .None else { + return achievements + } + + switch medalType { + case .Gold: + achievements.appendContentsOf(goldMedalAchievements()) + + case .Silver: + achievements.appendContentsOf(silverMedalAchievements()) + + case .Bronze: + achievements.appendContentsOf(bronzeMedalAchievements()) + + default: break + } + + return achievements + } + + private func flightAchievements() -> [GKAchievement] { + var achievements: [GKAchievement] = [] + + achievements.append(Achievement.Flight50.gkAchievement) + achievements.append(Achievement.Flight100.gkAchievement) + achievements.append(Achievement.Flight150.gkAchievement) + + return achievements + } + + private func redPlaneFlightAchievements() -> [GKAchievement] { + var achievements: [GKAchievement] = [] + + achievements.append(Achievement.RedPlane50.gkAchievement) + achievements.append(Achievement.RedPlane100.gkAchievement) + achievements.append(Achievement.RedPlane150.gkAchievement) + + return achievements + } + + private func bluePlaneFlightAchievements() -> [GKAchievement] { + var achievements: [GKAchievement] = [] + + achievements.append(Achievement.BluePlane50.gkAchievement) + achievements.append(Achievement.BluePlane100.gkAchievement) + achievements.append(Achievement.BluePlane150.gkAchievement) + + return achievements + } + + private func yellowPlaneFlightAchievements() -> [GKAchievement] { + var achievements: [GKAchievement] = [] + + achievements.append(Achievement.YellowPlane50.gkAchievement) + achievements.append(Achievement.YellowPlane100.gkAchievement) + achievements.append(Achievement.YellowPlane150.gkAchievement) + + return achievements + } + + private func greenPlaneFlightAchievements() -> [GKAchievement] { + var achievements: [GKAchievement] = [] + + achievements.append(Achievement.GreenPlane50.gkAchievement) + achievements.append(Achievement.GreenPlane100.gkAchievement) + achievements.append(Achievement.GreenPlane150.gkAchievement) + + return achievements + } + + private func planeFlightAchievements(planeType: PlaneType) -> [GKAchievement] { + var achievements: [GKAchievement] = [] + + switch planeType { + case .Red: + achievements.appendContentsOf(redPlaneFlightAchievements()) + + case .Blue: + achievements.appendContentsOf(bluePlaneFlightAchievements()) + + case .Yellow: + achievements.appendContentsOf(redPlaneFlightAchievements()) + + case .Green: + achievements.appendContentsOf(redPlaneFlightAchievements()) + } + + return achievements + } +} diff --git a/GameKitHelper.swift b/GameKitHelper.swift new file mode 100644 index 0000000..03ab5e7 --- /dev/null +++ b/GameKitHelper.swift @@ -0,0 +1,75 @@ +// +// GameKitHelper.swift +// OhMyPlane +// +// Created by HS Song on 2016. 4. 25.. +// Copyright © 2016년 softdevstory. All rights reserved. +// + +import Foundation +import UIKit +import GameKit + +let PresentAuthenticationViewController = "PresentAuthenticationViewController" +let PresentGameCenterViewController = "PresentGameCenterViewController" + +class GameKitHelper: NSObject { + static let sharedInstance = GameKitHelper() + + private override init() { + super.init() + } + + var authenticationViewController: UIViewController? + var gameCenterEnabled = false + + func authenticateLocalPlayer() { + let localPlayer = GKLocalPlayer() + localPlayer.authenticateHandler = { (viewController, error) in + if viewController != nil { + self.authenticationViewController = viewController + + NSNotificationCenter.defaultCenter().postNotificationName(PresentAuthenticationViewController, object: self) + } else if error == nil { + self.gameCenterEnabled = true + } else { + print("Game center error: \(error)") + } + } + } + + func showGKGameCenterViewController(viewController: UIViewController) { + guard gameCenterEnabled else { + return + } + + let gameCenterViewController = GKGameCenterViewController() + + gameCenterViewController.gameCenterDelegate = self + + viewController.presentViewController(gameCenterViewController, animated: true, completion: nil) + } + + func reportAchievements(achievements: [GKAchievement], errorHandler: ((NSError?) -> Void)? = nil) { + guard gameCenterEnabled else { + return + } + + GKAchievement.reportAchievements(achievements, withCompletionHandler: errorHandler) + } + + func reportScore(gkScore: GKScore, errorHandler: ((NSError?)->Void)? = nil) { + guard gameCenterEnabled else { + return + } + + GKScore.reportScores([gkScore], withCompletionHandler: errorHandler) + } +} + + +extension GameKitHelper: GKGameCenterControllerDelegate { + func gameCenterViewControllerDidFinish(gameCenterViewController: GKGameCenterViewController) { + gameCenterViewController.dismissViewControllerAnimated(true, completion: nil) + } +} \ No newline at end of file diff --git a/GameStatistics.swift b/GameStatistics.swift new file mode 100644 index 0000000..0e19b4d --- /dev/null +++ b/GameStatistics.swift @@ -0,0 +1,35 @@ +// +// GameStatistics.swift +// OhMyPlane +// +// Created by HS Song on 2016. 4. 27.. +// Copyright © 2016년 softdevstory. All rights reserved. +// + +import Foundation + +enum GameStatistics: String { + + case flightCountRedPlane + case flightCountYellowPlane + case flightCountGreenPlane + case flightCountBluePlane + case goldMedalCount + case silverMedalCount + case bronzeMedalCount + case flightCount + + func getValue() -> Int { + return NSUserDefaults.standardUserDefaults().integerForKey(self.rawValue) + } + + private func setValue(value: Int) { + NSUserDefaults.standardUserDefaults().setInteger(value, forKey: self.rawValue) + print("\(self.rawValue) value: \(value)") + } + + func increaseCountByOne() { + let value = self.getValue() + 1 + self.setValue(value) + } +} \ No newline at end of file diff --git a/LeaderBoardHelper.swift b/LeaderBoardHelper.swift new file mode 100644 index 0000000..ab824c2 --- /dev/null +++ b/LeaderBoardHelper.swift @@ -0,0 +1,49 @@ +// +// LeaderBoardHelper.swift +// OhMyPlane +// +// Created by HS Song on 2016. 4. 28.. +// Copyright © 2016년 softdevstory. All rights reserved. +// + +import Foundation +import GameKit + +enum LeaderBoard: String { + case RedPlaneHighScore + case BluePlaneHighScore + case YellowPlaneHighScore + case GreenPlaneHighScore + + var gkScore: GKScore { + let bundleId = NSBundle.mainBundle().bundleIdentifier! + return GKScore(leaderboardIdentifier: "\(bundleId).\(self.rawValue)") + } +} + +class LeaderBoardHelper { + static let sharedInstance = LeaderBoardHelper() + + private init() { + // for singleton pattern + } + + func createScore(planeType: PlaneType, score: Int) -> GKScore { + var gkScore: GKScore! + + switch planeType { + case .Red: + gkScore = LeaderBoard.RedPlaneHighScore.gkScore + case .Yellow: + gkScore = LeaderBoard.YellowPlaneHighScore.gkScore + case .Blue: + gkScore = LeaderBoard.BluePlaneHighScore.gkScore + case .Green: + gkScore = LeaderBoard.GreenPlaneHighScore.gkScore + } + + gkScore.value = Int64(score) + + return gkScore + } +} \ No newline at end of file diff --git a/OhMyPlane.xcodeproj/project.pbxproj b/OhMyPlane.xcodeproj/project.pbxproj index 80ddf08..c939ef4 100644 --- a/OhMyPlane.xcodeproj/project.pbxproj +++ b/OhMyPlane.xcodeproj/project.pbxproj @@ -8,6 +8,10 @@ /* Begin PBXBuildFile section */ A427556C1CBE332600EB0E50 /* GameScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = A496E8E01CA228C800A448F5 /* GameScene.swift */; }; + A42DE6611CCDD8F80088AD76 /* GameKitHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A42DE6601CCDD8F80088AD76 /* GameKitHelper.swift */; }; + A42DE6621CCDD8F80088AD76 /* GameKitHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A42DE6601CCDD8F80088AD76 /* GameKitHelper.swift */; }; + A42DE6651CCE11970088AD76 /* AchivementHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A42DE6641CCE11970088AD76 /* AchivementHelper.swift */; }; + A42DE6671CCF51320088AD76 /* GameKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A42DE6661CCF51320088AD76 /* GameKit.framework */; }; A435C0601CBF4628002EFCCF /* SKTUtils.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A435C05E1CBF45D3002EFCCF /* SKTUtils.framework */; }; A435C0621CBF61DF002EFCCF /* TVControlsScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = A435C0611CBF61DF002EFCCF /* TVControlsScene.swift */; }; A435C0631CBF61DF002EFCCF /* TVControlsScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = A435C0611CBF61DF002EFCCF /* TVControlsScene.swift */; }; @@ -23,6 +27,7 @@ A43735E41CA43F15005F5BC1 /* obstacle.atlas in Resources */ = {isa = PBXBuildFile; fileRef = A43735E31CA43F15005F5BC1 /* obstacle.atlas */; }; A43735E61CA51BA3005F5BC1 /* PauseGame.swift in Sources */ = {isa = PBXBuildFile; fileRef = A43735E51CA51BA3005F5BC1 /* PauseGame.swift */; }; A43735EA1CA51BC8005F5BC1 /* FailGame.swift in Sources */ = {isa = PBXBuildFile; fileRef = A43735E91CA51BC8005F5BC1 /* FailGame.swift */; }; + A46711BD1CC8BC3D005A0E6A /* GameKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A46711BC1CC8BC3D005A0E6A /* GameKit.framework */; }; A48DA0161CBE222B000DCCED /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A48DA0151CBE222B000DCCED /* AppDelegate.swift */; }; A48DA01C1CBE222B000DCCED /* GameViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A48DA01B1CBE222B000DCCED /* GameViewController.swift */; }; A48DA0211CBE222B000DCCED /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A48DA01F1CBE222B000DCCED /* Main.storyboard */; }; @@ -60,6 +65,11 @@ A48DA0671CBE2A7A000DCCED /* spark.png in Resources */ = {isa = PBXBuildFile; fileRef = A496E9091CA2853E00A448F5 /* spark.png */; }; A48DA0691CBE2AD7000DCCED /* ShareAssets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A48DA0681CBE2AD7000DCCED /* ShareAssets.xcassets */; }; A48DA06A1CBE2AD7000DCCED /* ShareAssets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A48DA0681CBE2AD7000DCCED /* ShareAssets.xcassets */; }; + A490077C1CD09E6A0046DAC8 /* GameStatistics.swift in Sources */ = {isa = PBXBuildFile; fileRef = A490077B1CD09E6A0046DAC8 /* GameStatistics.swift */; }; + A490077E1CD1ED860046DAC8 /* LeaderBoardHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A490077D1CD1ED860046DAC8 /* LeaderBoardHelper.swift */; }; + A490077F1CD300AF0046DAC8 /* LeaderBoardHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A490077D1CD1ED860046DAC8 /* LeaderBoardHelper.swift */; }; + A49007801CD300B20046DAC8 /* AchivementHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A42DE6641CCE11970088AD76 /* AchivementHelper.swift */; }; + A49007811CD300B60046DAC8 /* GameStatistics.swift in Sources */ = {isa = PBXBuildFile; fileRef = A490077B1CD09E6A0046DAC8 /* GameStatistics.swift */; }; A496E8DD1CA228C800A448F5 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A496E8DC1CA228C800A448F5 /* AppDelegate.swift */; }; A496E8E11CA228C800A448F5 /* GameScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = A496E8E01CA228C800A448F5 /* GameScene.swift */; }; A496E8E31CA228C800A448F5 /* GameViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A496E8E21CA228C800A448F5 /* GameViewController.swift */; }; @@ -93,6 +103,9 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + A42DE6601CCDD8F80088AD76 /* GameKitHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GameKitHelper.swift; sourceTree = ""; }; + A42DE6641CCE11970088AD76 /* AchivementHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AchivementHelper.swift; sourceTree = ""; }; + A42DE6661CCF51320088AD76 /* GameKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GameKit.framework; path = System/Library/Frameworks/GameKit.framework; sourceTree = SDKROOT; }; A435C05E1CBF45D3002EFCCF /* SKTUtils.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SKTUtils.framework; path = ../Carthage/Build/tvOS/SKTUtils.framework; sourceTree = ""; }; A435C0611CBF61DF002EFCCF /* TVControlsScene.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TVControlsScene.swift; sourceTree = ""; }; A435C0651CBF6248002EFCCF /* GameScene+TVControlsScene.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "GameScene+TVControlsScene.swift"; sourceTree = ""; }; @@ -107,6 +120,7 @@ A43735E31CA43F15005F5BC1 /* obstacle.atlas */ = {isa = PBXFileReference; lastKnownFileType = folder.skatlas; name = obstacle.atlas; path = ../Shared/obstacle.atlas; sourceTree = ""; }; A43735E51CA51BA3005F5BC1 /* PauseGame.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; name = PauseGame.swift; path = ../Shared/PauseGame.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; A43735E91CA51BC8005F5BC1 /* FailGame.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; name = FailGame.swift; path = ../Shared/FailGame.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; + A46711BC1CC8BC3D005A0E6A /* GameKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GameKit.framework; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS9.2.sdk/System/Library/Frameworks/GameKit.framework; sourceTree = DEVELOPER_DIR; }; A48DA0131CBE222B000DCCED /* OhMyPlaneTv.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OhMyPlaneTv.app; sourceTree = BUILT_PRODUCTS_DIR; }; A48DA0151CBE222B000DCCED /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; A48DA01B1CBE222B000DCCED /* GameViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameViewController.swift; sourceTree = ""; }; @@ -114,6 +128,8 @@ A48DA0221CBE222B000DCCED /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; A48DA0241CBE222B000DCCED /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; A48DA0681CBE2AD7000DCCED /* ShareAssets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = ShareAssets.xcassets; path = ../Shared/ShareAssets.xcassets; sourceTree = ""; }; + A490077B1CD09E6A0046DAC8 /* GameStatistics.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GameStatistics.swift; sourceTree = ""; }; + A490077D1CD1ED860046DAC8 /* LeaderBoardHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LeaderBoardHelper.swift; sourceTree = ""; }; A496E8D91CA228C800A448F5 /* OhMyPlane.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OhMyPlane.app; sourceTree = BUILT_PRODUCTS_DIR; }; A496E8DC1CA228C800A448F5 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = AppDelegate.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; A496E8E01CA228C800A448F5 /* GameScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; lineEnding = 0; name = GameScene.swift; path = ../Shared/GameScene.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; @@ -154,6 +170,7 @@ buildActionMask = 2147483647; files = ( A435C0601CBF4628002EFCCF /* SKTUtils.framework in Frameworks */, + A46711BD1CC8BC3D005A0E6A /* GameKit.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -162,12 +179,24 @@ buildActionMask = 2147483647; files = ( A4D1BF481CB77895001B455A /* SKTUtils.framework in Frameworks */, + A42DE6671CCF51320088AD76 /* GameKit.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + A42DE6631CCE117C0088AD76 /* GameCenter */ = { + isa = PBXGroup; + children = ( + A42DE6601CCDD8F80088AD76 /* GameKitHelper.swift */, + A490077D1CD1ED860046DAC8 /* LeaderBoardHelper.swift */, + A42DE6641CCE11970088AD76 /* AchivementHelper.swift */, + A490077B1CD09E6A0046DAC8 /* GameStatistics.swift */, + ); + name = GameCenter; + sourceTree = ""; + }; A435C0641CBF620D002EFCCF /* extensionsForTvOS */ = { isa = PBXGroup; children = ( @@ -217,6 +246,7 @@ A48DA0281CBE2261000DCCED /* Share */ = { isa = PBXGroup; children = ( + A42DE6631CCE117C0088AD76 /* GameCenter */, A496E9001CA2782D00A448F5 /* GameSetting.swift */, A4C08B2B1CB258C800FD8DAE /* TopThreeRecords.swift */, A4C08B211CAE1EB600FD8DAE /* Scenes */, @@ -228,6 +258,8 @@ A496E8D01CA228C800A448F5 = { isa = PBXGroup; children = ( + A42DE6661CCF51320088AD76 /* GameKit.framework */, + A46711BC1CC8BC3D005A0E6A /* GameKit.framework */, A48DA0281CBE2261000DCCED /* Share */, A496E8DB1CA228C800A448F5 /* OhMyPlane */, A48DA0141CBE222B000DCCED /* OhMyPlaneTv */, @@ -393,10 +425,20 @@ A48DA0121CBE222B000DCCED = { CreatedOnToolsVersion = 7.3; DevelopmentTeam = MGW797GVB2; + SystemCapabilities = { + com.apple.GameCenter = { + enabled = 1; + }; + }; }; A496E8D81CA228C800A448F5 = { CreatedOnToolsVersion = 7.3; DevelopmentTeam = MGW797GVB2; + SystemCapabilities = { + com.apple.GameCenter = { + enabled = 1; + }; + }; }; }; }; @@ -510,9 +552,11 @@ buildActionMask = 2147483647; files = ( A435C0631CBF61DF002EFCCF /* TVControlsScene.swift in Sources */, + A49007811CD300B60046DAC8 /* GameStatistics.swift in Sources */, A435C0681CBF62AE002EFCCF /* MainScene+TVControlsScene.swift in Sources */, A48DA04E1CBE2A2F000DCCED /* ReadyGame.swift in Sources */, A48DA04F1CBE2A2F000DCCED /* PlayGame.swift in Sources */, + A490077F1CD300AF0046DAC8 /* LeaderBoardHelper.swift in Sources */, A48DA0481CBE2A1C000DCCED /* TopThreeRecords.swift in Sources */, A48DA0471CBE2A19000DCCED /* GameSetting.swift in Sources */, A48DA0581CBE2A40000DCCED /* TopRecordsScene.swift in Sources */, @@ -521,6 +565,7 @@ A48DA04A1CBE2A23000DCCED /* AnimationComponent.swift in Sources */, A48DA0531CBE2A37000DCCED /* Broken.swift in Sources */, A48DA04D1CBE2A2A000DCCED /* RockEntity.swift in Sources */, + A49007801CD300B20046DAC8 /* AchivementHelper.swift in Sources */, A435C06A1CBF713A002EFCCF /* CreditScene+TVControlsScene.swift in Sources */, A427556C1CBE332600EB0E50 /* GameScene.swift in Sources */, A48DA04B1CBE2A23000DCCED /* PlaneMovementComponent.swift in Sources */, @@ -529,6 +574,7 @@ A48DA0161CBE222B000DCCED /* AppDelegate.swift in Sources */, A48DA0501CBE2A2F000DCCED /* PauseGame.swift in Sources */, A435C0661CBF6248002EFCCF /* GameScene+TVControlsScene.swift in Sources */, + A42DE6621CCDD8F80088AD76 /* GameKitHelper.swift in Sources */, A48DA04C1CBE2A2A000DCCED /* PlaneEntity.swift in Sources */, A48DA0511CBE2A2F000DCCED /* FailGame.swift in Sources */, A435C06C1CBF7264002EFCCF /* TopRecordsScene+TVControlsScene.swift in Sources */, @@ -541,6 +587,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + A42DE6611CCDD8F80088AD76 /* GameKitHelper.swift in Sources */, A435C0621CBF61DF002EFCCF /* TVControlsScene.swift in Sources */, A43735DA1CA4244E005F5BC1 /* Normal.swift in Sources */, A496E8FC1CA25E0E00A448F5 /* AnimationComponent.swift in Sources */, @@ -551,6 +598,7 @@ A4C08B301CB3A10D00FD8DAE /* TopRecordsScene.swift in Sources */, A496E8F41CA23DBB00A448F5 /* SpriteComponent.swift in Sources */, A43735DC1CA42455005F5BC1 /* Broken.swift in Sources */, + A490077E1CD1ED860046DAC8 /* LeaderBoardHelper.swift in Sources */, A4C08B2C1CB258C800FD8DAE /* TopThreeRecords.swift in Sources */, A496E9011CA2782D00A448F5 /* GameSetting.swift in Sources */, A43735D51CA3D9F9005F5BC1 /* RockEntity.swift in Sources */, @@ -559,6 +607,8 @@ A496E8FF1CA2763100A448F5 /* PlaneMovementComponent.swift in Sources */, A496E9071CA2823100A448F5 /* ReadyGame.swift in Sources */, A496E8DD1CA228C800A448F5 /* AppDelegate.swift in Sources */, + A42DE6651CCE11970088AD76 /* AchivementHelper.swift in Sources */, + A490077C1CD09E6A0046DAC8 /* GameStatistics.swift in Sources */, A4C08B231CAE1F2700FD8DAE /* MainScene.swift in Sources */, A43735E61CA51BA3005F5BC1 /* PauseGame.swift in Sources */, A43735DE1CA4245F005F5BC1 /* Crash.swift in Sources */, diff --git a/OhMyPlane/GameViewController.swift b/OhMyPlane/GameViewController.swift index a827571..0789e9d 100644 --- a/OhMyPlane/GameViewController.swift +++ b/OhMyPlane/GameViewController.swift @@ -29,6 +29,27 @@ class GameViewController: UIViewController { scene.scaleMode = .AspectFill skView.presentScene(scene) + + NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(GameViewController.showAuthenticationViewController), name: PresentAuthenticationViewController, object: nil) + + NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(GameViewController.showGameCenterViewController), name: PresentGameCenterViewController, object: nil) + + GameKitHelper.sharedInstance.authenticateLocalPlayer() + } + + func showAuthenticationViewController() { + let gameKitHelper = GameKitHelper.sharedInstance + if let authenticationViewController = gameKitHelper.authenticationViewController { + presentViewController(authenticationViewController, animated: true, completion: nil) + } + } + + func showGameCenterViewController() { + GameKitHelper.sharedInstance.showGKGameCenterViewController(self) + } + + deinit { + NSNotificationCenter.defaultCenter().removeObserver(self) } override func shouldAutorotate() -> Bool { diff --git a/OhMyPlane/Info.plist b/OhMyPlane/Info.plist index 538b846..49c746d 100644 --- a/OhMyPlane/Info.plist +++ b/OhMyPlane/Info.plist @@ -15,11 +15,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.1 + 1.2 CFBundleSignature ???? CFBundleVersion - 7 + 3 ITSAppUsesNonExemptEncryption LSRequiresIPhoneOS @@ -35,6 +35,7 @@ UIRequiredDeviceCapabilities armv7 + gamekit UIRequiresFullScreen diff --git a/OhMyPlane/TopRecordsScene+TVControlsScene.swift b/OhMyPlane/TopRecordsScene+TVControlsScene.swift index 86687b7..63c5281 100644 --- a/OhMyPlane/TopRecordsScene+TVControlsScene.swift +++ b/OhMyPlane/TopRecordsScene+TVControlsScene.swift @@ -8,12 +8,30 @@ import SpriteKit +private var activeNodes: [SKNode] = [] +private var currentNodeIndex = 0 + private let fadeOut = SKAction.fadeAlphaTo(0.5, duration: 0.5) private let fadeIn = SKAction.fadeAlphaTo(1.0, duration: 0.5) extension TopRecordsScene: TVControlsScene { func setupTVControls() { - backSprite.runAction(SKAction.repeatActionForever(SKAction.sequence([fadeOut, fadeIn]))) + let swipeLeft = UISwipeGestureRecognizer(target: self, action: #selector(MainScene.didSwipeOnRemote(_:))) + swipeLeft.direction = .Left + swipeLeft.delaysTouchesBegan = true + view!.addGestureRecognizer(swipeLeft) + + let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(MainScene.didSwipeOnRemote(_:))) + swipeRight.direction = .Right + swipeRight.delaysTouchesBegan = true + view!.addGestureRecognizer(swipeRight) + + activeNodes = [] + + activeNodes.append(backSprite) + activeNodes.append(gameCenterSprite) + + selectNodeAtIndex(0) } func touchOnRemoteBegan() { @@ -24,11 +42,48 @@ extension TopRecordsScene: TVControlsScene { // nothing to do } + func didSwipeOnRemote(swipe: UISwipeGestureRecognizer) { + var newIndexToSelect = currentNodeIndex + if swipe.direction == .Right { + newIndexToSelect += 1 + } else { + newIndexToSelect -= 1 + } + + if newIndexToSelect < 0 { + newIndexToSelect = activeNodes.count - 1 + } else if newIndexToSelect > activeNodes.count - 1 { + newIndexToSelect = 0 + } + + selectNodeAtIndex(newIndexToSelect) + } + + func selectNodeAtIndex(index: Int) { + activeNodes[index].runAction(SKAction.repeatActionForever(SKAction.sequence([fadeOut, fadeIn]))) + + if currentNodeIndex < activeNodes.count && index != currentNodeIndex, let node = activeNodes[currentNodeIndex] as? SKSpriteNode { + node.removeAllActions() + node.alpha = 1.0 + } + + currentNodeIndex = index + } + override func pressesBegan(presses: Set, withEvent event: UIPressesEvent?) { for press in presses { switch press.type { case .Select: - touchDownBack() + let node = activeNodes[currentNodeIndex] as! SKSpriteNode + + switch node { + case backSprite: + touchDownBack() + case gameCenterSprite: + touchDownGameCenter() + default: + break + } case .Menu: touchDownBack() @@ -43,5 +98,9 @@ extension TopRecordsScene: TVControlsScene { if backPressed { doBack() } + + if gameCenterPressed { + showGameCenterViewController() + } } } diff --git a/OhMyPlaneTv/GameViewController.swift b/OhMyPlaneTv/GameViewController.swift index bc82fba..1d6a660 100644 --- a/OhMyPlaneTv/GameViewController.swift +++ b/OhMyPlaneTv/GameViewController.swift @@ -28,6 +28,13 @@ class GameViewController: UIViewController { scene.scaleMode = .AspectFill skView.presentScene(scene) + + NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(GameViewController.showAuthenticationViewController), name: PresentAuthenticationViewController, object: nil) + + NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(GameViewController.showGameCenterViewController), name: PresentGameCenterViewController, object: nil) + + GameKitHelper.sharedInstance.authenticateLocalPlayer() + } override func didReceiveMemoryWarning() { @@ -66,4 +73,15 @@ class GameViewController: UIViewController { scene.pressesEnded(presses, withEvent: event) } + + func showAuthenticationViewController() { + let gameKitHelper = GameKitHelper.sharedInstance + if let authenticationViewController = gameKitHelper.authenticationViewController { + presentViewController(authenticationViewController, animated: true, completion: nil) + } + } + + func showGameCenterViewController() { + GameKitHelper.sharedInstance.showGKGameCenterViewController(self) + } } diff --git a/OhMyPlaneTv/Info.plist b/OhMyPlaneTv/Info.plist index db01328..a163e2c 100644 --- a/OhMyPlaneTv/Info.plist +++ b/OhMyPlaneTv/Info.plist @@ -15,11 +15,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.1 + 1.2 CFBundleSignature ???? CFBundleVersion - 7 + 3 ITSAppUsesNonExemptEncryption LSRequiresIPhoneOS @@ -29,6 +29,7 @@ UIRequiredDeviceCapabilities arm64 + gamekit diff --git a/Shared/CreditScene.swift b/Shared/CreditScene.swift index e733c70..2826c1f 100644 --- a/Shared/CreditScene.swift +++ b/Shared/CreditScene.swift @@ -166,7 +166,11 @@ class CreditScene: SKScene { position.y -= label.fontSize } - creditLayer.runAction(SKAction.moveBy(CGVectorMake(0, -position.y * 2 + overlapAmount()), duration: 32.0)) + creditLayer.runAction(SKAction.moveBy(CGVectorMake(0, -position.y * 2 + overlapAmount()), duration: 32.0)) { + let achievement = AchievementHelper.sharedInstance.creditWatchAchievement() + + GameKitHelper.sharedInstance.reportAchievements([achievement]) + } } func loadCreditLabels() { diff --git a/Shared/FailGame.swift b/Shared/FailGame.swift index 0c40517..ba9c0f1 100644 --- a/Shared/FailGame.swift +++ b/Shared/FailGame.swift @@ -30,8 +30,4 @@ class FailGame: GKState { override func willExitWithNextState(nextState: GKState) { scene.hideGameOver() } - - override func updateWithDeltaTime(seconds: NSTimeInterval) { - - } } diff --git a/Shared/GameScene.swift b/Shared/GameScene.swift index dca0c5c..ede4f74 100644 --- a/Shared/GameScene.swift +++ b/Shared/GameScene.swift @@ -227,26 +227,26 @@ class GameScene: SKScene, SKPhysicsContactDelegate { var medalNodes: [Rank: SKSpriteNode] = [:] private func prepareMedalNodes() { - let goldMedal = SKSpriteNode(imageNamed: Rank.First.imageFileName!) + let goldMedal = SKSpriteNode(imageNamed: Rank.Gold.imageFileName!) goldMedal.zPosition = SpriteZPosition.Overlay goldMedal.hidden = true cameraNode.addChild(goldMedal) - medalNodes[Rank.First] = goldMedal + medalNodes[Rank.Gold] = goldMedal - let silverMedal = SKSpriteNode(imageNamed: Rank.Second.imageFileName!) + let silverMedal = SKSpriteNode(imageNamed: Rank.Silver.imageFileName!) silverMedal.zPosition = SpriteZPosition.Overlay silverMedal.hidden = true cameraNode.addChild(silverMedal) - medalNodes[Rank.Second] = silverMedal + medalNodes[Rank.Silver] = silverMedal - let bronzeMedal = SKSpriteNode(imageNamed: Rank.Third.imageFileName!) + let bronzeMedal = SKSpriteNode(imageNamed: Rank.Bronze.imageFileName!) bronzeMedal.zPosition = SpriteZPosition.Overlay bronzeMedal.hidden = true cameraNode.addChild(bronzeMedal) - medalNodes[Rank.Third] = bronzeMedal + medalNodes[Rank.Bronze] = bronzeMedal } private func preparePauseNode() { @@ -746,14 +746,14 @@ class GameScene: SKScene, SKPhysicsContactDelegate { } private func hideMedal() { - medalNodes[Rank.First]?.removeAllActions() - medalNodes[Rank.First]?.hidden = true + medalNodes[Rank.Gold]?.removeAllActions() + medalNodes[Rank.Gold]?.hidden = true - medalNodes[Rank.Second]?.removeAllActions() - medalNodes[Rank.Second]?.hidden = true + medalNodes[Rank.Silver]?.removeAllActions() + medalNodes[Rank.Silver]?.hidden = true - medalNodes[Rank.Third]?.removeAllActions() - medalNodes[Rank.Third]?.hidden = true + medalNodes[Rank.Bronze]?.removeAllActions() + medalNodes[Rank.Bronze]?.hidden = true } // MARK: @@ -796,6 +796,40 @@ class GameScene: SKScene, SKPhysicsContactDelegate { rockXPositions.removeFirst() } } + + private func updateGameStatistics(planeType: PlaneType, medalType: Rank) { + GameStatistics.flightCount.increaseCountByOne() + + switch planeType { + case .Red: + GameStatistics.flightCountRedPlane.increaseCountByOne() + case .Green: + GameStatistics.flightCountGreenPlane.increaseCountByOne() + case .Yellow: + GameStatistics.flightCountYellowPlane.increaseCountByOne() + case .Blue: + GameStatistics.flightCountBluePlane.increaseCountByOne() + } + + switch medalType { + case .Gold: + GameStatistics.goldMedalCount.increaseCountByOne() + case .Silver: + GameStatistics.silverMedalCount.increaseCountByOne() + case .Bronze: + GameStatistics.bronzeMedalCount.increaseCountByOne() + case .None: + break + } + } + + private func reportToGameCenter(planeType: PlaneType, medalType: Rank, score: Int) { + let achievements = AchievementHelper.sharedInstance.createAchievements(planeType, medalType: medalType) + GameKitHelper.sharedInstance.reportAchievements(achievements) + + let gkScore = LeaderBoardHelper.sharedInstance.createScore(planeType, score: score) + GameKitHelper.sharedInstance.reportScore(gkScore) + } func checkGameScore() { let topThreeRecord = TopThreeRecords() @@ -804,11 +838,15 @@ class GameScene: SKScene, SKPhysicsContactDelegate { if rank != .None { showMedal(rank) - topThreeRecord.checkAndReplacePoint(planeEntity.planeType.rawValue, point: score) } + + updateGameStatistics(planeEntity.planeType, medalType: rank) + + reportToGameCenter(planeEntity.planeType, medalType: rank, score: score) } + // MARK: Camera /* diff --git a/Shared/TopRecordsScene.swift b/Shared/TopRecordsScene.swift index b04b09b..ed7a8cb 100644 --- a/Shared/TopRecordsScene.swift +++ b/Shared/TopRecordsScene.swift @@ -17,6 +17,10 @@ class TopRecordsScene: SKScene { var backTextures: [SKTexture] = [] var backPressed = false + var gameCenterSprite: SKSpriteNode! + var gameCenterTextures: [SKTexture] = [] + var gameCenterPressed = false + var topThreeRecords = TopThreeRecords() override func didMoveToView(view: SKView) { @@ -58,11 +62,21 @@ class TopRecordsScene: SKScene { } func loadButtons() { + gameCenterTextures.append(SKTexture(imageNamed: "game_center")) + gameCenterTextures.append(SKTexture(imageNamed: "game_center_pressed")) + + let gameCenter = SKSpriteNode(texture: gameCenterTextures[0]) + gameCenter.position = CGPoint(x: size.width - gameCenter.size.width, y: overlapAmount() / 2 + gameCenter.size.height) + gameCenter.zPosition = SpriteZPosition.Overlay + + backgroundLayer.addChild(gameCenter) + gameCenterSprite = gameCenter + backTextures.append(SKTexture(imageNamed: "back")) backTextures.append(SKTexture(imageNamed: "back_pressed")) let back = SKSpriteNode(texture: backTextures[0]) - back.position = CGPoint(x: size.width - back.size.width, y: overlapAmount() / 2 + back.size.height) + back.position = CGPoint(x: size.width - back.size.width, y: gameCenter.position.y + back.size.height) back.zPosition = SpriteZPosition.Overlay backgroundLayer.addChild(back) @@ -77,6 +91,14 @@ class TopRecordsScene: SKScene { SKTAudio.sharedInstance().playSoundEffect("click3.wav") } + func touchDownGameCenter() { + gameCenterSprite.texture = gameCenterTextures[1] + gameCenterSprite.size = (gameCenterSprite.texture?.size())! + gameCenterPressed = true + + playClickSound() + } + func touchDownBack() { backSprite.texture = backTextures[1] backSprite.size = (backSprite.texture?.size())! @@ -85,7 +107,16 @@ class TopRecordsScene: SKScene { playClickSound() } + func showGameCenterViewController() { + NSNotificationCenter.defaultCenter().postNotificationName(PresentGameCenterViewController, object: self) + + gameCenterSprite.texture = gameCenterTextures[0] + gameCenterSprite.size = (gameCenterSprite.texture?.size())! + gameCenterPressed = false + } + func doBack() { + let scene = MainScene(size: GameSetting.SceneSize) scene.scaleMode = (self.scene?.scaleMode)! let transition = SKTransition.pushWithDirection(.Down, duration: 0.6) @@ -110,6 +141,8 @@ class TopRecordsScene: SKScene { if node == backSprite { touchDownBack() + } else if node == gameCenterSprite { + touchDownGameCenter() } } @@ -117,6 +150,10 @@ class TopRecordsScene: SKScene { if backPressed { doBack() } + + if gameCenterPressed { + showGameCenterViewController() + } } override func touchesCancelled(touches: Set?, withEvent event: UIEvent?) { @@ -125,6 +162,12 @@ class TopRecordsScene: SKScene { backSprite.size = (backSprite.texture?.size())! backPressed = false } + + if gameCenterPressed { + gameCenterSprite.texture = gameCenterTextures[0] + gameCenterSprite.size = (gameCenterSprite.texture?.size())! + gameCenterPressed = false + } } func showTopRecords() { diff --git a/Shared/TopThreeRecords.swift b/Shared/TopThreeRecords.swift index 5df52a3..3b9cba7 100644 --- a/Shared/TopThreeRecords.swift +++ b/Shared/TopThreeRecords.swift @@ -9,18 +9,18 @@ import Foundation enum Rank: Int { - case First = 3 - case Second = 2 - case Third = 1 + case Gold = 3 + case Silver = 2 + case Bronze = 1 case None = 0 var imageFileName: String? { switch self { - case .First: + case .Gold: return "gold" - case .Second: + case .Silver: return "silver" - case .Third: + case .Bronze: return "bronze" case .None: return nil @@ -163,7 +163,7 @@ class TopThreeRecords { } func getRankOfPoint(point: Int) -> Rank { - var result: Rank = .First + var result: Rank = .Gold for record in topThreeRecords { if record.point >= point { diff --git a/Shared/etc.atlas/back_pressed.png b/Shared/etc.atlas/back_pressed.png index 2eac346..8b56c4b 100644 Binary files a/Shared/etc.atlas/back_pressed.png and b/Shared/etc.atlas/back_pressed.png differ diff --git a/Shared/etc.atlas/game_center.png b/Shared/etc.atlas/game_center.png new file mode 100644 index 0000000..8f41034 Binary files /dev/null and b/Shared/etc.atlas/game_center.png differ diff --git a/Shared/etc.atlas/game_center_pressed.png b/Shared/etc.atlas/game_center_pressed.png new file mode 100644 index 0000000..5ed1f9b Binary files /dev/null and b/Shared/etc.atlas/game_center_pressed.png differ