Spoof game: Difference between revisions

m
(Spoof game in FreeBASIC)
m (→‎{{header|Wren}}: Minor tidy)
 
(One intermediate revision by one other user not shown)
Line 9:
=={{header|C}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <time.h>
Line 147:
}
return 0;
}</langsyntaxhighlight>
 
{{output}}
Line 199:
=={{header|FreeBASIC}}==
{{trans|Julia}}
<langsyntaxhighlight lang="freebasic">Function PideEntero(texto As String) As Integer
Dim As Integer mon
While true
Line 247:
Color 15: Print "Another round? (Press X to exit, or another key to continue)"
Loop Until (Ucase(Input(1)) = "X")
End</langsyntaxhighlight>
 
 
=={{header|Go}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 393:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 447:
=={{header|Julia}}==
{{trans|Ring}}
<langsyntaxhighlight lang="julia">function queryint(prompt)
while true
print("\n", prompt, " (supply an integer) => ")
Line 490:
 
spoofgamefortwo()
</langsyntaxhighlight>{{out}}
<pre>
How many games do you want? (supply an integer) => 2
Line 513:
=={{header|Kotlin}}==
This program has a TEST mode. If you set it to true, the number of coins allocated to each player for each round won't be erased after he/she presses ENTER, which allows you to check it is working out the total for the round correctly.
<langsyntaxhighlight lang="scala">// Version 1.2.40
 
import java.util.Random
Line 601:
round++
}
}</langsyntaxhighlight>
 
{{output}}
Line 677:
=={{header|Nim}}==
{{trans|Kotlin}}
<langsyntaxhighlight Nimlang="nim">import math, random, sequtils, strformat, strutils, terminal
 
const Test = true
Line 767:
 
randomize()
play()</langsyntaxhighlight>
 
{{out}}
Line 825:
=={{header|Perl}}==
{{trans|Julia}}
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 864:
}
 
spoof_for_2();</langsyntaxhighlight>
{{out}}
<pre>How many games do you want? 1
Line 875:
 
=={{header|Phix}}==
<langsyntaxhighlight Phixlang="phix">function get_number(string prompt, integer lo, hi, pot, bool show=false)
if show then prompt &= sprintf(" from %d to %d",{lo,hi}) end if
printf(1,prompt&" : ")
Line 946:
{} = wait_key()
end procedure
main()</langsyntaxhighlight>
{{out}}
<pre>
Line 980:
(formerly Perl 6)
{{trans|Perl}}
<syntaxhighlight lang="raku" perl6line>sub query_for_integer ($prompt) { loop { ($_ = prompt "$prompt ") ~~ /^ \d+ $/ ?? return $_ !! say '(need an integer)'; } }
 
sub spoof_for_2 {
Line 1,010:
}
 
spoof_for_2();</langsyntaxhighlight>
{{out}}
<pre>How many games do you want? 1
Line 1,024:
 
A little extra code was added to add verbiage for various error conditions.
<langsyntaxhighlight 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.*/
Line 1,058:
if ?==. & @pot+3>=# then do; say er "illegal input for guess:" #; iterate; end
#= # / 1; return #
end /*forever*/</langsyntaxhighlight>
{{out|output|text=:}}
<pre>
Line 1,101:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Spoof game
 
Line 1,147:
ok
next
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,181:
{{libheader|Wren-ioutil}}
{{libheader|Wren-math}}
<langsyntaxhighlight ecmascriptlang="wren">import "random" for Random
import "./ioutil" for Input, Output, Stdin
import "./math" for Nums
 
var TEST = true // set to 'false' to erase each player's coins
Line 1,256:
first = (index2 < remaining.count - 1) ? remaining[index2 + 1] : remaining[0]
round = round + 1
}</langsyntaxhighlight>
 
{{out}}
Line 1,316:
=={{header|zkl}}==
{{trans|Ring}}
<langsyntaxhighlight lang="zkl">do(getNum("How many games you want? ")){
reg mypot,yourpot,myguess,yourguess;
do{ mypot,myguess = (0).random(4),(0).random(7); // 0..3, 0..6
Line 1,338:
try{ return(ask(msg).strip().toInt()) }
catch{ println("ack"); return(self.fcn(msg)) } // tail recursion
}</langsyntaxhighlight>
{{out}}
<pre style="height:35ex">
9,483

edits