The challenge of this lesson is to build an island surrounded by a sea.
Tired of being landlocked? Use code to create your very own island!
First, create two empty arrays that each store an array of coordinates. One will store coordinates for the island, and the other will store coordinates for the sea.
Next, write a set of conditions within your if statement to append coordinates to your island array. These coordinates should be in the center of the map, and might be a 3x3 or 4x4 block. Append any coordinates that don't meet these conditions to your sea array.
Adding water:
To add water, remove existing items first.
world.removeItems(at: coordinate)
world.place(Water(), at: coordinate)
After you've appended coordinates to each array, place blocks for each coordinate in the island array, and water coordinates in the sea array. Good luck!

Hint: You can create an empty array of coordinates like this: var island: [Coordinate] = []. This code creates a new variable that stores an array of coordinates, initialized with no items. After you create your island and sea arrays, write conditions for your if statement that determine if a coordinate is in the island region of the world. For example, you might want to append any coordinate with both the column and row greater than 3 and less than 7.
Your powers are growing! With arrays, you can manage a lot of information quickly and efficiently to create amazing worlds.
Did you notice how the array allCoordinates was initialized? You can use the all possibleCoordinates property of the world instance to give you an array of all the coordinates in the puzzle world. This lets you iterate over every coordinate. How cool is that?
Next we will be looking at "Appending Removed Values".
Tired of being landlocked? Use code to create your very own island!
First, create two empty arrays that each store an array of coordinates. One will store coordinates for the island, and the other will store coordinates for the sea.
Next, write a set of conditions within your if statement to append coordinates to your island array. These coordinates should be in the center of the map, and might be a 3x3 or 4x4 block. Append any coordinates that don't meet these conditions to your sea array.
Adding water:
To add water, remove existing items first.
world.removeItems(at: coordinate)
world.place(Water(), at: coordinate)
After you've appended coordinates to each array, place blocks for each coordinate in the island array, and water coordinates in the sea array. Good luck!
Hint: You can create an empty array of coordinates like this: var island: [Coordinate] = []. This code creates a new variable that stores an array of coordinates, initialized with no items. After you create your island and sea arrays, write conditions for your if statement that determine if a coordinate is in the island region of the world. For example, you might want to append any coordinate with both the column and row greater than 3 and less than 7.
Code:
let allCoordinates = world.allPossibleCoordinates //Create two empty arrays of type [Coordinate]. var island: [Coordinate] = [] var sea: [Coordinate] = [] for coordinate in allCoordinates { if coordinate.column > 3 && coordinate.column < 7 && coordinate.row > 3 && coordinate.row < 7 { // Append to island array. island.append(coordinate) } else { // Append to sea array. sea.append(coordinate) } } // For your island array, place blocks. for coordinate in island { world.place(Block(), at:coordinate) } // For your sea array, place water. for coordinate in sea { world.removeItems(at: coordinate) world.place(Water(), at: coordinate) }
Did you notice how the array allCoordinates was initialized? You can use the all possibleCoordinates property of the world instance to give you an array of all the coordinates in the puzzle world. This lets you iterate over every coordinate. How cool is that?
Next we will be looking at "Appending Removed Values".
Comment