diff --git a/CardGameApp/CardGameApp.xcodeproj/project.pbxproj b/CardGameApp/CardGameApp.xcodeproj/project.pbxproj index b8a6a002..96940e3d 100644 --- a/CardGameApp/CardGameApp.xcodeproj/project.pbxproj +++ b/CardGameApp/CardGameApp.xcodeproj/project.pbxproj @@ -8,10 +8,10 @@ /* Begin PBXBuildFile section */ FD692644209D93EE0069B29A /* CustomExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD692643209D93EE0069B29A /* CustomExtension.swift */; }; - FD7A6A2520A031BC002D66CA /* WholeStackDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD7A6A2420A031BC002D66CA /* WholeStackDelegate.swift */; }; - FD7A6A2720A0401A002D66CA /* DeckDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD7A6A2620A0401A002D66CA /* DeckDelegate.swift */; }; + FD7A6A2520A031BC002D66CA /* WholeStackManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD7A6A2420A031BC002D66CA /* WholeStackManager.swift */; }; + FD7A6A2720A0401A002D66CA /* DeckManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD7A6A2620A0401A002D66CA /* DeckManager.swift */; }; FD884CD320883F1100DD1954 /* CardStacksView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD884CD220883F1100DD1954 /* CardStacksView.swift */; }; - FD884CD72088AAF300DD1954 /* CardGameDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD884CD62088AAF300DD1954 /* CardGameDelegate.swift */; }; + FD884CD72088AAF300DD1954 /* CardGameManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD884CD62088AAF300DD1954 /* CardGameManager.swift */; }; FDC1ACB0208F23F000A39C47 /* CardDeckView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDC1ACAF208F23F000A39C47 /* CardDeckView.swift */; }; FDC5D438208DF2BB000A1E0C /* FoundationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDC5D437208DF2BB000A1E0C /* FoundationView.swift */; }; FDD8FA16207F035400F5FD99 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDD8FA15207F035400F5FD99 /* AppDelegate.swift */; }; @@ -27,16 +27,16 @@ FDDFB93C2080498800920FB4 /* CardDeck.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDDFB9352080498700920FB4 /* CardDeck.swift */; }; FDDFB93D2080498800920FB4 /* Card.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDDFB9362080498700920FB4 /* Card.swift */; }; FDF8BBB0209AF89C00AA0C82 /* CustomProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDF8BBAF209AF89C00AA0C82 /* CustomProtocols.swift */; }; - FDF8BBB2209AFA2A00AA0C82 /* StackDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDF8BBB1209AFA2A00AA0C82 /* StackDelegate.swift */; }; + FDF8BBB2209AFA2A00AA0C82 /* StackManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDF8BBB1209AFA2A00AA0C82 /* StackManager.swift */; }; FDF8BBB4209C905100AA0C82 /* FoundationDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDF8BBB3209C905100AA0C82 /* FoundationDelegate.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ FD692643209D93EE0069B29A /* CustomExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomExtension.swift; sourceTree = ""; }; - FD7A6A2420A031BC002D66CA /* WholeStackDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WholeStackDelegate.swift; sourceTree = ""; }; - FD7A6A2620A0401A002D66CA /* DeckDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeckDelegate.swift; sourceTree = ""; }; + FD7A6A2420A031BC002D66CA /* WholeStackManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WholeStackManager.swift; sourceTree = ""; }; + FD7A6A2620A0401A002D66CA /* DeckManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeckManager.swift; sourceTree = ""; }; FD884CD220883F1100DD1954 /* CardStacksView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardStacksView.swift; sourceTree = ""; }; - FD884CD62088AAF300DD1954 /* CardGameDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardGameDelegate.swift; sourceTree = ""; }; + FD884CD62088AAF300DD1954 /* CardGameManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardGameManager.swift; sourceTree = ""; }; FDC1ACAF208F23F000A39C47 /* CardDeckView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardDeckView.swift; sourceTree = ""; }; FDC5D437208DF2BB000A1E0C /* FoundationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoundationView.swift; sourceTree = ""; }; FDD8FA12207F035400F5FD99 /* CardGameApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CardGameApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -54,7 +54,7 @@ FDDFB9352080498700920FB4 /* CardDeck.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardDeck.swift; sourceTree = ""; }; FDDFB9362080498700920FB4 /* Card.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Card.swift; sourceTree = ""; }; FDF8BBAF209AF89C00AA0C82 /* CustomProtocols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomProtocols.swift; sourceTree = ""; }; - FDF8BBB1209AFA2A00AA0C82 /* StackDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StackDelegate.swift; sourceTree = ""; }; + FDF8BBB1209AFA2A00AA0C82 /* StackManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StackManager.swift; sourceTree = ""; }; FDF8BBB3209C905100AA0C82 /* FoundationDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoundationDelegate.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -83,11 +83,11 @@ FD7DF3E620A2F0DB00BD62B7 /* DelegateModel */ = { isa = PBXGroup; children = ( - FD884CD62088AAF300DD1954 /* CardGameDelegate.swift */, - FD7A6A2620A0401A002D66CA /* DeckDelegate.swift */, + FD884CD62088AAF300DD1954 /* CardGameManager.swift */, + FD7A6A2620A0401A002D66CA /* DeckManager.swift */, FDF8BBB3209C905100AA0C82 /* FoundationDelegate.swift */, - FD7A6A2420A031BC002D66CA /* WholeStackDelegate.swift */, - FDF8BBB1209AFA2A00AA0C82 /* StackDelegate.swift */, + FD7A6A2420A031BC002D66CA /* WholeStackManager.swift */, + FDF8BBB1209AFA2A00AA0C82 /* StackManager.swift */, ); path = DelegateModel; sourceTree = ""; @@ -214,9 +214,9 @@ FDC5D438208DF2BB000A1E0C /* FoundationView.swift in Sources */, FD884CD320883F1100DD1954 /* CardStacksView.swift in Sources */, FDF8BBB0209AF89C00AA0C82 /* CustomProtocols.swift in Sources */, - FD7A6A2520A031BC002D66CA /* WholeStackDelegate.swift in Sources */, - FD884CD72088AAF300DD1954 /* CardGameDelegate.swift in Sources */, - FD7A6A2720A0401A002D66CA /* DeckDelegate.swift in Sources */, + FD7A6A2520A031BC002D66CA /* WholeStackManager.swift in Sources */, + FD884CD72088AAF300DD1954 /* CardGameManager.swift in Sources */, + FD7A6A2720A0401A002D66CA /* DeckManager.swift in Sources */, FDD8FA18207F035400F5FD99 /* ViewController.swift in Sources */, FDF8BBB4209C905100AA0C82 /* FoundationDelegate.swift in Sources */, FDDD33C62085EFCF000E9D0E /* CustomEnum.swift in Sources */, @@ -226,7 +226,7 @@ FDDFB93D2080498800920FB4 /* Card.swift in Sources */, FDD8FA16207F035400F5FD99 /* AppDelegate.swift in Sources */, FDC1ACB0208F23F000A39C47 /* CardDeckView.swift in Sources */, - FDF8BBB2209AFA2A00AA0C82 /* StackDelegate.swift in Sources */, + FDF8BBB2209AFA2A00AA0C82 /* StackManager.swift in Sources */, FDDFB93B2080498800920FB4 /* EnumCollection.swift in Sources */, FDDFB93A2080498800920FB4 /* CardStack.swift in Sources */, ); diff --git a/CardGameApp/CardGameApp/AppDelegate.swift b/CardGameApp/CardGameApp/AppDelegate.swift index 77f80266..568adeee 100644 --- a/CardGameApp/CardGameApp/AppDelegate.swift +++ b/CardGameApp/CardGameApp/AppDelegate.swift @@ -15,7 +15,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { let mainViewController = self.window?.rootViewController as! ViewController - mainViewController.cardGameManager = CardGameDelegate.shared() + mainViewController.cardGameManager = CardGameManager.shared() return true } diff --git a/CardGameApp/CardGameApp/DelegateModel/CardGameDelegate.swift b/CardGameApp/CardGameApp/DelegateModel/CardGameManager.swift similarity index 75% rename from CardGameApp/CardGameApp/DelegateModel/CardGameDelegate.swift rename to CardGameApp/CardGameApp/DelegateModel/CardGameManager.swift index 0072b0a8..7e80a3c2 100644 --- a/CardGameApp/CardGameApp/DelegateModel/CardGameDelegate.swift +++ b/CardGameApp/CardGameApp/DelegateModel/CardGameManager.swift @@ -8,23 +8,23 @@ import Foundation -class CardGameDelegate: CardGameManageable { +class CardGameManager: CardGameDelegate { // MARK: Singleton Related - private static var sharedCardDeck = CardGameDelegate() + private static var sharedCardDeck = CardGameManager() private init() { cardDeck.shuffle() var stacks = [CardStack]() - for numberOfCard in CardGameDelegate.defaultStackRange { + for numberOfCard in CardGameManager.defaultStackRange { let oneStack = cardDeck.makeStack(numberOf: numberOfCard) stacks.append(oneStack) } - self.stackManagers = WholeStackDelegate(stacks: stacks) - self.foundationManager = FoundationDelegate() - self.deckManager = DeckDelegate(deck: self.cardDeck) + self.stackManagers = WholeStackManager(stacks: stacks) + self.foundationManager = FoundationManager() + self.deckManager = DeckManager(deck: self.cardDeck) NotificationCenter.default.addObserver(self, @@ -43,24 +43,24 @@ class CardGameDelegate: CardGameManageable { NotificationCenter.default.post(name: .openDeckUpdated, object: true) } - class func shared() -> CardGameDelegate { + class func shared() -> CardGameManager { return sharedCardDeck } - class func restartSharedDeck() -> CardGameDelegate { - sharedCardDeck = CardGameDelegate() + class func restartSharedDeck() -> CardGameManager { + sharedCardDeck = CardGameManager() return sharedCardDeck } - func getWholeStackDelegate() -> (CardStackManageable & Stackable) { + func getWholeStackDelegate() -> (CardStackDelegate & Stackable) { return self.stackManagers } - func getFoundationDelegate() -> (FoundationManageable & Stackable) { + func getFoundationDelegate() -> (FoundationDelegate & Stackable) { return self.foundationManager } - func getDeckDelegate() -> CardDeckManageable { + func getDeckDelegate() -> CardDeckDelegate { return self.deckManager } @@ -69,9 +69,9 @@ class CardGameDelegate: CardGameManageable { static let defaultStackRange: CountableClosedRange = 1...7 static let defaultStackNumber: Int = 7 private var cardDeck = CardDeck() - private var stackManagers: (CardStackManageable & Stackable)! - private var foundationManager: (FoundationManageable & Stackable)! - private var deckManager: CardDeckManageable! + private var stackManagers: (CardStackDelegate & Stackable)! + private var foundationManager: (FoundationDelegate & Stackable)! + private var deckManager: CardDeckDelegate! func shuffleDeck() { deckManager.shuffleDeck() diff --git a/CardGameApp/CardGameApp/DelegateModel/DeckDelegate.swift b/CardGameApp/CardGameApp/DelegateModel/DeckManager.swift similarity index 96% rename from CardGameApp/CardGameApp/DelegateModel/DeckDelegate.swift rename to CardGameApp/CardGameApp/DelegateModel/DeckManager.swift index 3c2eabde..87143ee8 100644 --- a/CardGameApp/CardGameApp/DelegateModel/DeckDelegate.swift +++ b/CardGameApp/CardGameApp/DelegateModel/DeckManager.swift @@ -8,7 +8,7 @@ import Foundation -class DeckDelegate: CardDeckManageable { +class DeckManager: CardDeckDelegate { var deck: CardDeck! var openedDeck = [Card]() diff --git a/CardGameApp/CardGameApp/DelegateModel/FoundationDelegate.swift b/CardGameApp/CardGameApp/DelegateModel/FoundationDelegate.swift index 52ddc465..5adef998 100644 --- a/CardGameApp/CardGameApp/DelegateModel/FoundationDelegate.swift +++ b/CardGameApp/CardGameApp/DelegateModel/FoundationDelegate.swift @@ -8,7 +8,7 @@ import Foundation -class FoundationDelegate: FoundationManageable, Stackable { +class FoundationManager: FoundationDelegate, Stackable { static let range: CountableRange = 0..<4 var foundations = [CardStack]() @@ -17,18 +17,18 @@ class FoundationDelegate: FoundationManageable, Stackable { } init() { //초기상태는 빈 카드스택 4개 - for _ in FoundationDelegate.range { + for _ in FoundationManager.range { foundations.append(CardStack()) } } func stackable(nextCard card: Card) -> Int? { if card.isDenominationA() { - for i in FoundationDelegate.range where foundations[i].isEmpty() { + for i in FoundationManager.range where foundations[i].isEmpty() { return i } } else { - for i in FoundationDelegate.range where !foundations[i].isEmpty() { + for i in FoundationManager.range where !foundations[i].isEmpty() { if foundations[i].last()!.isLower(than: card) { return i } diff --git a/CardGameApp/CardGameApp/DelegateModel/StackDelegate.swift b/CardGameApp/CardGameApp/DelegateModel/StackManager.swift similarity index 92% rename from CardGameApp/CardGameApp/DelegateModel/StackDelegate.swift rename to CardGameApp/CardGameApp/DelegateModel/StackManager.swift index c7b080eb..63d5ca37 100644 --- a/CardGameApp/CardGameApp/DelegateModel/StackDelegate.swift +++ b/CardGameApp/CardGameApp/DelegateModel/StackManager.swift @@ -8,9 +8,9 @@ import Foundation -class StackDelegate: StackManageable { +class StackManager: StackDelegate { - private static var stackDelegates = [StackDelegate]() + private static var stackDelegates = [StackManager]() private var lastCard: Card? { return self.stack.last() diff --git a/CardGameApp/CardGameApp/DelegateModel/WholeStackDelegate.swift b/CardGameApp/CardGameApp/DelegateModel/WholeStackManager.swift similarity index 76% rename from CardGameApp/CardGameApp/DelegateModel/WholeStackDelegate.swift rename to CardGameApp/CardGameApp/DelegateModel/WholeStackManager.swift index 42b11f41..be84fd7f 100644 --- a/CardGameApp/CardGameApp/DelegateModel/WholeStackDelegate.swift +++ b/CardGameApp/CardGameApp/DelegateModel/WholeStackManager.swift @@ -8,18 +8,18 @@ import Foundation -class WholeStackDelegate: CardStackManageable,Stackable { - var stackManagers: [StackManageable]! +class WholeStackManager: CardStackDelegate,Stackable { + var stackManagers: [StackDelegate]! init(stacks: [CardStack]) { - var stackManagers = [StackManageable]() + var stackManagers = [StackDelegate]() for i in 0.. StackManageable { + func getStackDelegate(of column: Int) -> StackDelegate { return self.stackManagers[column] } diff --git a/CardGameApp/CardGameApp/Model/CustomProtocols.swift b/CardGameApp/CardGameApp/Model/CustomProtocols.swift index afef7f91..e5101e91 100644 --- a/CardGameApp/CardGameApp/Model/CustomProtocols.swift +++ b/CardGameApp/CardGameApp/Model/CustomProtocols.swift @@ -18,10 +18,10 @@ protocol ImageSelector { // MARK: CardGame Related -protocol CardGameManageable { - func getDeckDelegate() -> CardDeckManageable - func getWholeStackDelegate() -> (CardStackManageable & Stackable) - func getFoundationDelegate() -> (FoundationManageable & Stackable) +protocol CardGameDelegate { + func getDeckDelegate() -> CardDeckDelegate + func getWholeStackDelegate() -> (CardStackDelegate & Stackable) + func getFoundationDelegate() -> (FoundationDelegate & Stackable) func shuffleDeck() func movableFromDeck(from: ViewKey) -> (to: ViewKey, index: Int?) func movableFromStack(from: ViewKey, column: Int) -> (to: ViewKey, index: Int?) @@ -29,7 +29,7 @@ protocol CardGameManageable { func popStack(column: Int) } -protocol CardDeckManageable { +protocol CardDeckDelegate { func hasEnoughCard() -> Bool func lastOpenedCard() -> Card? func shuffleDeck() @@ -37,19 +37,19 @@ protocol CardDeckManageable { func pop() } -protocol CardStackManageable { +protocol CardStackDelegate { func lastCard(of column: Int) -> Card func removePoppedCard(of column: Int) - func getStackDelegate(of column: Int) -> StackManageable + func getStackDelegate(of column: Int) -> StackDelegate } -protocol FoundationManageable { +protocol FoundationDelegate { func cardInTurn(at:(column: Int, row: Int)) -> Card func countOfCards(of: Int) -> Int func cards(in column: Int) -> [Card] } -protocol StackManageable { +protocol StackDelegate { func countOfCard() -> Int func cardInTurn(at index: Int) -> Card func removePoppedCard() diff --git a/CardGameApp/CardGameApp/View/CardDeckView.swift b/CardGameApp/CardGameApp/View/CardDeckView.swift index d5fd65ed..132cee32 100644 --- a/CardGameApp/CardGameApp/View/CardDeckView.swift +++ b/CardGameApp/CardGameApp/View/CardDeckView.swift @@ -9,9 +9,9 @@ import UIKit class CardDeckView: UIView { - var gameManager: CardGameManageable = CardGameDelegate.shared() + var gameManager: CardGameDelegate = CardGameManager.shared() var closedCardDeck = CardImageView() - var deckManager: CardDeckManageable! + var deckManager: CardDeckDelegate! var lastCardView: CardImageView? { guard let lastView = subviews.last else { return nil } return lastView as? CardImageView diff --git a/CardGameApp/CardGameApp/View/CardStacksView.swift b/CardGameApp/CardGameApp/View/CardStacksView.swift index ea6b7950..fcba30f2 100644 --- a/CardGameApp/CardGameApp/View/CardStacksView.swift +++ b/CardGameApp/CardGameApp/View/CardStacksView.swift @@ -9,8 +9,8 @@ import UIKit class CardStacksView: UIView { - var gameManager: CardGameManageable = CardGameDelegate.shared() - var wholeStackManager: (CardStackManageable & Stackable)! + var gameManager: CardGameDelegate = CardGameManager.shared() + var wholeStackManager: (CardStackDelegate & Stackable)! var oneStackViews = [OneStack]() override init(frame: CGRect) { @@ -48,8 +48,8 @@ class CardStacksView: UIView { class OneStack: UIView { var column: Int! - var wholeStackManager: (CardStackManageable & Stackable)! - var stackManager: StackManageable! + var wholeStackManager: (CardStackDelegate & Stackable)! + var stackManager: StackDelegate! var lastCardView: CardImageView? { guard let lastView = subviews.last else { return nil } return lastView as? CardImageView @@ -59,7 +59,7 @@ class OneStack: UIView { super.init(frame: frame) } - convenience init(column: Int, manager: CardStackManageable & Stackable) { + convenience init(column: Int, manager: CardStackDelegate & Stackable) { self.init(frame: CGRect(x: PositionX.allValues[column].value, y: 0, width: 414 / 7, diff --git a/CardGameApp/CardGameApp/View/FoundationView.swift b/CardGameApp/CardGameApp/View/FoundationView.swift index 98704843..0a508dd1 100644 --- a/CardGameApp/CardGameApp/View/FoundationView.swift +++ b/CardGameApp/CardGameApp/View/FoundationView.swift @@ -9,8 +9,8 @@ import UIKit class FoundationView: UIView { - let gameManager: CardGameManageable = CardGameDelegate.shared() - var foundationManager: FoundationManageable! + let gameManager: CardGameDelegate = CardGameManager.shared() + var foundationManager: FoundationDelegate! let numberOfFoundation = 4 override init(frame: CGRect) { @@ -45,7 +45,7 @@ class FoundationView: UIView { func redraw() { self.subviews.forEach({ $0.removeFromSuperview() }) - for i in FoundationDelegate.range { + for i in FoundationManager.range { let newOrigin = CGPoint(x: PositionX.allValues[i].value, y: PositionY.upper.value) let frameForDraw = CGRect(origin: newOrigin, size: ViewController.cardSize) if foundationManager.countOfCards(of: i) == 0 { diff --git a/CardGameApp/CardGameApp/ViewController.swift b/CardGameApp/CardGameApp/ViewController.swift index 8c221446..39362a83 100644 --- a/CardGameApp/CardGameApp/ViewController.swift +++ b/CardGameApp/CardGameApp/ViewController.swift @@ -9,7 +9,7 @@ import UIKit class ViewController: UIViewController { - var cardGameManager: CardGameManageable = CardGameDelegate.shared() + var cardGameManager: CardGameDelegate = CardGameManager.shared() private var deckView: CardDeckView! private var stackView: CardStacksView!