You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This function can be optimized like this so that it can create any nums of blocks.
@discardableResultfileprivatefunc generateNewBlock()->Bool{varblankLocations=[BlockMatrixType.Index]()
for rowIndex in 0..<4{
for colIndex in 0..<4{letindex=(colIndex, rowIndex)
if _blockMatrix[index]==nil{
blankLocations.append(index)}}}
guard blankLocations.count >=1else{return false
}// Don't forget to sync data.defer{
objectWillChange.send(self)}
_blockMatrix.place(IdentifiedBlock(id: newGlobalID, number:2), to: blankLocations.randomElement()!)return true
}@discardableResultfileprivatefunc generateNewBlocks(_ num:Int=1)->Bool{
guard num >0else{return false
}
for _ in 0..<num {
if !generateNewBlock(){return false
}}return true
}
The text was updated successfully, but these errors were encountered:
SwiftUI-2048/SwiftUI2048/Models/GameLogic.swift
Line 131 in 34f315a
This function can be optimized like this so that it can create any nums of blocks.
The text was updated successfully, but these errors were encountered: