gongchengxiaofendui / Game-2048

团队作业
1 stars 0 forks source link

生成数字时判断方格是否已满 #14

Closed gyf-lancelot closed 8 years ago

gyf-lancelot commented 8 years ago

判断方格是否已满,只在空格处生成数字

gyf-lancelot commented 8 years ago

func setPosition(row:Int,col:Int,value:Int) -> Bool { assert(row >= 0 && row < dimension) assert(col >= 0 && col < dimension) var index = self.dimension * row + col var val = tiles[index] if (val > 0) { println("This position has been occupied") return false } tiles[index] = value return true }

func emptyPositions() -> [Int]
{
    var emptytiles = [Int]()

    for i in 0..<(dimension * dimension)
    {
        if(tiles[i] == 0)
        {
            emptytiles.append(i)
        }
    }
     return emptytiles
}

func isfull() -> Bool
{
    if(emptyPositions().count == 0)
    {
        return true
    }
    return false
}