tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
18
Task/Pig-the-dice-game/Mathematica/pig-the-dice-game.math
Normal file
18
Task/Pig-the-dice-game/Mathematica/pig-the-dice-game.math
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
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]]}]
|
||||
Loading…
Add table
Add a link
Reference in a new issue