Created
July 19, 2012 01:36
Revisions
-
M Parker revised this gist
Aug 13, 2013 . 1 changed file with 15 additions and 6 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,13 +12,22 @@ def roll(num = 1, sides = 6, bonus = 0) # - 1d4 # - d4 def parse_command(command = "") # Split up the command. prefix_parts = command.split(/d/) suffix_parts = prefix_parts[1].split(/\+|-/) # The number of dice. num = prefix_parts[0].empty? ? 1 : prefix_parts[0].to_i # The type of dice. sides = suffix_parts[0].to_i # Bonus. bonus = suffix_parts[1].empty? ? 0 : suffix_parts[1].to_i # Tell the user what we're doing so if they mistyped it, they're not # confused. $stdout.write(sprintf("Rolling %d x %d-sided dice with bonus %d.", num, sides, bonus)) return roll(num, sides, bonus) end -
M Parker revised this gist
Aug 13, 2013 . 1 changed file with 8 additions and 9 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,8 @@ #!/usr/bin/ruby def roll(num = 1, sides = 6, bonus = 0) # Rand returns a number between 1 and the argument. return (rand(sides-1) + 1 + bonus) * num; end # Parse a string in the following forms: @@ -12,14 +12,13 @@ def roll(num = 1, sides = 6, bonus = 0) # - 1d4 # - d4 def parse_command(command = "") parts = command.split(/d/) # The number of dice num = to_i(command_halves[0]) command_quarters = command_halves[1].split(/+/) # The type of dice # type = command_quarters[ end -
M Parker created this gist
Jul 19, 2012 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ #!/usr/bin/ruby def roll(num = 1, sides = 6, bonus = 0) # Rand returns a number between 1 and the argument. return (rand(sides-1) + 1 + bonus) * num; end # Parse a string in the following forms: # - 1d4+1 or 1d4-1 # - d4+1 or d4-1 # - +1 or -1 # - 1d4 # - d4 def parse_command(command = "") parts = command.split(/d/) # The number of dice num = to_i(command_halves[0]) command_quarters = command_halves[1].split(/+/) # The type of dice type = command_quarters[ end