Advertisement
Der_Teufel

Dice in Knight

Sep 20th, 2022 (edited)
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. ## Roll one die
  2. # Arguments:
  3. # n_sides
  4. ; = roll_die BLOCK
  5. ; = roll % RANDOM n_sides
  6. : IF ? roll 0 = roll n_sides roll
  7.  
  8. ## Roll many dice
  9. # Arguments:
  10. # n_dice n_sides
  11. # Changes:
  12. # n_dice
  13. ; = roll_dice BLOCK
  14. ; = rolls @
  15. ; WHILE > n_dice 0
  16. ; = rolls + rolls , CALL roll_die
  17. : = n_dice - n_dice 1
  18. : rolls
  19.  
  20. ## Main function
  21. ; = main BLOCK
  22. ; OUTPUT "Input dice command:"
  23. ; = input PROMPT
  24. ; = n_dice +0 input
  25. ; WHILE ! ? 'd' [input
  26. : = input ]input
  27. ; = input ]input
  28. ; = n_sides +0 input
  29. ; IF | < n_dice 1 < n_sides 1
  30. ; OUTPUT "Both numbers must be positive integers!"
  31. : QUIT 1
  32. NULL
  33. ; CALL roll_dice
  34. ; OUTPUT "You rolled:"
  35. ; OUTPUT "[ \"
  36. ; = sum 0
  37. ; WHILE LENGTH rolls
  38. ; OUTPUT ++ "" [rolls "\"
  39. ; = sum + sum [rolls
  40. ; = rolls ]rolls
  41. : IF LENGTH rolls
  42. OUTPUT ", \"
  43. NULL
  44. ; OUTPUT " ]"
  45. : OUTPUT + "Sum: " sum
  46.  
  47. : CALL main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement