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

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

隅々まで歩き回る@コードを学ぼう2

//隅々まで歩き回る@コードを学ぼう2
greenPortal.isActive = false

func back() {
    if isBlocked {
        turnLeft()
        turnLeft()
        moveForward()
    }
}

func xC() {
    for i in 1 ... 4 {
        turnLeft()
        moveForward()
        if isOnGem {
            collectGem()
        } else if isOnClosedSwitch {
            toggleSwitch()
        }
        turnLeft()
        turnLeft()
        moveForward()
    }
}

turnLeft()
moveForward()
moveForward()
xC()
moveForward()
greenPortal.isActive = true
back()
greenPortal.isActive = false
xC()
moveForward()
greenPortal.isActive = true
back()
turnRight()
orangePortal.isActive = false
moveForward()
moveForward()
moveForward()
xC()
moveForward()
orangePortal.isActive = true
back()
orangePortal.isActive = false
xC()