From eba8a2fc6220efaee564259ffb79ac60e12ed8ea Mon Sep 17 00:00:00 2001 From: jiulinxiri Date: Tue, 24 Dec 2024 09:19:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=B8=E6=88=8F=E7=BB=93=E6=9D=9F=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Twinmoji/ContentView.swift | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Twinmoji/ContentView.swift b/Twinmoji/ContentView.swift index 63ebe79..80863c6 100644 --- a/Twinmoji/ContentView.swift +++ b/Twinmoji/ContentView.swift @@ -33,6 +33,8 @@ struct ContentView: View { var answerTime: Double @Binding var isGameActive: Bool + @State private var playerHasWon = false + var body: some View { HStack(spacing: 0) { PlayerButton(gameState: gameState, score: player1Score, color: .blue, onSelect: selectPlayer1) @@ -59,6 +61,17 @@ struct ContentView: View { .background(Color(white: 0.9)) .persistentSystemOverlays(.hidden) .onAppear(perform: createLevel) + .alert("Game Over!", isPresented: $playerHasWon) { + Button("Start Again") { + isGameActive = false + } + } message: { + if player1Score > player2Score { + Text("Player 1 Won \(player1Score) - \(player2Score)") + } else { + Text("Player 2 Won \(player2Score) - \(player1Score)") + } + } } func createLevel() { @@ -114,7 +127,7 @@ struct ContentView: View { } if player1Score == 5 || player2Score == 5 { - // + playerHasWon = true } else { createLevel() }