21 game: Difference between revisions
m
Undo revision 338856 by Walterpachl (talk)
Walterpachl (talk | contribs) m (→{{header|REXX}}: it's -> its) |
Walterpachl (talk | contribs) m (Undo revision 338856 by Walterpachl (talk)) |
||
Line 5,006:
This REXX version allows the user to choose if the computer should go first.
<lang rexx>/*REXX program plays the 21 game with a human, each player chooses 1, 2, or 3 which */
/*
sep= copies('
say sep 'Playing the 21 game.' /*tell what's happening here at the zoo*/
$=0; goal= 21 /*the sum [or running total] (so far).*/
Line 5,014:
if $==goal then leave /*the user won the game with the last #*/
call ?; if y==. then y= random(1, 3) /*get computer's choice or a random #*/
say sep 'The computer chooses ' y " as
call tot y, 0 /*call subroutine to show the total. */
end /*j*/
Line 5,021:
else say sep 'The computer has won the 21 game.'
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
?: y=.; do c=1 for 3 until y\==.; if (c+$) // 4 == 1 then y= c; end; return
ser: if bad then return; bad=1; say; say; say sep '***error***' arg(1); say; return
tot: arg q,who; $=$+q; say sep 'The game total is now' sep2 $ sep2; /*add; show $*/ return
/*──────────────────────────────────────────────────────────────────────────────────────*/
g: low = (j \== 1) /*allow user to have computer go first.*/
do until \bad; bad= 0; say /*prompt 'til user gives a good number.*/
say sep 'Please enter a number from ' low "
if j=1 then say sep '[A value of 0 (zero) means you want the computer to go first.]'
parse pull x _ . 1 ox; upper x /*obtain user's lowercase response(s). */
Line 5,044:
{{out|output|text=''':'''}}
<pre>
3
3
3
3
1
</pre>
|