vb.net - can someone help me to include aces into my blackjack program -


i have been trying create simple blackjack game user picks cards , decides whether hit or stick , if cards go above 21 lose. not know how add in aces program choose whether ace 1 or 11. please code

module module1  sub main()     dim cards(4, 13) integer      dim value integer     dim value2 integer     dim royal string     dim suit string     dim card1 integer     dim card2 integer     dim card3 integer     dim card4 integer     dim card5 integer     dim card6 integer     dim card7 integer     dim answer string     dim total integer      randomize()     value = (3 * rnd()) + 1     value2 = (11 * rnd()) + 1      'suits: 1= hearts     '2= diamonds     '3=spades     '4=clubs     cards(1, 1) = 2     cards(2, 1) = 2     cards(3, 1) = 2     cards(4, 1) = 2     cards(1, 2) = 3     cards(2, 2) = 3     cards(3, 2) = 3     cards(4, 2) = 3     cards(1, 3) = 4     cards(2, 3) = 4     cards(3, 3) = 4     cards(4, 3) = 4     cards(1, 4) = 5     cards(2, 4) = 5     cards(3, 4) = 5     cards(4, 4) = 5     cards(1, 5) = 6     cards(2, 5) = 6     cards(3, 5) = 6     cards(4, 5) = 6     cards(1, 6) = 7     cards(2, 6) = 7     cards(3, 6) = 7     cards(4, 6) = 7     cards(1, 7) = 8     cards(2, 7) = 8     cards(3, 7) = 8     cards(4, 7) = 8     cards(1, 8) = 9     cards(2, 8) = 9     cards(3, 8) = 9     cards(4, 8) = 9     cards(1, 9) = 10     cards(2, 9) = 10     cards(3, 9) = 10     cards(4, 9) = 10     'jacks     cards(1, 10) = 10     cards(2, 10) = 10     cards(3, 10) = 10     cards(4, 10) = 10     'queens     cards(1, 11) = 10     cards(2, 11) = 10     cards(3, 11) = 10     cards(4, 11) = 10     'kings     cards(1, 12) = 10     cards(2, 12) = 10     cards(3, 12) = 10     cards(4, 12) = 10        if value2 = 1         royal = "2"     elseif value2 = 2         royal = "3"     elseif value2 = 3         royal = "4"     elseif value2 = 4         royal = "5"     elseif value2 = 5         royal = "6"     elseif value2 = 6         royal = "7"     elseif value2 = 7         royal = "8"     elseif value2 = 8         royal = "9"     elseif value2 = 9         royal = "10"     elseif value2 = 10         royal = "jack"     elseif value2 = 11         royal = "queen"     elseif value2 = 12         royal = "king"       end if      if value = 1         suit = "hearts"     elseif value = 2         suit = "diamonds"     elseif value = 3         suit = "spades"     elseif value = 4         suit = "clubs"      end if     console.writeline("your first card {0} of {1}", royal, suit)     card1 = cards(value, value2)      value = (3 * rnd()) + 1     value2 = (11 * rnd()) + 1     if value2 = 1         royal = "2"     elseif value2 = 2         royal = "3"     elseif value2 = 3         royal = "4"     elseif value2 = 4         royal = "5"     elseif value2 = 5         royal = "6"     elseif value2 = 6         royal = "7"     elseif value2 = 7         royal = "8"     elseif value2 = 8         royal = "9"     elseif value2 = 9         royal = "10"     elseif value2 = 10         royal = "jack"     elseif value2 = 11         royal = "queen"     elseif value2 = 12         royal = "king"     end if     if value = 1         suit = "hearts"     elseif value = 2         suit = "diamonds"     elseif value = 3         suit = "spades"     elseif value = 4         suit = "clubs"     end if     console.writeline("your second card {0} of {1}", royal, suit)     card2 = cards(value, value2)     console.readkey()     total = card1 + card2     if total > 21         console.writeline("you lose")         console.readline()     else         console.writeline("do want hit or stick?")         answer = console.readline         if answer = "hit"             value = (3 * rnd()) + 1             value2 = (11 * rnd()) + 1             if value2 = 1                 royal = "2"             elseif value2 = 2                 royal = "3"             elseif value2 = 3                 royal = "4"             elseif value2 = 4                 royal = "5"             elseif value2 = 5                 royal = "6"             elseif value2 = 6                 royal = "7"             elseif value2 = 7                 royal = "8"             elseif value2 = 8                 royal = "9"             elseif value2 = 9                 royal = "10"             elseif value2 = 10                 royal = "jack"             elseif value2 = 11                 royal = "queen"             elseif value2 = 12                 royal = "king"             end if             if value = 1                 suit = "hearts"             elseif value = 2                 suit = "diamonds"             elseif value = 3                 suit = "spades"             elseif value = 4                 suit = "clubs"             end if             console.writeline("your card {0} of {1}", royal, suit)             card3 = cards(value, value2)             console.readkey()             total = card1 + card2 + card3             if total > 21                 console.writeline("you lose")                 console.readline()             else                 console.writeline("do want hit or stick?")                 answer = console.readline                 if answer = "hit"                     value = (3 * rnd()) + 1                     value2 = (11 * rnd()) + 1                     if value2 = 1                         royal = "2"                     elseif value2 = 2                         royal = "3"                     elseif value2 = 3                         royal = "4"                     elseif value2 = 4                         royal = "5"                     elseif value2 = 5                         royal = "6"                     elseif value2 = 6                         royal = "7"                     elseif value2 = 7                         royal = "8"                     elseif value2 = 8                         royal = "9"                     elseif value2 = 9                         royal = "10"                     elseif value2 = 10                         royal = "jack"                     elseif value2 = 11                         royal = "queen"                     elseif value2 = 12                         royal = "king"                     end if                     if value = 1                         suit = "hearts"                     elseif value = 2                         suit = "diamonds"                     elseif value = 3                         suit = "spades"                     elseif value = 4                         suit = "clubs"                     end if                       console.writeline("your card {0} of {1}", royal, suit)                     card4 = cards(value, value2)                     console.readkey()                     total = card1 + card2 + card3 + card4                     if total > 21                         console.writeline("you lose")                         console.readline()                     else                         console.writeline("do want hit or stick?")                         answer = console.readline                         if answer = "hit"                             value = (3 * rnd()) + 1                             value2 = (11 * rnd()) + 1                             if value2 = 1                                 royal = "2"                             elseif value2 = 2                                 royal = "3"                             elseif value2 = 3                                 royal = "4"                             elseif value2 = 4                                 royal = "5"                             elseif value2 = 5                                 royal = "6"                             elseif value2 = 6                                 royal = "7"                             elseif value2 = 7                                 royal = "8"                             elseif value2 = 8                                 royal = "9"                             elseif value2 = 9                                 royal = "10"                             elseif value2 = 10                                 royal = "jack"                             elseif value2 = 11                                 royal = "queen"                             elseif value2 = 12                                 royal = "king"                             end if                             if value = 1                                 suit = "hearts"                             elseif value = 2                                 suit = "diamonds"                             elseif value = 3                                 suit = "spades"                             elseif value = 4                                 suit = "clubs"                             end if                              console.writeline("your card {0} of {1}", royal, suit)                             card5 = cards(value, value2)                             console.readkey()                             total = card1 + card2 + card3 + card4 + card5                             if total > 21                                 console.writeline("you lose")                                 console.readline()                             else                                 console.writeline("do want hit or stick?")                                 answer = console.readline                                 if answer = "hit"                                     value = (3 * rnd()) + 1                                     value2 = (11 * rnd()) + 1                                     if value2 = 1                                         royal = "2"                                     elseif value2 = 2                                         royal = "3"                                     elseif value2 = 3                                         royal = "4"                                     elseif value2 = 4                                         royal = "5"                                     elseif value2 = 5                                         royal = "6"                                     elseif value2 = 6                                         royal = "7"                                     elseif value2 = 7                                         royal = "8"                                     elseif value2 = 8                                         royal = "9"                                     elseif value2 = 9                                         royal = "10"                                     elseif value2 = 10                                         royal = "jack"                                     elseif value2 = 11                                         royal = "queen"                                     elseif value2 = 12                                         royal = "king"                                     end if                                     if value = 1                                         suit = "hearts"                                     elseif value = 2                                         suit = "diamonds"                                     elseif value = 3                                         suit = "spades"                                     elseif value = 4                                         suit = "clubs"                                     end if                                       console.writeline("your card {0} of {1}", royal, suit)                                     card6 = cards(value, value2)                                     console.readkey()                                     total = card1 + card2 + card3 + card4 + card5 + card6                                     if total > 21                                         console.writeline("you lose")                                         console.readline()                                     else                                         console.writeline("do want hit or stick?")                                         answer = console.readline                                         if answer = "hit"                                             value = (3 * rnd()) + 1                                             value2 = (11 * rnd()) + 1                                             if value2 = 1                                                 royal = "2"                                             elseif value2 = 2                                                 royal = "3"                                             elseif value2 = 3                                                 royal = "4"                                             elseif value2 = 4                                                 royal = "5"                                             elseif value2 = 5                                                 royal = "6"                                             elseif value2 = 6                                                 royal = "7"                                             elseif value2 = 7                                                 royal = "8"                                             elseif value2 = 8                                                 royal = "9"                                             elseif value2 = 9                                                 royal = "10"                                             elseif value2 = 10                                                 royal = "jack"                                             elseif value2 = 11                                                 royal = "queen"                                             elseif value2 = 12                                                 royal = "king"                                             end if                                             if value = 1                                                 suit = "hearts"                                             elseif value = 2                                                 suit = "diamonds"                                             elseif value = 3                                                 suit = "spades"                                             elseif value = 4                                                 suit = "clubs"                                             end if                                              console.writeline("your card {0} of {1}", royal, suit)                                             card7 = cards(value, value2)                                             console.readkey()                                             total = card1 + card2 + card3 + card4 + card5 + card6 + card7                                         elseif answer = "stick"                                             console.writeline("your final score {0}", total)                                             console.readline()                                          end if                                     end if                                 end if                             end if                         end if                     end if                 end if             end if         end if     end if         end sub  end module 

use rule like: aces worth 11, unless total exceeds 21, worth 1. have recalculate total each ace in hand until total less or equal 21. might not optimal strategy, enough learning how code.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -