添加菜单视图
This commit is contained in:
@@ -30,6 +30,8 @@ struct ContentView: View {
|
|||||||
@State private var answerAnchor = UnitPoint.center
|
@State private var answerAnchor = UnitPoint.center
|
||||||
|
|
||||||
var itemCount: Int
|
var itemCount: Int
|
||||||
|
var answerTime: Double
|
||||||
|
@Binding var isGameActive: Bool
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
HStack(spacing: 0) {
|
HStack(spacing: 0) {
|
||||||
@@ -96,7 +98,7 @@ struct ContentView: View {
|
|||||||
func runClock() {
|
func runClock() {
|
||||||
answerScale = 1
|
answerScale = 1
|
||||||
|
|
||||||
withAnimation(.linear(duration: 1)) {
|
withAnimation(.linear(duration: answerTime)) {
|
||||||
answerScale = 0
|
answerScale = 0
|
||||||
} completion: {
|
} completion: {
|
||||||
timeOut()
|
timeOut()
|
||||||
@@ -132,5 +134,5 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
ContentView(itemCount: 9)
|
ContentView(itemCount: 9, answerTime: 2, isGameActive: .constant(true))
|
||||||
}
|
}
|
||||||
|
64
Twinmoji/MenuView.swift
Normal file
64
Twinmoji/MenuView.swift
Normal 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()
|
||||||
|
}
|
@@ -11,7 +11,8 @@ import SwiftUI
|
|||||||
struct TwinmojiApp: App {
|
struct TwinmojiApp: App {
|
||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
WindowGroup {
|
WindowGroup {
|
||||||
ContentView(itemCount: 9)
|
MenuView()
|
||||||
|
.preferredColorScheme(.light)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user