RosettaCodeData/Task/Pig-the-dice-game/Mathematica/pig-the-dice-game.math
Ingy döt Net b83f433714 tasks a-s
2013-04-10 23:57:08 -07:00

18 lines
786 B
Text

DynamicModule[{score, players = {1, 2}, roundscore = 0,
roll}, (score@# = 0) & /@ players;
Panel@Dynamic@
Column@{Grid[
Prepend[{#, score@#} & /@ players, {"Player", "Score"}],
Background -> {None, 2 -> Gray}], roundscore,
If[ValueQ@roll, Row@{"Rolled ", roll}, ""],
If[IntegerQ@roundscore,
Row@{Button["Roll", roll = RandomInteger[{1, 6}];
If[roll == 1, roundscore = 0; players = RotateLeft@players,
roundscore += roll]],
Button["Hold", score[players[[1]]] += roundscore;
roundscore = 0;
If[score[players[[1]]] >= 100, roll =.;
roundscore = Row@{players[[1]], " wins."},
players = RotateLeft@players]]},
Button["Play again.",
roundscore = 0; (score@# = 0) & /@ players]]}]