module Rules::Dice

Module to define the possible rolls

Public Class Methods

prompt_roll(type_of_roll) click to toggle source

A small prompt to require a roll o perfomr a random roll

# File data/rpg-prompt/rules_default.rb, line 74
def self.prompt_roll(type_of_roll)
  case type_of_roll
  when :d6
    roll_prompt = :ask_for_d6
    roll_limit = 6
  else
    roll_prompt = :ask_for_d10
    roll_limit = 10
  end
  roll = 0
  Message.message(:preset_roll_prompt)
  case Keypress.read_char
  when "r"
    Message.message(roll_prompt)
    loop do
      roll = $stdin.gets.to_i
      if (roll > roll_limit) || (roll <= 0)
        Message.message(:bad_range)
        redo
      else
        Message.help(:rolling, {roll: roll})
      end
      break
    end
  else
    roll = Dice.roll(type_of_roll)
    Message.help(:rolling, {roll: roll})
  end
  roll
end
roll(type_of_roll) click to toggle source

The roll itself

# File data/rpg-prompt/rules_default.rb, line 64
def self.roll(type_of_roll)
  case type_of_roll
  when :d6
    1+rand(6)
  when :d10
    1+rand(10)
  end
end