feat: added global quiz score
This commit is contained in:
@@ -9,15 +9,60 @@ import SwiftUI
|
||||
|
||||
struct CategorySelectionView: View {
|
||||
@ObservedObject var viewModel = ViewModel()
|
||||
@AppStorage("globalScore") var globalScore: Int = 0
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
VStack(spacing: 24) {
|
||||
// Minimaler Header
|
||||
Text("Quiz Kategorien")
|
||||
.font(.title)
|
||||
.fontWeight(.bold)
|
||||
.padding(.top)
|
||||
// Willkommensnachricht
|
||||
VStack(spacing: 8) {
|
||||
Text("Willkommen!")
|
||||
.font(.largeTitle)
|
||||
.fontWeight(.bold)
|
||||
.foregroundColor(.primary)
|
||||
|
||||
Text("Wähle eine Kategorie und teste dein Wissen")
|
||||
.font(.subheadline)
|
||||
.foregroundColor(.secondary)
|
||||
.multilineTextAlignment(.center)
|
||||
}
|
||||
.padding(.top)
|
||||
|
||||
// Punktestand
|
||||
HStack {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text("Deine Punkte")
|
||||
.font(.caption)
|
||||
.foregroundColor(.secondary)
|
||||
Text("\(globalScore)")
|
||||
.font(.title2)
|
||||
.fontWeight(.bold)
|
||||
.foregroundColor(.blue)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
Image(systemName: "star.fill")
|
||||
.foregroundColor(.orange)
|
||||
.font(.title2)
|
||||
}
|
||||
.padding()
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 12)
|
||||
.fill(Color(.systemGray6))
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 12)
|
||||
.stroke(Color(.systemGray4), lineWidth: 1)
|
||||
)
|
||||
)
|
||||
.padding(.horizontal)
|
||||
|
||||
// Kategorien Header
|
||||
Text("Verfügbare Quiz")
|
||||
.font(.title2)
|
||||
.fontWeight(.semibold)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding(.horizontal)
|
||||
|
||||
// Liste der Kategorien
|
||||
VStack(spacing: 12) {
|
||||
@@ -60,7 +105,7 @@ struct CategorySelectionView: View {
|
||||
}
|
||||
.background(Color.white)
|
||||
.navigationBarHidden(true)
|
||||
.navigationTitle("Quiz-Auswahl")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,13 @@
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import AudioToolbox
|
||||
|
||||
struct ContentView: View {
|
||||
|
||||
@ObservedObject var viewModel = ViewModel()
|
||||
@AppStorage("globalScore") var score: Int = 0
|
||||
@Environment(\.dismiss) var dismiss
|
||||
|
||||
@State private var selectedAnswerIndex: Int? = nil
|
||||
@State private var isAnswered = false
|
||||
@@ -33,13 +36,16 @@ struct ContentView: View {
|
||||
.cornerRadius(10)
|
||||
|
||||
Button("Zurück zur Kategorieauswahl") {
|
||||
viewModel.selectedCategory = nil
|
||||
dismiss()
|
||||
}
|
||||
.padding()
|
||||
.background(Color.gray)
|
||||
.foregroundColor(.white)
|
||||
.cornerRadius(10)
|
||||
}
|
||||
.onAppear {
|
||||
AudioServicesPlaySystemSound(1322)
|
||||
}
|
||||
} else if let frage = viewModel.currentQuestion {
|
||||
Text("Punkte: \(viewModel.score)")
|
||||
.font(.headline)
|
||||
@@ -76,6 +82,9 @@ struct ContentView: View {
|
||||
viewModel.incrementScore(selectedIndex: index)
|
||||
viewModel.answeredCount += 1
|
||||
viewModel.selectedAnswers[viewModel.currentQuestionIndex] = index
|
||||
if index == frage.correctAnswer {
|
||||
score += 1
|
||||
}
|
||||
}) {
|
||||
Text(frage.answers[index])
|
||||
.padding(.vertical, 12)
|
||||
@@ -158,9 +167,6 @@ struct ContentView: View {
|
||||
let correct = viewModel.questions[index].correctAnswer
|
||||
return selected == correct ? .green : .red
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#Preview {
|
||||
|
||||
Reference in New Issue
Block a user