Skip to content

Commit

Permalink
Refactor: Modify for-in loop in foundationView and Add cards() in fou…
Browse files Browse the repository at this point in the history
…ndationDelegate #26
  • Loading branch information
jinios authored and godrm committed May 14, 2018
1 parent 425332b commit 87d00a1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ class FoundationDelegate: FoundationManageable, Stackable {
return self.foundations[at.column].getCard(at: at.row)
}

func cards(in column: Int) -> [Card] {
return self.foundations[column].getCards()
}

}
3 changes: 3 additions & 0 deletions CardGameApp/CardGameApp/Model/CardStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ struct CardStack {
return (self.cards.count == 0)
}

func getCards()-> [Card] {
return self.cards
}
}


Expand Down
1 change: 1 addition & 0 deletions CardGameApp/CardGameApp/Model/CustomProtocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ protocol CardStackManageable {
protocol FoundationManageable {
func cardInTurn(at:(column: Int, row: Int)) -> Card
func countOfCards(of: Int) -> Int
func cards(in column: Int) -> [Card]
}

protocol StackManageable {
Expand Down
6 changes: 1 addition & 5 deletions CardGameApp/CardGameApp/View/FoundationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,19 @@ class FoundationView: UIView {

func redraw() {
self.subviews.forEach({ $0.removeFromSuperview() })

for i in FoundationDelegate.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 {
self.drawEmptyDock(in: frameForDraw)
} else {
for j in 0..<foundationManager.countOfCards(of: i) {
let card = foundationManager.cardInTurn(at: (column: i, row: j))
for card in foundationManager.cards(in: i) {
let cardImage = CardImageView(frame: frameForDraw)
cardImage.getImage(of: card)
addSubview(cardImage)
}
}
}

}

}

0 comments on commit 87d00a1

Please sign in to comment.