Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Roll one die
- # Arguments:
- # n_sides
- ; = roll_die BLOCK
- ; = roll % RANDOM n_sides
- : IF ? roll 0 = roll n_sides roll
- ## Roll many dice
- # Arguments:
- # n_dice n_sides
- # Changes:
- # n_dice
- ; = roll_dice BLOCK
- ; = rolls @
- ; WHILE > n_dice 0
- ; = rolls + rolls , CALL roll_die
- : = n_dice - n_dice 1
- : rolls
- ## Main function
- ; = main BLOCK
- ; OUTPUT "Input dice command:"
- ; = input PROMPT
- ; = n_dice +0 input
- ; WHILE ! ? 'd' [input
- : = input ]input
- ; = input ]input
- ; = n_sides +0 input
- ; IF | < n_dice 1 < n_sides 1
- ; OUTPUT "Both numbers must be positive integers!"
- : QUIT 1
- NULL
- ; CALL roll_dice
- ; OUTPUT "You rolled:"
- ; OUTPUT "[ \"
- ; = sum 0
- ; WHILE LENGTH rolls
- ; OUTPUT ++ "" [rolls "\"
- ; = sum + sum [rolls
- ; = rolls ]rolls
- : IF LENGTH rolls
- OUTPUT ", \"
- NULL
- ; OUTPUT " ]"
- : OUTPUT + "Sum: " sum
- : CALL main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement