隨機化的陸地
?? ? ? ?
? ? ? ? var heights: [Int] = [2,6 ,9,2,6 ,9 ,9 ] ?
?? ? ? ?
? ? ? ? for i in 1...20 {?
? ? ? ? let localNumber = randomInt (from:? 1,? ?
? ? ? ? to: 12)?
? ? ? ? heights.append (localNumber)?
? ? ? ? }?
?? ? ? ?
? ? ? ? let allCoordinates = world.allPossibleCoordinates?
? ? ? ? //網(wǎng)絡(luò)中所有坐標(biāo)系?
?? ? ? ?
?? ? ? ?
? ? ? ? var index = 0?
? ? ? ? //設(shè)定空數(shù)據(jù) 一個核心的循環(huán)計數(shù)器index?
?? ? ? ?
? ? ? ? for coordinate in allCoordinates?
? ? ? ? //0到該空間數(shù)據(jù)坐標(biāo)到循環(huán)次數(shù)也就是所有坐標(biāo)予以給數(shù)值?
? ? ? ? {?
? ? ? ? if index == heights.count {?
? ? ? ? index = 0//假如數(shù)字等于height里面的數(shù)據(jù)那么index等于0?
? ? ? ? }?
?? ? ? ?
? ? ? ? for i in 0...heights [index]? {?
? ? ? ? //d當(dāng)數(shù)據(jù)變動1234時候那么放磚塊?? ,這里的index是上面的數(shù)組一共是7個
?? ? ? ?
? ? ? ? //放置一塊磚。?
? ? ? ? world.place(Block(),at:coordinate)?
? ? ? ? }?
? ? ? ? // 使索引遞增。?
? ? ? ? index += 1?
? ? ? ? }?
? ? ? ? //可以看到磚塊最高個數(shù)位4。修改數(shù)據(jù)可以得到磚塊的高度
?? ? ? ?
? ? ? ??