3
|
1 //
|
|
2 // GameAlertsModifier.swift
|
|
3 // GeoQuiz
|
|
4 //
|
|
5 // Created by Dennis Concepción Martín on 22/9/22.
|
|
6 //
|
|
7
|
|
8 import SwiftUI
|
|
9
|
|
10 struct GameAlertsModifier<T: Game>: ViewModifier {
|
|
11 @ObservedObject var game: T
|
7
|
12 @Environment(\.dismiss) var dismiss
|
3
|
13
|
|
14 func body(content: Content) -> some View {
|
|
15 content
|
|
16 .alert(game.alertTitle, isPresented: $game.showingWrongAnswerAlert) {
|
8
|
17 Button("Continue", role: .cancel) {
|
|
18 game.askQuestion {
|
|
19 game.selector()
|
|
20 }
|
|
21 }
|
3
|
22 } message: {
|
|
23 Text(game.alertMessage)
|
|
24 }
|
|
25
|
7
|
26 .alert(game.alertTitle, isPresented: $game.showingGameOverAlert) {
|
8
|
27 Button("Try again") {
|
|
28 game.reset {
|
|
29 game.selector()
|
|
30 }
|
|
31 }
|
7
|
32 Button("Exit", role: .cancel) { dismiss()}
|
3
|
33 } message: {
|
|
34 Text(game.alertMessage)
|
|
35 }
|
|
36
|
|
37 .alert(game.alertTitle, isPresented: $game.showingEndGameAlert) {
|
8
|
38 Button("Play again") {
|
|
39 game.reset() {
|
|
40 game.selector()
|
|
41 }
|
|
42 }
|
7
|
43 Button("Exit", role: .cancel) { dismiss() }
|
3
|
44 } message: {
|
|
45 Text(game.alertMessage)
|
|
46 }
|
4
|
47
|
|
48 .alert("Are you sure?", isPresented: $game.showingExitGameAlert) {
|
7
|
49 Button("Exit", role: .destructive) { dismiss() }
|
4
|
50 Button("Cancel", role: .cancel) { }
|
|
51 } message: {
|
7
|
52 Text("Progress won't be saved.")
|
4
|
53 }
|
3
|
54 }
|
|
55 }
|