Number reversal game: Difference between revisions

m
→‎{{header|REXX}}: added/changed comments and whitespace, used a template for the OUTPUTs.
m (→‎{{header|REXX}}: added/changed comments and whitespace, used a template for the OUTPUTs.)
Line 2,846:
:::*   allows the user to enter   '''quit'''
:::*   allows the user to halt the game via   '''Cntl-Break'''   (or equivalent)
<lang rexx>/*REXX pgmprogram (a game): reverse a jumbled set of numeralsdecimal digits until'til they're in order.*/
signal on halt /*allows the CBLF to HALT the program.*/
___= copies('─', 9); pad=left('', 9) /*a fence used for computer's messages.*/
say ___ "This game will show you nine random unique digits (1 ──► 9), and you'll enter"
say ___ "enter "one of those digits which will reverse all the digits upfrom tothe left-most (anddigit"
say ___ "up to (and including) that decimal digit. The game's objective is to get all the"
say ___ "of the digits in ascending order with the fewest tries. Here are're your digits:"
ok= 123456789 /*the result that the string should be.*/
$= /* ◄─── decimal target to be generated.*/
$=
do until length($)==9; _=random(1, 9) /*build a random unique numeric string.*/
_=random(1,9); if pos(_, $) \== 0 then iterate /*onlyUnique? Only use a digdecimal digit once.*/
$=$ || _ /*construct a string of unique digits. */
if $==ok then $= /*string can't be in order, start over.*/
end /*until ··· */
 
do score=1 until $==ok; say /* [↓] display the digsdigits and& the prompt*/
say; say ___ $ right('please enter a digit (or Quit):', 50)
parse pull xox .; ?=left(x,1) ux . 1 x .; upper ux /*get a decimal digit (maybe) from CBLF*/
if abbrev('QUIT',x ux, 1) then signal halt /*does the CBLF want to quit this game?*/
if length(x)>1 then do; say ___ pad 'oops,***error*** invalid input!: ' xox; iterate; end
if x=='' then iterate /*try again, CBLF didn't enter anything*/
g=pos(?x, $) /*validate if the input digit is legal.*/
if g==0 then say ___ pad 'oops,***error*** invalid digit!: ' ? ox
else $=strip(reverse(left($, g))substr($, g+1)) /*reverse some (or all) digits*/
end /*score*/
 
say; say ___ $; say; say center(' Congratulations! ', 70, "═"); say
say ___ pad 'Your score was' score; exit /*stick a fork in it, we're all done. */
halt: say ___ pad 'quitting.'; exit /* " " " " " " " " */</lang>
'''{{out|output''' |text=&nbsp; from playing one game of the &nbsp; ''number reversal game'':
<pre>
───────── This game will show you nine random unique digits (1 ──► 9), and you'll enter
───────── enter one of those digits which will reverse all the digits upfrom tothe left-most (anddigit
───────── up to (and including) that decimal digit. The game's objective is to get all the
───────── of the digits in ascending order with the fewest tries. Here are're your digits:
 
───────── 613279548 please enter a digit (or Quit):
Line 2,922:
══════════════════════════ Congratulations! ══════════════════════════
 
───────── Your score was 12
</pre>