21 game: Difference between revisions

1,176 bytes removed ,  2 years ago
m
m (→‎{{header|REXX}}: it's -> its)
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 */
/*────────────------------ is added to the current sum, the first player to reach 21 exactly wins.*/
sep= copies('-', 8); sep2= " "copies('-', 8)" " /*construct an eye─catchingeye-catching msg fences.*/
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 it'sits choice." /*inform player.*/
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 " ───►---? 3 (or Quit):"
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>
────────-------- Playing the 21 game.
 
────────-------- Please enter a number from 0 ───►---? 3 (or Quit):
────────-------- [A value of 0 (zero) means you want the computer to go first.]
3 ◄■■■■■■■■■■?¦¦¦¦¦¦¦¦¦¦ user input
────────-------- The game total is now ════════-------- 3 ════════--------
────────-------- The computer chooses 2 as it'sits choice.
────────-------- The game total is now ════════-------- 5 ════════--------
 
────────-------- Please enter a number from 1 ───►---? 3 (or Quit):
3 ◄■■■■■■■■■■?¦¦¦¦¦¦¦¦¦¦ user input
────────-------- The game total is now ════════-------- 8 ════════--------
────────-------- The computer chooses 1 as it'sits choice.
────────-------- The game total is now ════════-------- 9 ════════--------
 
────────-------- Please enter a number from 1 ───►---? 3 (or Quit):
3 ◄■■■■■■■■■■?¦¦¦¦¦¦¦¦¦¦ user input
────────-------- The game total is now ════════-------- 12 ════════--------
────────-------- The computer chooses 1 as it'sits choice.
────────-------- The game total is now ════════-------- 13 ════════--------
 
────────-------- Please enter a number from 1 ───►---? 3 (or Quit):
3 ◄■■■■■■■■■■?¦¦¦¦¦¦¦¦¦¦ user input
────────-------- The game total is now ════════-------- 16 ════════--------
────────-------- The computer chooses 1 as it'sits choice.
────────-------- The game total is now ════════-------- 17 ════════--------
 
────────-------- Please enter a number from 1 ───►---? 3 (or Quit):
1 ◄■■■■■■■■■■?¦¦¦¦¦¦¦¦¦¦ user input
────────-------- The game total is now ════════-------- 18 ════════--------
────────-------- The computer chooses 3 as it'sits choice.
────────-------- The game total is now ════════-------- 21 ════════--------
 
────────-------- The computer has won the 21 game.
</pre>
 
2,295

edits