Jump to content

Pig the dice game: Difference between revisions

m (→‎{{header|Ring}}: Remove vanity tags)
Line 2,669:
 
Player #2 wins with a score of 22!</pre>
 
=={{header|Phix}}==
Initially a translation of [[Pig_the_dice_game#Lua|Lua]], but now quite different.
<lang Phix>constant numPlayers = 2,
maxScore = 100
sequence scores = repeat(0,numPlayers)
printf(1,"\nPig The Dice Game\n\n")
integer points = 0, -- points accumulated in current turn, 0=swap turn
player = 1 -- start with first player
while true do
integer roll = rand(6)
printf(1,"Player %d, your score is %d, you rolled %d. ",{player,scores[player],roll})
if roll=1 then
printf(1," Too bad. :(\n")
points = 0 -- swap turn
else
points += roll
if scores[player]+points>=maxScore then exit end if
printf(1,"Round score %d. Roll or Hold?",{points})
integer reply = upper(wait_key())
printf(1,"%c\n",{reply})
if reply == 'H' then
scores[player] += points
points = 0 -- swap turn
end if
end if
if points=0 then
player = mod(player,numPlayers) + 1
end if
end while
printf(1,"\nPlayer %d wins with a score of %d!\n",{player,scores[player]+points})</lang>
{{out}}
<pre>
Pig The Dice Game
 
Player 1, your score is 0, you rolled 2. Round score 2. Roll or Hold?R
Player 1, your score is 0, you rolled 5. Round score 7. Roll or Hold?R
Player 1, your score is 0, you rolled 3. Round score 10. Roll or Hold?R
Player 1, your score is 0, you rolled 4. Round score 14. Roll or Hold?H
Player 2, your score is 0, you rolled 5. Round score 5. Roll or Hold?R
Player 2, your score is 0, you rolled 1. Too bad. :(
Player 1, your score is 14, you rolled 3. Round score 3. Roll or Hold?H
...
Player 2, your score is 86, you rolled 3. Round score 9. Roll or Hold?R
Player 2, your score is 86, you rolled 6.
Player 2 wins with a score of 101!
</pre>
 
=={{header|PHP}}==
7,818

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.