-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/die object #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or 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 characters
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
9bdfb82 to
7457f5c
Compare
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
7457f5c to
04dff47
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add
DieandDiceSetclasses toNerdDicemodule. These allow you to instantiateDieobjects individually (by usingDie.new) or as a collection (by usingDiceSet.new). Also added inroll_dicemethod to theNerdDicemodule that makes use of theDiceSetandDieobjects with a similar interface to thetotal_dicemethod and added in aSetsRandomizationTechniquemodule that is mixed in by both theDieandDiceSetobjects. Added in configuration options toNerdDice::Configurationthat 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.)