Sponsored

Collapse

Announcement

Collapse
No announcement yet.

Floating Islands - Swift Playgrounds

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Floating Islands - Swift Playgrounds

    The challenge of this lesson is to add blocks, stairs, and portals.

    For this challenge, practice your world-building skills by adding all the elements needed to solve the puzzle. There are many different solutions, so decide whether you prefer to use a portal to jump around, or add blocks to bridge gaps.

    Remember:
    You can create an instance and place it with the same line of code:
    world.place(Block(), atColumn: 2, row: 2)

    First, you'll need to initialize a character to solve the puzzle. See if you can think it through by using pseudocode that navigates through the puzzle world. Then use your code to change the structure of the puzzle world.

    Click image for larger version

Name:	Screen Shot 2017-01-05 at 5.07.50 PM.png
Views:	293
Size:	187.7 KB
ID:	1806

    Hint: There are many different ways to solve this puzzle. Use your world-building skills to add blocks, portals, and stairs that will help you solve the puzzle in whatever way you think will work best. You need to add an instance of your character or the expert to solve this puzzle. Don't be afraid to try different approaches to solving this puzzle. Coders often don't get things right on the first try!

    Code:
    let character = Character()
    world.place(character, facing: east, atColumn: 1, row: 6)
    
    func turnAround() {
     character.turnLeft()
     character.turnLeft()
    }
    
    func jumpToggleTurn() {
     character.jump()
     character.toggleSwitch()
     turnAround()
    }
    
    func solvePart() {
     character.collectGem()
     jumpToggleTurn()
     character.jump()
     character.turnRight()
     jumpToggleTurn()
    }
    
    solvePart()
    world.place(Portal(color: green), atStartColumn: 1, startRow: 6, atEndColumn: 2, endRow: 0)
    character.jump()
    turnAround()
    character.jump()
    solvePart()
    let bluePortal = Portal(color: blue)
    world.place(bluePortal, atStartColumn: 2, startRow: 1, atEndColumn: 6, endRow: 4)
    character.jump()
    turnAround()
    bluePortal.isActive = false
    solvePart()
    Impressive! Overtime you figure out a new solution, you gain a better sense of which solutions will work for a certain kind of problem. The next time you see something similar, you'll already have a hunch about how to solve it!

    Next we will be looking at "Build a Loop" tutorial.

  • #2
     

    Comment


    • #3
      Code:
      let char = Character()
      
      world.place(char, facing: east, atColumn: 1, row: 2)
      
      world.place(Portal(color: green), atStartColumn: 1, startRow: 3, atEndColumn: 2, endRow: 7)
      
      world.place(Portal(color: red), atStartColumn: 3, startRow: 3, atEndColumn: 5, endRow: 3)
      
      
      
      
      func solveSquare() {
      
          for i in 1 ... 4 {
      
              char.jump()
      
              if i == 4 {
      
                  break
      
              }
      
              char.turnRight()
      
              if char.isOnGem {
      
                  char.collectGem()
      
              } else if char.isOnClosedSwitch {
      
                  char.toggleSwitch()
      
              }
      
          }
      
      }
      
      
      
      
      solveSquare()
      
      char.moveForward()
      
      char.turnRight()
      
      char.turnRight()
      
      solveSquare()
      
      char.move(distance: 2)
      
      char.turnLeft()
      
      solveSquare()

      Comment

      Working...
      X