diff --git a/TetrisKit/GameController.swift b/TetrisKit/GameController.swift index 83a37d0..00b104f 100644 --- a/TetrisKit/GameController.swift +++ b/TetrisKit/GameController.swift @@ -24,9 +24,11 @@ public class GameController: ObservableObject { } } @Published public var currentPieceAtDropPoint: GamePiece? - @Published public var nextTetrominoes: [Tetromino] = [.random(), .random(), .random()] + @Published public var nextTetrominoes: [Tetromino] = [] @Published public var heldTetromino: Tetromino? + var currentBag: [Tetromino] = [] + @Published public var score = 0 var previousPieceWasTetris = false @@ -41,13 +43,26 @@ public class GameController: ObservableObject { public func start() { state = .playing(.normal) + generateBag() nextPiece() } func nextPiece() { let tetromino = nextTetrominoes.removeFirst() currentPiece = GamePiece(tetromino: tetromino, topLeft: ((width - tetromino.shape.count) / 2, 0)) - nextTetrominoes.append(.random()) + + if currentBag.isEmpty { + generateBag() + } + nextTetrominoes.append(currentBag.removeFirst()) + } + + func generateBag() { + currentBag = Array(0..