2022年2月18日 星期五

學習程式設計1_09_建立新的函數

Suggest_Code_01

func turnRight(){
turnLeft()
turnLeft()
turnLeft()
}
moveForward()
turnLeft()
moveForward()
turnRight()
moveForward()
turnRight()
moveForward()
turnRight()
moveForward()
turnLeft()
moveForward()
toggleSwitch()

Result: OK


Suggest_Code_02

Func turnRight(){
turnLeft()
turnLeft()
turnLeft()
}
moveForward()
turnRight()
moveForward()
turnRight()
moveForward()
moveForward()
turnRight()
moveForward()
moveForward()
moveForward()
moveForward()
turnRight()
moveForward()
toggleSwitch()

Result: OK





Hint:
關卡內有3塊開關,只要將沒有發亮的開關打開即可,本來就亮著的開關不用再去做 toggleSwitch 的動作。

沒有留言:

學習程式設計1_10_收集、切換、重複

Suggest_Code_01 moveForward() collectGem() moveForward() toggleSwitch() moveForward() turnLeft() moveForward() collectGem() moveForward() to...