Last active
June 2, 2022 10:57
-
-
Save Vzhukov74/5510b167482bac4d63fd0492e3d2efe8 to your computer and use it in GitHub Desktop.
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
struct GameView: View { | |
@StateObject var viewModel = GameViewModel(riddle: Ridle.defaultRiddle(), keys: Keys.defaultKeys()) | |
var body: some View { | |
Group { | |
ZStack { | |
GeometryReader { geo in | |
if viewModel.gameState == .loading { | |
EmptyView() | |
} else { | |
board(width: geo.size.width) | |
} | |
} | |
switch viewModel.gameState { | |
case .win: | |
EmptyView() | |
case .lose: | |
EmptyView() | |
case .waitingForNewRidle: | |
EmptyView() | |
default: EmptyView() | |
} | |
} | |
} | |
.onAppear { | |
viewModel.load() | |
} | |
} | |
private func board(width: CGFloat) -> some View { | |
VStack { | |
BoardView(words: viewModel.riddle.words) | |
.padding(.horizontal, 26) | |
Spacer(minLength: 0) | |
KeyboardView(keys: viewModel.keys, | |
width: width - 8, | |
onTap: viewModel.onTap, | |
onEnter: viewModel.onEnter, | |
onRemove: viewModel.onRemove) | |
.padding(.horizontal, 4) | |
}.padding(.vertical, 16) | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
GameView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment