diff --git a/TetraVex/TVGameViewController.swift b/TetraVex/TVGameViewController.swift index 4ca7155..f728980 100644 --- a/TetraVex/TVGameViewController.swift +++ b/TetraVex/TVGameViewController.swift @@ -75,6 +75,9 @@ class TVGameViewController: NSViewController { if boardModel!.addPieceToBoard(pv.pieceModel!, x: i, y: j) { pv.frame.origin.x = CGFloat(i)*pv.frame.width + boardAreaBox.frame.origin.x pv.frame.origin.y = CGFloat(j)*pv.frame.height + boardAreaBox.frame.origin.y + } else { + pv.frame.origin.x = templatePieceView.frame.origin.x + CGFloat(Int.random(0...100)) + pv.frame.origin.y = templatePieceView.frame.origin.y - CGFloat(Int.random(0...100)) } } } diff --git a/TetraVexKit/TetraVexBoardModel.swift b/TetraVexKit/TetraVexBoardModel.swift index 8be777c..4c75da8 100644 --- a/TetraVexKit/TetraVexBoardModel.swift +++ b/TetraVexKit/TetraVexBoardModel.swift @@ -12,11 +12,15 @@ open class TetraVexBoardModel { // MARK: - Properties open var board : [[PieceModel?]] + open var boardWidth : Int = 0 + open var boardHeight : Int = 0 open var startedPlaying : Bool = false // MARK: - Initializer public init(width: Int, height: Int) { board = Array(repeating: Array(repeating: nil, count: height), count: width) + boardWidth = width + boardHeight = height } // MARK: - Board manipulation @@ -69,7 +73,19 @@ open class TetraVexBoardModel { return true } - func isCompleted() -> Bool { + open func removePieceFromBoard(_ piece: PieceModel) -> Bool { + for i in 0.. Bool { for a in board { for p in a { if p == nil { diff --git a/TetraVexKitTests/TetraVexKitTests.swift b/TetraVexKitTests/TetraVexKitTests.swift index 866438b..779dc10 100644 --- a/TetraVexKitTests/TetraVexKitTests.swift +++ b/TetraVexKitTests/TetraVexKitTests.swift @@ -56,8 +56,15 @@ class TetraVexKitTests: XCTestCase { let c = PieceModel(top: 3, left: 1, bottom: 4, right: 2) let d = PieceModel(top: 2, left: 2, bottom: 1, right: 1) + let board = TetraVexBoardModel(width: 2, height: 2) - var r = board.addPieceToBoard(a, x: 0, y: 1) + var r = board.removePieceFromBoard(a) + XCTAssert(r == false) + r = board.addPieceToBoard(a, x: 1, y: 1) + XCTAssert(r == true) + r = board.removePieceFromBoard(a) + XCTAssert(r == true) + r = board.addPieceToBoard(a, x: 0, y: 1) XCTAssert(r == true) r = board.addPieceToBoard(b, x: 0, y: 1) XCTAssert(r == false)