Compare commits
4 Commits
9ec4bfe937
...
e134deb11d
Author | SHA1 | Date | |
---|---|---|---|
e134deb11d | |||
125d979636 | |||
f91b4e4e78 | |||
f115286093 |
@@ -39,6 +39,8 @@ struct CardView: View {
|
||||
.fixedSize()
|
||||
.shadow(radius: 10)
|
||||
.disabled(userCanAnswer == false)
|
||||
.transition(.push(from: .top))
|
||||
.id(card)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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) {
|
||||
@@ -41,8 +43,8 @@ struct ContentView: View {
|
||||
|
||||
if leftCard.isEmpty == false {
|
||||
HStack {
|
||||
CardView(card: leftCard)
|
||||
CardView(card: rightCard)
|
||||
CardView(card: leftCard, userCanAnswer: gameState != .waiting, onSelect: checkAnswer)
|
||||
CardView(card: rightCard, userCanAnswer: gameState != .waiting, onSelect: checkAnswer)
|
||||
|
||||
}
|
||||
.padding(.horizontal, 10)
|
||||
@@ -63,7 +65,7 @@ struct ContentView: View {
|
||||
currentEmoji = allEmoji.shuffled()
|
||||
withAnimation(.spring(duration: 0.75)) {
|
||||
leftCard = Array(currentEmoji[0..<itemCount]).shuffled()
|
||||
rightCard = Array(currentEmoji[itemCount + 1 ..< itemCount + itemCount] + [currentEmoji[0]]).shuffled()
|
||||
rightCard = Array(currentEmoji[itemCount + 1..<itemCount + itemCount] + [currentEmoji[0]]).shuffled()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,14 +98,41 @@ struct ContentView: View {
|
||||
func runClock() {
|
||||
answerScale = 1
|
||||
|
||||
withAnimation(.linear(duration: 1)) {
|
||||
withAnimation(.linear(duration: answerTime)) {
|
||||
answerScale = 0
|
||||
} completion: {
|
||||
timeOut()
|
||||
}
|
||||
}
|
||||
|
||||
func checkAnswer(_ string: String) {
|
||||
if string == currentEmoji[0] {
|
||||
if gameState == .player1Answering {
|
||||
player1Score += 1
|
||||
} else if gameState == .player2Answering {
|
||||
player2Score += 1
|
||||
}
|
||||
|
||||
if player1Score == 5 || player2Score == 5 {
|
||||
//
|
||||
} else {
|
||||
createLevel()
|
||||
}
|
||||
} else {
|
||||
if gameState == .player1Answering {
|
||||
player1Score -= 1
|
||||
} else if gameState == .player2Answering {
|
||||
player2Score -= 1
|
||||
}
|
||||
}
|
||||
|
||||
answerColor = .clear
|
||||
answerScale = 0
|
||||
gameState = .waiting
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#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 {
|
||||
var body: some Scene {
|
||||
WindowGroup {
|
||||
ContentView(itemCount: 9)
|
||||
MenuView()
|
||||
.preferredColorScheme(.light)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user