tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
|
|
@ -0,0 +1,12 @@
|
|||
DynamicModule[{record, play, text = "\nRock-paper-scissors\n",
|
||||
choices = {"Rock", "Paper", "Scissors"}},
|
||||
Evaluate[record /@ choices] = {1, 1, 1};
|
||||
play[x_] :=
|
||||
Module[{y = RandomChoice[record /@ choices -> RotateLeft@choices]},
|
||||
record[x]++;
|
||||
text = "Your Choice:" <> x <> "\nComputer's Choice:" <> y <> "\n" <>
|
||||
Switch[{x, y}, Alternatives @@ Partition[choices, 2, 1, 1],
|
||||
"You lost.",
|
||||
Alternatives @@ Reverse /@ Partition[choices, 2, 1, 1],
|
||||
"You win.", _, "Draw."]];
|
||||
Column@{Dynamic[text], ButtonBar[# :> play[#] & /@ choices]}]
|
||||
Loading…
Add table
Add a link
Reference in a new issue