/* Rexx Workshop - "Modified" Black Jack */ /* Card List */ Cards.2 = 2 Cards.3 = 3 Cards.4 = 4 Cards.5 = 5 Cards.6 = 6 Cards.7 = 7 Cards.8 = 8 Cards.9 = 9 Cards.10= 10 Cards.11= J Cards.12= Q Cards.13= K Cards.14= A /* Explain the game including revised rules */ say "Let's play Black Jack!" say " " say "In our version of the game:" say "a) The dealer will have a hand with a total between 16 and 21" say "b) Aces are worth 11, unless they raise your total to > 21;" say " then they are worth 1. The value of aces cannot change once" say " assigned." say " " say "Let's see if you can beat the dealer!" say " " /* Randomly set the dealer's total between 16 and 21 */ dealer = RANDOM(16,21) /* Loop to call a subroutine to randomly draw first 2 cards */ card_total = 0 say "Your cards are ...." Do 2 Call Get_Card End /* Loop to display the player's total, prompt to see if */ /* the player wants an additional card, and call the */ /* subroutine to randomly draw another card if player */ /* replies "YES" */ /* */ /* Continue until one of the following conditions occurs: */ /* a) The player reaches 21; go compare to dealer's total */ /* b) The player exceeds 21; tell player they are busted */ /* c) The player replies something other than "YES" */ Do Forever say "Your total is" card_total say " " If card_total = 21 Then Leave say "Would you like another card? Answer YES to continue" pull hit_me If hit_me <> "YES" Then Leave Call Get_Card If card_total > 21 Then Do say "Your total is" card_total "- BUSTED!!" Exit End End /* Display the dealer's total, determine whether player has */ /* won or lost (ties lose), and display the result. */ say "The dealer has" dealer Select When card_total > dealer Then say "You WIN!!!" Otherwise say "Sorry the Dealer wins - maybe next time ..." End /* End the main program */ Exit /* Subroutine to generate a random number representing the */ /* entries in the list above, get the card entry matching */ /* the number generated, and add the card value to the */ /* player's total. */ /* */ /* Assign a value to the selected card as follows: */ /* 2-10 - value matches the card */ /* J,Q,K - value is 10 */ /* A - value is 11, or 1 if 11 raises total above 21 */ Get_Card: card_num = RANDOM(2,14) card = Cards.card_num say card If card='J' | card='K' | card='Q' Then card_value = 10 Else Select When card='A' Then Do card_value=11 If card_total + card_value > 21 Then card_value=1 End Otherwise card_value = card End card_total = card_total+card_value Return