From f11528609317aa21ed68d19a2da8f27987690b25 Mon Sep 17 00:00:00 2001 From: jiulinxiri Date: Tue, 24 Dec 2024 05:13:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20CardView?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Twinmoji/ContentView.swift | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) 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 {