Skip to content

Conversation

@msducheminjr
Copy link
Member

Add Die and DiceSet classes to NerdDice module. These allow you to instantiate Die objects individually (by using Die.new) or as a collection (by using DiceSet.new). Also added in roll_dice method to the NerdDice module that makes use of the DiceSet and Die objects with a similar interface to the total_dice method and added in a SetsRandomizationTechnique module that is mixed in by both the Die and DiceSet objects. Added in configuration options to NerdDice::Configuration that allow users to specify foreground and background colors for dice with defaults set as constants. (Functionality for doing anything with those colors other than getting and setting them hasn't been implemented yet.)

Create the new NerdDice::Die class that represents a single die with
the ability to be instantiated and rolled. Each time you call the public
method on the die, the value is set to the result of the roll.

Completes backlog items:
* Write specs for Die class
* Implement Die class so specs pass
Refactor Die class to call the generator_override= attribute writer in
the initialize method and move validation into that method. Remove
unintentional puts statements from the generator_override= and
initialize.

Also implemented the Comparable module in Die so that the values of
different dice can be compared and the dice can respond to the sort
method and other enumerable methods.

Completes backog items
* Remove puts statements and improve code coverage in Die class
* Implement Comparable in Die class
Add a damage_type property (default null) to the Die class and change
the default foreground color and background color of a new die to read
its value from the NerdDice::Configuration object instead of constants
in the Die class. Created new options :die_background_color, and
:die_foreground_color in the Configuration class with default values set
as constants.

Completes NerdDice backlog items:
* Add damage_type option to Die class
* Have default background and foreground colors be part of the
  configuration object instead of constants on the Die class.
Implement the DiceSet method that has a constructor similar to the
argument structure of NerdDice.total_dice that also takes and cascades
optional properties to each die in the collection.

Other changes
* Fix comments in NerdDice.total_dice and Die classes
* Change Die generator_override property to randomization_technique to
  keep optional arguments consistent with NerdDice.total_dice method

Completes NerdDice backlog items:
* Write specs for DiceSet class
* Implement DiceSet class so specs pass
Include the Enumerable module in DiceSet, which allows for calling
methods like :each and :sort directly on the class instead of on the
@dice instance variable.

Add reroll_all method to the DiceSet class that re-rolls each die in
the collection

Completes NerdDice backlog items
* Include Enumerable module in DiceSet
* Add reroll_all method to DiceSet
Implement the highest and lowest methods (aliased as with_advantage and
with_disadvantage, respectively). Modify the Die class to have an
is_included_in_total attribute that can be manipulated by the DiceSet
object.

Completes NerdDice Backlog Item:
Add highest(x) and lowest(x) methods aliased as with_advantage
with_disadvantage
Create include_all_dice! method in DiceSet that resets the
is_included_in_total attribute of each die to be true. Call this method
at the beginning of the highest and lowest methods.

This fixes a bug where if you alternated highest/lowest and reroll_all
for the same DiceSet object, you would eventually exclude all dice,
making the total 0.

Fixes #30
Total is 0 if you keep re-rolling and using highest/lowest methods
Add a custom attribute writer for the bonus attribute in DiceSet that
validates input and call that method when intializing the DiceSet.

Completes NerdDice backlog item:
Create a setter method DiceSet bonus=
Refactor the repeated randomization_technique= code into a module called
SetsRandomizationTechnique that gets mixed in by both the Die and
DiceSet classes. Also moved the attribute reader to the mixin module.

Completes NerdDice backlog item:
Refactor randomization_technique= into a mixin
Add roll_dice method with similar method construction to the total_dice
method, except that it returns a DiceSet object instead of an Integer
and allows for chaining methods to filter the dice or take actions on
them.

Completes NerdDice backlog item:
Add roll_dice method to NerdDice module. Return DiceSet
Add sort! and reverse! methods to DiceSet that change the order of the
elements in the dice array. This could already be done via
dice_set.dice.sort!, but it makes sense to have this available on the
top level of the class as a method.

Completes NerdDice backlog item:
Add sort! and reverse! methods to DiceSet that sort the dice in place.
Make DiceSet.reroll_all a bang method reroll_all! and have it include
all dice in the total after rerolling them.

Completes NerdDiceBacklog item:
Make reroll_all a bang method (reroll_all!) and have it reset included
in total to true
* Modify the README and CHANGELOG to account for the functionality on the
feature/die-object branch for 0.3 before merging into master.
* Fix RuboCop offense missed in the previous 2 commits.
* Add method comments for the Die and DiceSet classes

Completes #3 Ability to inspect the individual dice and take actions on
them
Add roll_dice method to the nerd_dice_benchmark suite and add separate
values to the ratio hash for them. Change the existing keys like
:nerd_dice_securerandom to :total_dice_securerandom to differentiate
between the total_dice and roll_dice methods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants