game_dice 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/bin/roll +21 -0
  2. data/lib/game_dice/die.rb +23 -0
  3. data/lib/game_dice.rb +1 -0
  4. metadata +48 -0
data/bin/roll ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'game_dice'
4
+
5
+ begin
6
+ abort("Usage: #{File.basename(__FILE__)} <number>d<sides>") unless ARGV.length > 0
7
+
8
+ number_of_dice = ARGV.first.split('d').first.to_i
9
+ sides = ARGV.first.split('d').last.to_i
10
+ dice = []
11
+
12
+ abort('There must be at least 1 die.') unless number_of_dice > 0
13
+ abort('Dice must have at least 2 sides.') unless sides > 1
14
+
15
+ number_of_dice.times { dice << Die.new(sides).roll }
16
+
17
+ puts "Rolled #{number_of_dice}d#{sides}..."
18
+ dice.each_index { |i| puts "\tDie #{i + 1}: #{dice[i]}" }
19
+ puts "\t ------"
20
+ puts " Total Result: #{dice.inject('+')}"
21
+ end
@@ -0,0 +1,23 @@
1
+ # Represents an individual die object with the specified number of sides.
2
+ # Defaults to a 6-sided die.
3
+ class Die
4
+ # The number of sides on the die.
5
+ attr_reader :sides
6
+ # The result of the last roll.
7
+ attr_reader :last_roll
8
+
9
+ # Create a new die object with the specified number of sides. Defaults to 6.
10
+ def initialize(sides=6)
11
+ @sides = sides
12
+ @last_roll = 0
13
+ end
14
+
15
+ # Rolls the die and stores the result in the _last_roll_ attribute.
16
+ def roll
17
+ @last_roll = Array.new(@sides) { |i| i + 1 }.shuffle.first
18
+ end
19
+
20
+ def to_s
21
+ "A single die with #{@sides} sides. Currenly showing: #{@last_roll}."
22
+ end
23
+ end
data/lib/game_dice.rb ADDED
@@ -0,0 +1 @@
1
+ require 'game_dice/die'
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: game_dice
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brandon Rice
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-03 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email: brice84@gmail.com
16
+ executables:
17
+ - roll
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/game_dice.rb
22
+ - lib/game_dice/die.rb
23
+ - bin/roll
24
+ homepage:
25
+ licenses: []
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 1.8.24
45
+ signing_key:
46
+ specification_version: 3
47
+ summary: A simple library and scripts for rolling common RPG dice.
48
+ test_files: []