修改 CardView
This commit is contained in:
@@ -41,8 +41,8 @@ struct ContentView: View {
|
|||||||
|
|
||||||
if leftCard.isEmpty == false {
|
if leftCard.isEmpty == false {
|
||||||
HStack {
|
HStack {
|
||||||
CardView(card: leftCard)
|
CardView(card: leftCard, userCanAnswer: gameState != .waiting, onSelect: checkAnswer)
|
||||||
CardView(card: rightCard)
|
CardView(card: rightCard, userCanAnswer: gameState != .waiting, onSelect: checkAnswer)
|
||||||
|
|
||||||
}
|
}
|
||||||
.padding(.horizontal, 10)
|
.padding(.horizontal, 10)
|
||||||
@@ -102,6 +102,33 @@ struct ContentView: View {
|
|||||||
timeOut()
|
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 {
|
#Preview {
|
||||||
|
Reference in New Issue
Block a user