Pig the dice game: Difference between revisions
Content added Content deleted
(added MiniScript example) |
|||
Line 2,378: | Line 2,378: | ||
Button["Play again.", |
Button["Play again.", |
||
roundscore = 0; (score@# = 0) & /@ players]]}]</lang> |
roundscore = 0; (score@# = 0) & /@ players]]}]</lang> |
||
=={{header|Object}}== |
|||
<lang MiniScript>// Pig the Dice for two players. |
|||
Player = {} |
|||
Player.score = 0 |
|||
Player.doTurn = function() |
|||
rolls = 0 |
|||
pot = 0 |
|||
print self.name + "'s Turn!" |
|||
while true |
|||
if self.score + pot >= goal then |
|||
print " " + self.name.upper + " WINS WITH " + (self.score + pot) + "!" |
|||
inp = "H" |
|||
else |
|||
inp = input(self.name + ", you have " + pot + " in the pot. [R]oll or Hold? ") |
|||
end if |
|||
if inp == "" or inp[0].upper == "R" then |
|||
die = ceil(rnd*6) |
|||
if die == 1 then |
|||
print " You roll a 1. Busted!" |
|||
return |
|||
else |
|||
print " You roll a " + die + "." |
|||
pot = pot + die |
|||
end if |
|||
else |
|||
self.score = self.score + pot |
|||
return |
|||
end if |
|||
end while |
|||
end function |
|||
p1 = new Player |
|||
p1.name = "Alice" |
|||
p2 = new Player |
|||
p2.name = "Bob" |
|||
goal = 100 |
|||
while p1.score < goal and p2.score < goal |
|||
for player in [p1, p2] |
|||
print |
|||
print p1.name + ": " + p1.score + " | " + p2.name + ": " + p2.score |
|||
player.doTurn |
|||
if player.score >= goal then break |
|||
end for |
|||
end while</lang> |
|||
{{out}} |
|||
<pre>Alice: 0 | Bob: 0 |
|||
Alice's Turn! |
|||
Alice, you have 0 in the pot. [R]oll or Hold? |
|||
You roll a 4. |
|||
Alice, you have 4 in the pot. [R]oll or Hold? |
|||
You roll a 5. |
|||
Alice, you have 9 in the pot. [R]oll or Hold? |
|||
You roll a 5. |
|||
Alice, you have 14 in the pot. [R]oll or Hold? h |
|||
Alice: 14 | Bob: 0 |
|||
Bob's Turn! |
|||
Bob, you have 0 in the pot. [R]oll or Hold? |
|||
You roll a 6. |
|||
Bob, you have 6 in the pot. [R]oll or Hold? |
|||
You roll a 4. |
|||
Bob, you have 10 in the pot. [R]oll or Hold? |
|||
You roll a 4. |
|||
Bob, you have 14 in the pot. [R]oll or Hold? |
|||
You roll a 6. |
|||
Bob, you have 20 in the pot. [R]oll or Hold? h |
|||
Alice: 14 | Bob: 20 |
|||
Alice's Turn! |
|||
Alice, you have 0 in the pot. [R]oll or Hold? |
|||
You roll a 1. Busted! |
|||
... |
|||
Alice: 49 | Bob: 90 |
|||
Bob's Turn! |
|||
Bob, you have 0 in the pot. [R]oll or Hold? |
|||
You roll a 5. |
|||
Bob, you have 5 in the pot. [R]oll or Hold? |
|||
You roll a 3. |
|||
Bob, you have 8 in the pot. [R]oll or Hold? |
|||
You roll a 6. |
|||
BOB WINS WITH 104!</pre> |
|||
=={{header|Objeck}}== |
=={{header|Objeck}}== |
||
<lang objeck> |
<lang objeck> |