大宮盆栽デイズ - Omiya Bonsai Days -

冗談めかす埼玉のファインマン

ランダムな地形@コードを学ぼう2

創作の課題なのに、遊び心、楽しむ気持ちが全くないコードになりました。今は早く Playgrounds のコンテンツを制覇したい気持ちだけが強いです。

// ランダムな地形@コードを学ぼう2
let allCoordinates = world.allPossibleCoordinates
var heights: [Int] = []

// Append random numbers to heights.
for i in 1 ... 20 {
    let localNumber = randomInt(from: 0, to: 13)
    heights.append(localNumber)
}

var index = 0
for coordinate in allCoordinates {
    if index == heights.count {
        index = 0
    }
    
    // currentHeight stores the height at the current index.
    var currentHeight = heights[index]
    
    
    if currentHeight == 0 {
        // Do something interesting if currentHeight is equal to 0.
        
        
    } else {
        for i in 1...currentHeight {
            world.place(Block(), at: coordinate)
        }
        if currentHeight > 10 {
            // Do something different, such as placing a character.
            world.place(Character(), at: coordinate)
        } else if coordinate.column >= 3 && coordinate.column < 6 {
            // Do something different, such as placing water.
            
            
        }
        // Add more rules to customize your world.
        
        
    }
    index += 1
    
}

youtu.be