Module AceyDucey Dim Running As Boolean Dim GameOver As Boolean Dim Wallet As Integer Dim Bet As Integer Dim Cards(3) As Integer Dim Rnd As Random Function AskQuestion(prompt As String) Dim gotAns As Boolean = False Dim ans As String While Not gotAns Console.WriteLine($"{prompt} ?") ans = Console.ReadLine If String.IsNullOrWhiteSpace(ans) Then Console.WriteLine("PLEASE ANSWER THE QUESTION.") Else gotAns = True End If End While Return ans.ToUpper() End Function Function GetIntInput(prompt As String) Dim gotVal As Boolean = False Dim value As Integer While Not gotVal Dim ans As String Console.WriteLine($"{prompt} :") ans = Console.ReadLine If Not Integer.TryParse(ans, value) Then Console.WriteLine("YOU DID NOT ENTER AN INTEGER.") Else gotVal = True End If End While Return value End Function Sub AskForBet() Dim gotBet As Boolean = False While Not gotBet Bet = GetIntInput("WHAT IS YOUR BET") If Bet < 0 Then Console.WriteLine("PLEASE BET A NON-NEGATIVE NUMBER.") ElseIf Bet > Wallet Then Console.WriteLine("SORRY MY FRIEND, BUT YOU BET TOO MUCH.") Console.WriteLine($"YOU HAVE ONLY {Wallet} DOLLARS TO BET.") Else gotBet = True End If End While End Sub Function AskToPlayAgain() Dim gotAns As Boolean = False Dim answer As Boolean While Not gotAns Dim ans As String ans = AskQuestion("DO YOU WANT TO PLAY AGAIN") If ans = "YES" Or ans = "Y" Then gotAns = True answer = True ElseIf ans = "NO" Or ans = "N" Then gotAns = True answer = False Else Console.WriteLine("PLEASE ANSWER ""YES"" OR ""NO""") End If End While Return answer End Function Function AskToSeeTheRules() Dim gotAns As Boolean = False Dim answer As Boolean While Not gotAns Dim ans As String ans = AskQuestion("DO YOU WANT TO SEE THE RULES") If ans = "YES" Or ans = "Y" Then gotAns = True answer = True ElseIf ans = "NO" Or ans = "N" Then gotAns = True answer = False Else Console.WriteLine("PLEASE ANSWER ""YES"" OR ""NO""") End If End While Return answer End Function Sub DisplayCard(card As Integer) If card = 11 Then Console.WriteLine("JACK") ElseIf card = 12 Then Console.WriteLine("QUEEN") ElseIf card = 13 Then Console.WriteLine("KING") ElseIf card = 14 Then Console.WriteLine("ACE") Else Console.WriteLine($"{card}") End If End Sub Sub DisplayRules() Console.WriteLine($"ACEY DUCEY Is PLAYED IN THE FOLLOWING MANNER") Console.WriteLine($"THE DEALER(COMPUTER) DEALS TWO CARDS FACE UP") Console.WriteLine($"YOU HAVE THE OPTION TO BET Or Not BET DEPENDING") Console.WriteLine($"On WHETHER Or Not YOU FEEL THE NEXT CARD WILL ") Console.WriteLine($"HAVE A VALUE BETWEEN THE FIRST TWO.") Console.WriteLine($"") Console.WriteLine($"If YOU DO NOT WANT TO BET, INPUT A 0(ZERO).") End Sub Function GenerateRandomNumber(minimum As Integer, maximum As Integer, show As Boolean) Dim value As Integer value = Rnd.Next(minimum, maximum) If show Then Console.WriteLine($"{value}") End If Return value End Function Function SelectCard() Dim card As Integer Dim gotCard As Boolean = False While Not gotCard card = GenerateRandomNumber(2, 15, False) If Cards(0) <> card And Cards(1) <> card And Cards(2) <> card Then DisplayCard(card) gotCard = True End If End While Return card End Function Sub ClearCards() Cards(0) = 0 Cards(1) = 0 Cards(2) = 0 End Sub Sub Main() Rnd = New Random(Environment.TickCount) Console.WriteLine("*** ACEY DUCEY : VB .NET ***") If AskToSeeTheRules() Then DisplayRules() End If Running = True While Running Wallet = 100 GameOver = False While Not GameOver Console.WriteLine($"YOU NOW HAVE {Wallet} DOLLARS.") ClearCards() Cards(0) = SelectCard() Cards(1) = SelectCard() AskForBet() If Bet > 0 Then Cards(2) = SelectCard() If (Cards(2) > Cards(0) And Cards(2) < Cards(1)) Or (Cards(2) > Cards(1) And Cards(2) < Cards(0)) Then Console.WriteLine("YOU WIN!!!") Wallet = Wallet + Bet Else Console.WriteLine("SORRY, YOU LOSE.") Wallet = Wallet - Bet End If If Wallet < 1 Then Console.WriteLine("SORRY FRIEND, YOU ARE BROKE.") GameOver = True End If Else GameOver = True End If End While Console.WriteLine("*** GAME OVER ***") Running = AskToPlayAgain() End While Console.WriteLine("OK, HOPE YOU HAD FUN.") Console.WriteLine("THANKS FOR PLAYING!") Console.ReadLine() End Sub End Module