Greed: Difference between revisions
Content added Content deleted
(Add Factor) |
m (→{{header|REXX}}: added/changed comments and whitespace, ensured scope of HALT.) |
||
Line 984:
<lang rexx>/*REXX program lets a user play the game of GREED (by Matthew Day) from the console. */
parse arg sw sd @ b ?r . /*obtain optional argumenst from the CL*/
if sw=='' | sw=="," then sw=
if sd=='' | sd=="," then sd=
if @=='' | @=="," then @= '@' /*here " " " " " */
if b=='' | b=="," then b= ' ' /*blank " " " " " */
Line 991:
if length(@)==2 & datatype(@,'X') then @=x2c(@) /*maybe use @ char for current pos. */
if length(b)==2 & datatype(b,'X') then b=x2c(b) /* " " B char for background. */
call init /* [↓] CLR is reset if there's an err*/
clr=1; do until # == sw*sd; ??= /*keep playing until the grid is blank.*/
call show clr /*show the playing field (grid) to term*/
call ask; clr=
if \move() then do; clr=
if ??==@. then say ____ "invalid move: moving out of bounds."
if ??==b then say ____ "invalid move: moving into a blank."
Line 1,011 ⟶ 1,012:
say ____
say ____ 'enter a move ──or── QUIT (the score is: ' #")"
parse pull z 2 1 what . 1 oz; upper z what
if abbrev('QUIT', what, 2) | abbrev(
if length( space(oz) )==1 & pos(z, 'QWEADZXC')\==0 then return
say ____ '***error*** invalid direction for a move:' space(oz); say
Line 1,018 ⟶ 1,019:
halt: say; say ____ 'quitting.'; exit 1
/*──────────────────────────────────────────────────────────────────────────────────────*/
init: @.= 'ff'x; $.=.; ____= copies(
▲ signal on halt /*handle pressing of Ctrl-Break key. */
do r=1 for sd
do c=1 for sw; @.r.c= random(1, 9)
end /*c*/
end /*r*/
!r= random(1, sd); !c= random(1, sw); @.!r.!c= @; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
move: @.!r.!c= '≤'; $r= !r; $c= !c; ??=
@@=. /*nullify the count of move positions. */
do until @@==0;
?= @.!r.!c; if ?==@. | ?==b then do; !r= $r; !c= $c; ??= ?; return 0
if @@==. then @@=?; if datatype(@@, 'W') then @@= @@ - 1
@.!r.!c= '±' /*nullify (later, a blank) position. */
end /*until*/
@.!r.!c= @; return 1
/*──────────────────────────────────────────────────────────────────────────────────────*/
show: arg tell; #=0; if tell then do;
do r=1 for sd; _= ' ' /* [↑] DOS cmd CLS clears the screen*/
do c=1 for sw /*construct row of the grid for display*/
if @.r.c==
if @.r.c==
if @.r.c==
if @.r.c==
?= @.r.c;
if ?==b | ?==@ then #= # + 1
if tell then $.r.c= @.r.c
end /*c*/
if r==!r then _= _ '◄'
if tell then say _ /*display a row of grid to screen. */
end /*r*/; say;
A note on the OUTPUT sections: each (cleared) screen displayed is shown below as a separate OUTPUT section.
|