Answer Key
Heads up... You’re accessing parts of this content for free, with some sections shown as
text.
Heads up... You’re accessing parts of this content for free, with some sections shown as
text.Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.
Unlock now
Your final code should look something like this:
import SwiftUI
struct ContentView: View {
@State var playerRow = 0
@State var playerCol = 7
var body: some View {
Text("Player Location: \(playerRow), \(playerCol)")
Spacer()
VStack {
Text("🟩🟩🟩🟩🟩🟩🟩🐰🟩🟩🟩🟩🟩🟩🟩🟩")
Text("🟩🟧🟧🟧🟧🟧🟧🟧🟩🟧🟧🟧🟧🟧🟧🟩")
Text("🟩🟩🟩🟩🟩🟩🟩🟧🟩🟩🟩🟩🟩🟩🟧🟩")
Text("🟩🟧🟧🟧🟧🟧🟩🟧🟧🟧🟧🟧🟧🟧🟧🟩")
Text("🟩🟧🟩🟩🟩🟧🟩🟩🟩🟩🟩🟩🟩🟩🟧🟩")
Text("🟩🟩🟩🟩🟩🟧🟧🟧🟧🟧🟧🟧🟧🟧🟧🟩")
Text("🟩🟧🟧🟧🟧🟧🟩🟩🟩🟩🟧🟩🟧🟩🟧🟩")
Text("🟩🟧🟩🟩🟩🟧🟩🟧🟧🟧🟧🟩🟧🟩🟧🟩")
Text("🟩🟧🟧🟧🟩🟧🟩🟩🟩🟩🟩🟩🟩🟩🟧🟩")
Text("🟩🟩🟩🟧🟩🟩🟩🟩🟩🟩🟩🟧🟧🟧🟧🟩")
Text("🟩🟩🟩🟧🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩")
}
Spacer()
HStack {
Button {
playerRow -= 1
} label: {
Text("⬆️").font(.system(size: 50))
}
Button {
playerRow += 1
} label: {
Text("⬇️").font(.system(size: 50))
}
Button {
playerCol -= 1
} label: {
Text("⬅️").font(.system(size: 50))
}
Button {
playerCol += 1
} label: {
Text("➡️").font(.system(size: 50))
}
}
Spacer()
}
}