-
Notifications
You must be signed in to change notification settings - Fork 12
/
ContentView.swift
31 lines (28 loc) · 985 Bytes
/
ContentView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import SwiftUI
struct ContentView: View {
@ObservedObject var gameManager = GameManager(gridSize: 4)
var body: some View {
VStack {
ScoreView(score: gameManager.score, highScore: gameManager.highScore)
GridView(grid: gameManager.grid, gridSize: gameManager.gridSize)
.gesture(DragGesture()
.onEnded { gesture in
handleSwipe(direction: gesture.direction)
}
)
}
.padding()
.alert(isPresented: $gameManager.showGameOver) {
Alert(
title: Text("Game Over"),
message: Text("You scored \(gameManager.score) points!"),
dismissButton: .default(Text("Restart")) {
gameManager.restartGame()
}
)
}
}
private func handleSwipe(direction: SwipeDirection) {
gameManager.swipe(direction: direction)
}
}