我們過(guò)了這么多關(guān)卡丧诺,每一個(gè)磚塊、海水都是系統(tǒng)設(shè)置好的吼句,我們能不能自己給自己做一個(gè)?
現(xiàn)在機(jī)會(huì)來(lái)了事格。
我們把原始的地形看一下惕艳。
現(xiàn)在我們要做的是,造一個(gè)高低不一的島嶼驹愚。
代碼如下:
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// 使索引遞增。
}
執(zhí)行后:
有的數(shù)字我們自己試試修改一下