Last active
December 10, 2023 21:05
-
-
Save imbradmiller/438fa0459ef5bc14cef77ee1f203ecb5 to your computer and use it in GitHub Desktop.
Random Gems Everywhere
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let totalGems = randomNumberOfGems | |
var gemCon = 0 | |
func navigate () { | |
while !isBlocked { | |
moveForward() | |
if isOnGem { | |
collectGem() | |
gemCon += 1 | |
} | |
} | |
} | |
func turnOffPortals() { | |
bluePortal.isActive = false | |
pinkPortal.isActive = false | |
} | |
func turnOnPortals() { | |
bluePortal.isActive = true | |
pinkPortal.isActive = true | |
} | |
func turnAround() { | |
turnRight() | |
turnRight() | |
} | |
while gemCon < totalGems { | |
navigate() | |
turnAround() | |
turnOffPortals() | |
navigate() | |
turnAround() | |
turnOnPortals() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is simple but cleaver soloution
Also If you add FUNC to it,it will be much better,
anyway:
let totalGems = randomNumberOfGems
var gem = 0
while gem < totalGems {
moveForward()
if isOnGem {
collectGem()
gem += 1
}
if isBlocked {
turnRight()
turnRight()
if pinkPortal.isActive == false {
pinkPortal.isActive = true
bluePortal.isActive = false
}else{
pinkPortal.isActive = false
bluePortal.isActive = true
}
}
}