我们过了这么多关卡,每一个砖块、海水都是系统设置好的,我们能不能自己给自己做一个?
现在机会来了。

我们把原始的地形看一下。

现在我们要做的是,造一个高低不一的岛屿。
代码如下:
var heights: [Int] = [9,7,5,3,1]
//var heights: [Int] = [randomInt(from: 0, to: 10)]
let allCoordinates = world.allPossibleCoordinates
var index = 0
for coordinate in allCoordinates {
if index == heights.count {
index = 0
}
for index in 0...heights[index] {
world.place(Block(), at: coordinate)
//world.place(Block(), at: coordinate)// 放置一块砖。
}
index = index + 1// 使索引递增。
}
执行后:

有的数字我们自己试试修改一下