Sponsored

Collapse

Announcement

Collapse
No announcement yet.

Uniting Worlds - Swift Playgrounds

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

  • Uniting Worlds - Swift Playgrounds

    The goal of this level is to add a ew block to bridge two worlds.

    Up to now, the puzzle world has been defined for you. Now you can start making changes to that world.

    The switch in this puzzle is in an unreachable area, so you'll need to add a tile to connect the two pieces of this puzzle.

    Placing a block:
    Here's how you would place a block of coordinate(1,1):

    let block1 = Block()
    world.place(block1, atColumn:1, row: 1)

    1. First, create an instance of type Block.
    2. Next, use dot notation to access the world instance and call the place method.
    3. Pass your arguments into the place method. Use your Block instance for the item parameter, and a set of coordinates for the atColumn and row parameters.

    Click image for larger version

Name:	Screen Shot 2017-01-05 at 1.35.34 AM.png
Views:	2
Size:	201.4 KB
ID:	1693

    Hint: Before you can place a block, you need to create an instance of the Block type. Use the following code: let newBlock = Block(). Place a block by calling the place method on the world instance, and passing in all required arguments. Two possible coordinates for the block are (2,2) and (3,3).

    The best answer solution for this Uniting Worlds lesson is shown below:

    Code:
    let block1 = Block()
    world.place(block1, atColumn: 3, row: 3)
    
    while !isOnClosedSwitch {
     moveForward()
     if isBlocked {
      turnLeft()
      if isBlocked {
       turnRight()
       turnRight()
      }
     }
    }
    toggleSwitch()
    Incredible! You now have the power to add blocks to the world. How awesome is that? As you move on, you'll continue to learn new ways to manipulate the puzzle world with code.

    Next lesson is "Connect and Solve".

  • #2
     

    Comment


    • #3
      Code:
      let block1 = Block()
      
      world.place(block1, atColumn: 3, row: 3)
      
      
      
      
      while !isOnClosedSwitch {
      
          moveForward()
      
          if isBlockedRight && isBlocked {
      
              turnLeft()
      
          } else if isBlockedLeft && isBlocked {
      
              turnRight()
      
          }
      
      }
      
      toggleSwitch()

      Comment

      Working...
      X