PlayGround/코딩배우기 2

PlayGrounds [ 3개의 보석, 4개의 스위치 ]

동빠기 2020. 2. 27. 17:19

 

 

//1. 2개의 개별적인 변수 생성 (보석을 수집하고, 스위치를 작동시키기 위함)

var gemCounter = 0

var onSwitch = 0


//3. 캐릭터가 언제 동작을 중단할지,  if구문 or while루프로 조건식 생성

while (gemCounter < 3 || onSwitch < 4) {

	while !isBlocked {

		moveForward()
        
        //2. 보석을 수집할때 변수를 1씩 증가 시키기

		if isOnGem && gemCounter < 3 {

			gemCounter = gemCounter + 1

		}
		
         //2. 스위치를 작동할때 변수를 1씩 증가 시키기

        
		if isOnClosedSwitch && onSwitch < 4 {

			toggleSwitch()

			onSwitch = onSwitch + 1

		}

	}

	if isBlockedLeft {

		turnRight()

	}

	else if isBlockedRight {

		turnLeft()

	}

}