Class: BCDice::CommonCommand::TallyDice::Node::Dice

Inherits:
Object
  • Object
show all
Defined in:
lib/bcdice/common_command/tally_dice/node.rb

Overview

個数カウントダイス:ダイスのノード

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(times:, sides:, show_zeros:) ⇒ Dice

Returns a new instance of Dice.

Parameters:

  • times (Integer)

    振る回数

  • sides (Integer)

    面数



108
109
110
111
112
# File 'lib/bcdice/common_command/tally_dice/node.rb', line 108

def initialize(times:, sides:, show_zeros:)
  @times = times
  @sides = sides
  @show_zeros = show_zeros
end

Instance Attribute Details

#show_zerosBoolean (readonly) Also known as: show_zeros?

Returns 個数0を表示するか.

Returns:

  • (Boolean)

    個数0を表示するか



102
103
104
# File 'lib/bcdice/common_command/tally_dice/node.rb', line 102

def show_zeros
  @show_zeros
end

#sidesInteger (readonly)

Returns 面数.

Returns:

  • (Integer)

    面数



100
101
102
# File 'lib/bcdice/common_command/tally_dice/node.rb', line 100

def sides
  @sides
end

#timesInteger (readonly)

Returns 振る回数.

Returns:

  • (Integer)

    振る回数



98
99
100
# File 'lib/bcdice/common_command/tally_dice/node.rb', line 98

def times
  @times
end

Instance Method Details

#roll(randomizer) ⇒ Array<Integer>

ダイスを振る

Parameters:

Returns:

  • (Array<Integer>)

    出目の配列



122
123
124
# File 'lib/bcdice/common_command/tally_dice/node.rb', line 122

def roll(randomizer)
  randomizer.roll_barabara(@times, @sides)
end

#to_sString

Returns:

  • (String)


127
128
129
130
# File 'lib/bcdice/common_command/tally_dice/node.rb', line 127

def to_s
  show_zeros_symbol = @show_zeros ? "Z" : "Y"
  "#{@times}T#{show_zeros_symbol}#{@sides}"
end

#valid?Boolean

Returns ダイスとして有効(振る回数、面数ともに正の数)か.

Returns:

  • (Boolean)

    ダイスとして有効(振る回数、面数ともに正の数)か



115
116
117
# File 'lib/bcdice/common_command/tally_dice/node.rb', line 115

def valid?
  @times > 0 && @sides > 0
end