添加菜单视图

This commit is contained in:
2024-12-24 05:51:34 +08:00
parent 125d979636
commit e134deb11d
3 changed files with 70 additions and 3 deletions

View File

@@ -30,6 +30,8 @@ struct ContentView: View {
@State private var answerAnchor = UnitPoint.center
var itemCount: Int
var answerTime: Double
@Binding var isGameActive: Bool
var body: some View {
HStack(spacing: 0) {
@@ -96,7 +98,7 @@ struct ContentView: View {
func runClock() {
answerScale = 1
withAnimation(.linear(duration: 1)) {
withAnimation(.linear(duration: answerTime)) {
answerScale = 0
} completion: {
timeOut()
@@ -132,5 +134,5 @@ struct ContentView: View {
}
#Preview {
ContentView(itemCount: 9)
ContentView(itemCount: 9, answerTime: 2, isGameActive: .constant(true))
}

64
Twinmoji/MenuView.swift Normal file
View File

@@ -0,0 +1,64 @@
//
// MenuView.swift
// Twinmoji
//
// Created by Zhang Mengxu on 2024/12/24.
//
import SwiftUI
struct MenuView: View {
@State private var timeOut = 1.0
@State private var items = 9
@State private var isGameActive = false
var body: some View {
if isGameActive {
ContentView(itemCount: items, answerTime: timeOut, isGameActive: $isGameActive)
} else {
VStack(spacing: 10) {
Text("Twinmoji")
.font(.largeTitle)
.fontDesign(.rounded)
Text("Answer Time")
.font(.headline)
Picker("Timeout", selection: $timeOut) {
Text("Slow").tag(2.0)
Text("Medium").tag(1.0)
Text("Fast").tag(0.5)
}
.pickerStyle(.segmented)
.padding(.bottom)
Text("Diffculty")
.font(.headline)
Picker("Diffculty", selection: $items) {
Text("Easy").tag(9)
Text("Hard").tag(12)
}
.pickerStyle(.segmented)
Button("Start Game") {
isGameActive = true
}
.buttonStyle(.borderedProminent)
}
.padding()
.background(.white)
.clipShape(.rect(cornerRadius: 20))
.shadow(radius: 10)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.padding()
.background(Color(white: 0.9))
}
}
}
#Preview {
MenuView()
}

View File

@@ -11,7 +11,8 @@ import SwiftUI
struct TwinmojiApp: App {
var body: some Scene {
WindowGroup {
ContentView(itemCount: 9)
MenuView()
.preferredColorScheme(.light)
}
}
}