diff --git a/Twinmoji/ContentView.swift b/Twinmoji/ContentView.swift index 55b95ab..92e12c8 100644 --- a/Twinmoji/ContentView.swift +++ b/Twinmoji/ContentView.swift @@ -41,8 +41,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) @@ -102,6 +102,33 @@ struct ContentView: View { 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 {