Spoof game: Difference between revisions

Content added Content deleted
(→‎{{header|REXX}}: added the REXX computer programming language for this task.)
Line 657: Line 657:
"player3: 18 12"}
"player3: 18 12"}
pot:12, player2 buys the drinks!
pot:12, player2 buys the drinks!
</pre>

=={{header|REXX}}==
<lang rexx>/*REXX program plays the "spoof" game with a human player (does presentation & scoring).*/
parse arg seed .; if datatype(seed, 'W') then call random ,,seed /*use RANDOM seed? */
__= copies('─', 9) /*literal used in the game's prompting.*/

do forever /*$ = computer; @ = human or CBLF. */
do until $pot+3<$g; $pot = random(0, 3) /*get a computer number for the pot. */
$g = random(0, 6) /* " " " " " " guess. */
end /*until*/
say
say copies('─', 55); say __ "The computer has got a pot and a guess."
@pot= 0
@pot= prompt(__ 'What is your pot? (or QUIT)' )
@g= prompt(__ 'What is your guess? (or QUIT)', .)
say __ "The computer's pot is: " $pot
say __ "The computer's guess is: " $g
pot= $pot + @pot
say
select
when $g==pot & @g==pot then say __ 'This game is a draw.'
when $g==pot then say __ 'This game won by the computer.'
when @g==pot then say __ 'This game won by you. Congratulations!'
otherwise say __ 'This game has no winner.'
end /*select*/
end /*forever*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
prompt: do forever; er= __ '***error*** '; say arg(1); parse pull # y . 1 _,?
upper #; if abbrev('QUIT', #, 1) then exit 1 /*user wants to quit? */
if #=='' then do; say er "no argument entered." ; iterate; end
if y\=='' then do; say er "too many arguments:" _; iterate; end
if \datatype(#,'N') then do; say er "argument isn't numeric:" #; iterate; end
if \datatype(#,'W') then do; say er "argument isn't an integer:" #; iterate; end
if ?==. & @pot+3>=# then do; say er "illegal input for guess:" #; iterate; end
#= # / 1; return #
end /*forever*/</lang>
{{out|output|text=:}}
<pre>
───────────────────────────────────────────────────────
───────── The computer has got a pot and a guess.
───────── What is your pot? (or QUIT)
1 ◄■■■■■■■■■■■ user input.
───────── What is your guess? (or QUIT)
2 ◄■■■■■■■■■■■ user input.
───────── The computer's pot is: 1
───────── The computer's guess is: 6

───────── This game won by you. Congratulations!

───────────────────────────────────────────────────────
───────── The computer has got a pot and a guess.
───────── What is your pot? (or QUIT)
3 ◄■■■■■■■■■■■ user input.
───────── What is your guess? (or QUIT)
4 ◄■■■■■■■■■■■ user input.
───────── The computer's pot is: 2
───────── The computer's guess is: 6

───────── This game has no winner.

───────────────────────────────────────────────────────
───────── The computer has got a pot and a guess.
───────── What is your pot? (or QUIT)
4 ◄■■■■■■■■■■■ user input.
───────── What is your guess? (or QUIT)
2 ◄■■■■■■■■■■■ user input.
───────── The computer's pot is: 1
───────── The computer's guess is: 5

───────── This game won by the computer.

───────────────────────────────────────────────────────
───────── The computer has got a pot and a guess.
───────── What is your pot? (or QUIT)
q ◄■■■■■■■■■■■ user input.
</pre>
</pre>