Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
45
Task/Pig-the-dice-game/Maple/pig-the-dice-game.maple
Normal file
45
Task/Pig-the-dice-game/Maple/pig-the-dice-game.maple
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
pig := proc()
|
||||
local Points, pointsThisTurn, answer, rollNum, i, win;
|
||||
randomize();
|
||||
Points := [0, 0];
|
||||
win := [false, 0];
|
||||
while not win[1] do
|
||||
for i to 2 do
|
||||
if not win[1] then
|
||||
printf("Player %a's turn.\n", i);
|
||||
answer := "";
|
||||
pointsThisTurn := 0;
|
||||
while not answer = "HOLD" do
|
||||
while not answer = "ROLL" and not answer = "HOLD" do
|
||||
printf("Would you like to ROLL or HOLD?\n");
|
||||
answer := StringTools:-UpperCase(readline());
|
||||
if not answer = "ROLL" and not answer = "HOLD" then
|
||||
printf("Invalid answer.\n\n");
|
||||
end if;
|
||||
end do;
|
||||
if answer = "ROLL" then
|
||||
rollNum := rand(1..6)();
|
||||
printf("You rolled a %a!\n", rollNum);
|
||||
if rollNum = 1 then
|
||||
pointsThisTurn := 0;
|
||||
answer := "HOLD";
|
||||
else
|
||||
pointsThisTurn := pointsThisTurn + rollNum;
|
||||
answer := "";
|
||||
printf("Your points so far this turn: %a.\n\n", pointsThisTurn);
|
||||
end if;
|
||||
end if;
|
||||
end do;
|
||||
printf("This turn is over! Player %a gained %a points this turn.\n\n", i, pointsThisTurn);
|
||||
Points[i] := Points[i] + pointsThisTurn;
|
||||
if Points[i] >= 100 then
|
||||
win := [true, i];
|
||||
end if;
|
||||
printf("Player 1 has %a points. Player 2 has %a points.\n\n", Points[1], Points[2]);
|
||||
end if;
|
||||
end do;
|
||||
end do;
|
||||
printf("Player %a won with %a points!\n", win[2], Points[win[2]]);
|
||||
end proc;
|
||||
|
||||
pig();
|
||||
Loading…
Add table
Add a link
Reference in a new issue