Skip to content

Commit

Permalink
Refactor: Rename model classes and Delegate protocols #26
Browse files Browse the repository at this point in the history
  • Loading branch information
jinios committed May 14, 2018
1 parent 7314e2b commit 87e9b29
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 64 deletions.
32 changes: 16 additions & 16 deletions CardGameApp/CardGameApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -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 = "<group>"; };
FD7A6A2420A031BC002D66CA /* WholeStackDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WholeStackDelegate.swift; sourceTree = "<group>"; };
FD7A6A2620A0401A002D66CA /* DeckDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeckDelegate.swift; sourceTree = "<group>"; };
FD7A6A2420A031BC002D66CA /* WholeStackManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WholeStackManager.swift; sourceTree = "<group>"; };
FD7A6A2620A0401A002D66CA /* DeckManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeckManager.swift; sourceTree = "<group>"; };
FD884CD220883F1100DD1954 /* CardStacksView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardStacksView.swift; sourceTree = "<group>"; };
FD884CD62088AAF300DD1954 /* CardGameDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardGameDelegate.swift; sourceTree = "<group>"; };
FD884CD62088AAF300DD1954 /* CardGameManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardGameManager.swift; sourceTree = "<group>"; };
FDC1ACAF208F23F000A39C47 /* CardDeckView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardDeckView.swift; sourceTree = "<group>"; };
FDC5D437208DF2BB000A1E0C /* FoundationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoundationView.swift; sourceTree = "<group>"; };
FDD8FA12207F035400F5FD99 /* CardGameApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CardGameApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -54,7 +54,7 @@
FDDFB9352080498700920FB4 /* CardDeck.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardDeck.swift; sourceTree = "<group>"; };
FDDFB9362080498700920FB4 /* Card.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Card.swift; sourceTree = "<group>"; };
FDF8BBAF209AF89C00AA0C82 /* CustomProtocols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomProtocols.swift; sourceTree = "<group>"; };
FDF8BBB1209AFA2A00AA0C82 /* StackDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StackDelegate.swift; sourceTree = "<group>"; };
FDF8BBB1209AFA2A00AA0C82 /* StackManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StackManager.swift; sourceTree = "<group>"; };
FDF8BBB3209C905100AA0C82 /* FoundationDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoundationDelegate.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -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 = "<group>";
Expand Down Expand Up @@ -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 */,
Expand All @@ -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 */,
);
Expand Down
2 changes: 1 addition & 1 deletion CardGameApp/CardGameApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}

Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

class DeckDelegate: CardDeckManageable {
class DeckManager: CardDeckDelegate {
var deck: CardDeck!
var openedDeck = [Card]()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

class FoundationDelegate: FoundationManageable, Stackable {
class FoundationManager: FoundationDelegate, Stackable {

static let range: CountableRange = 0..<4
var foundations = [CardStack]()
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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..<stacks.count {
stackManagers.append(StackDelegate(oneStack: stacks[i], column: i))
stackManagers.append(StackManager(oneStack: stacks[i], column: i))
}
self.stackManagers = stackManagers
}

func getStackDelegate(of column: Int) -> StackManageable {
func getStackDelegate(of column: Int) -> StackDelegate {
return self.stackManagers[column]
}

Expand Down
18 changes: 9 additions & 9 deletions CardGameApp/CardGameApp/Model/CustomProtocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,38 @@ 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?)
func popOpenDeck()
func popStack(column: Int)
}

protocol CardDeckManageable {
protocol CardDeckDelegate {
func hasEnoughCard() -> Bool
func lastOpenedCard() -> Card?
func shuffleDeck()
func removePoppedCard()
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()
Expand Down
4 changes: 2 additions & 2 deletions CardGameApp/CardGameApp/View/CardDeckView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions CardGameApp/CardGameApp/View/CardStacksView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions CardGameApp/CardGameApp/View/FoundationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion CardGameApp/CardGameApp/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down

0 comments on commit 87e9b29

Please sign in to comment.