右にも左にも@コードを学ぼう1
関数にするべきところがいくつかありますが、とりあえずそのまま掲載します。
//右にも左にも@コードを学ぼう1 for i in 1 ... 3 { turnLeft() moveForward() toggleSwitch() moveForward() toggleSwitch() turnLeft() turnLeft() moveForward() moveForward() moveForward() collectGem() moveForward() collectGem() turnLeft() turnLeft() moveForward() moveForward() turnRight() moveForward() }
//右にも左にも@コードを学ぼう1 //一歩進んでスイッチオン func moveToggle() { moveForward() toggleSwitch() } //反対方向に向く func back() { turnLeft() turnLeft() } //2歩進む func step2() { moveForward() moveForward() } for i in 1 ... 3 { turnLeft() moveToggle() moveToggle() back() step2() moveForward() collectGem() moveForward() collectGem() back() step2() turnRight() moveForward() }