From d4eff0d774b68d9a6567aba67e27c18f5c48ddb5 Mon Sep 17 00:00:00 2001 From: CrystalMoogle Date: Sun, 16 Jul 2023 16:10:48 +0100 Subject: [PATCH] Replace this with a switch statement, make it easier to read --- BlackjackGUI/game.vb | 51 +++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/BlackjackGUI/game.vb b/BlackjackGUI/game.vb index 86c4f42..a12951b 100644 --- a/BlackjackGUI/game.vb +++ b/BlackjackGUI/game.vb @@ -141,35 +141,28 @@ RaiseEvent EndGame(winMessage) End Sub Function GetResults() - If dealer.winType = WinCondition.Blackjack Then - If player.winType = WinCondition.Blackjack Then - Return "Player ties with Blackjack!" - Else - Return "Dealer wins with Blackjack!" - End If - End If - If player.winType = WinCondition.Blackjack Then - Return "Player wins with Blackjack!" - End If - If player.winType = WinCondition.FiveCard Then - Return "Player wins with Five Card Charlie!" - End If - If player.winType = WinCondition.Bust Then - Return "Player busts!" - End If - If dealer.winType = WinCondition.Bust Then - Return "Dealer busts!" - End If - If player.total > dealer.total Then - Return "Player wins with total of " + player.total.ToString() + "!" - End If - If player.total = dealer.total Then - Return "Tie!" - End If - If player.total < dealer.total Then - Return "Dealer wins with total of " + dealer.total.ToString() + "!" - End If - Return "error" + Select Case True + Case dealer.winType = WinCondition.Blackjack + If player.winType = WinCondition.Blackjack Then + Return "Player ties with Blackjack!" + Else + Return "Dealer wins with Blackjack!" + End If + Case player.winType = WinCondition.Blackjack + Return "Player wins with Blackjack!" + Case player.winType = WinCondition.FiveCard + Return "Player wins with Five Card Charlie!" + Case player.winType = WinCondition.Bust + Return "Player busts!" + Case dealer.winType = WinCondition.Bust + Return "Dealer busts!" + Case player.total > dealer.total + Return "Player wins with a total of " & player.total.ToString() & "!" + Case player.total = dealer.total + Return "Tie!" + Case Else + Return "Dealer wins with a total of " & dealer.total.ToString() & "!" + End Select End Function Function CreateDeck() As List(Of Tuple(Of String, String)) Dim response As New List(Of Tuple(Of String, String))