Spoof game: Difference between revisions
Content added Content deleted
m (→{{header|zkl}}: attribution) |
m (→{{header|zkl}}: opps) |
||
Line 92: | Line 92: | ||
reg mypot,yourpot,myguess,yourguess; |
reg mypot,yourpot,myguess,yourguess; |
||
do{ mypot,myguess = (0).random(4),(0).random(7); // 0..3, 0..6 |
do{ mypot,myguess = (0).random(4),(0).random(7); // 0..3, 0..6 |
||
}while(mypot + 3 |
}while(mypot + 3 <= myguess); |
||
println("I have put my pot and guess."); |
println("I have put my pot and guess."); |
||
while(True){ |
while(True){ |
||
Line 101: | Line 101: | ||
println("Bad input! Try again"); |
println("Bad input! Try again"); |
||
} |
} |
||
⚫ | |||
pot:=mypot + yourpot; |
pot:=mypot + yourpot; |
||
⚫ | |||
if(myguess==pot==yourguess) println("Draw!\n"); |
if(myguess==pot==yourguess) println("Draw!\n"); |
||
else if(myguess==pot) println("I won!\n"); |
else if(myguess==pot) println("I won!\n"); |
||
Line 114: | Line 114: | ||
{{out}} |
{{out}} |
||
<pre style="height:35ex"> |
<pre style="height:35ex"> |
||
How many games you want? 4 |
How many games you want? 4 |
||
I have put my pot and guess. |
I have put my pot and guess. |
||
Your pot? 2 |
Your pot? 2 |
||
Your guess? |
Your guess? 3 |
||
⚫ | |||
Bad input! Try again |
|||
Your pot? 3 |
|||
Your guess? 4 |
|||
⚫ | |||
You won! |
You won! |
||
I have put my pot and guess. |
I have put my pot and guess. |
||
Your pot? |
Your pot? 1 |
||
Your guess? 0 |
Your guess? 0 |
||
My |
My pot is: 2. My guess is: 3. Pot is 3 |
||
⚫ | |||
⚫ | |||
I have put my pot and guess. |
I have put my pot and guess. |
||
Your pot? |
Your pot? 4 |
||
Your guess? |
Your guess? 5 |
||
My |
My pot is: 1. My guess is: 1. Pot is 5 |
||
You won! |
|||
No winner! |
|||
I have put my pot and guess. |
I have put my pot and guess. |
||
Your pot? |
Your pot? 2 |
||
Your guess? |
Your guess? 1 |
||
My |
My pot is: 3. My guess is: 2. Pot is 5 |
||
⚫ | |||
⚫ | |||
</pre> |
</pre> |
Revision as of 04:03, 23 April 2018
Spoof game is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Create Spoof game. See details: Spoof game
Ring
<lang ring>
- Project : Spoof game
- Date : 2018/04/22
- Author : Gal Zsolt (~ CalmoSoft ~)
- Email : <calmosoft@gmail.com>
spoof = 0:6 see "How many games you want? " give games
for n = 1 to games
while true mypot = random(3) myguess = random(6) if mypot + 3 >= myguess loop else exit ok end see "I have put my pot and guess" + nl while true see "Your pot? " give yourpot see "Your guess? " give yourguess if ascii(yourpot) < 48 or ascii(yourpot) > 54 or ascii(yourguess) < 48 or ascii(yourguess) > 54 loop ok if yourpot + 3 >= yourguess exit else see "Bad input! Try again" + nl loop ok end see "My put is: " + mypot + nl see "My guess is: " + myguess + nl pot = mypot + yourpot if myguess = pot and yourguess = pot see "Draw!" + nl elseif myguess = pot see "I won!" + nl elseif yourguess = pot see "You won!" + nl else see "No winner!" + nl ok
next </lang> Output:
How many games you want? 4 I have put my pot and guess Your pot? 1 Your guess? 3 My put is: 2 My guess is: 6 You won! I have put my pot and guess Your pot? 1 Your guess? 4 My put is: 2 My guess is: 5 No winner! I have put my pot and guess Your pot? 3 Your guess? 6 My put is: 3 My guess is: 6 Draw! I have put my pot and guess Your pot? 2 Your guess? 4 My put is: 0 My guess is: 5 No winner!
zkl
<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 }while(mypot + 3 <= myguess); println("I have put my pot and guess."); while(True){ yourpot =getNum("Your pot? "); yourguess=getNum("Your guess? "); if(((0<=yourpot<=6) and (0<=yourguess<=6)) and yourpot + 3 >= yourguess) break; println("Bad input! Try again"); } pot:=mypot + yourpot; println("My pot is: ",mypot, ". My guess is: ",myguess, ". Pot is ",pot); if(myguess==pot==yourguess) println("Draw!\n"); else if(myguess==pot) println("I won!\n"); else if(yourguess==pot) println("You won!\n"); else println("No winner!\n");
} fcn getNum(msg){
try{ return(ask(msg).strip().toInt()) } catch{ println("ack"); return(self.fcn(msg)) } // tail recursion
}</lang>
- Output:
How many games you want? 4 I have put my pot and guess. Your pot? 2 Your guess? 3 My pot is: 1. My guess is: 0. Pot is 3 You won! I have put my pot and guess. Your pot? 1 Your guess? 0 My pot is: 2. My guess is: 3. Pot is 3 I won! I have put my pot and guess. Your pot? 4 Your guess? 5 My pot is: 1. My guess is: 1. Pot is 5 You won! I have put my pot and guess. Your pot? 2 Your guess? 1 My pot is: 3. My guess is: 2. Pot is 5 No winner!