【发布时间】:2019-11-20 14:30:59
【问题描述】:
所以我正在上课,我正在努力让我们的事情变得更容易一些。我们正在尝试制作像景观一样的 Q*bert,并且我们正在使用数组。我试图让它更短且可重复。所以我有:
let allCoordinate = world.allPossibleCoordinates
let coordinaterow = coordinate.row
var coordinaterow = 3
while coodinaterow != 8 {
var heights: [Int] = [0,0,0,0,0,0,0,0,1]
var index = 0
for coordinate in allCoordinates {
if coordinate.row ==3 {
if index == height.count {
index = 0
}
for i in 0...heights[index] {
world.place(Block(), at: coordinate)
}
index += 1
}
}
allCoordinate += 1
coordinaterow += 1
}
如何增加高度数组,如:
0,0,0,0,0,0,0,0,1 -- 0,0,0,0,0,0,0,1,2 -- 0,0,0,0,0,0,1,2,3
等等
【问题讨论】: