game_dice 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/roll CHANGED
@@ -7,15 +7,15 @@ begin
7
7
 
8
8
  number_of_dice = ARGV.first.split('d').first.to_i
9
9
  sides = ARGV.first.split('d').last.to_i
10
- dice = []
11
10
 
12
11
  abort('There must be at least 1 die.') unless number_of_dice > 0
13
12
  abort('Dice must have at least 2 sides.') unless sides > 1
14
13
 
15
- number_of_dice.times { dice << Die.new(sides).roll }
14
+ dice = Dice.new(number_of_dice, sides)
15
+ dice.roll
16
16
 
17
17
  puts "Rolled #{number_of_dice}d#{sides}..."
18
- dice.each_index { |i| puts "\tDie #{i + 1}: #{dice[i]}" }
18
+ dice.each_index { |i| puts "\tDie #{i + 1}: #{dice[i].last_roll}" }
19
19
  puts "\t ------"
20
- puts " Total Result: #{dice.inject('+')}"
20
+ puts " Total Result: #{dice.total}"
21
21
  end
@@ -0,0 +1,22 @@
1
+ # A Dice object represents a collection of individual Die objects.
2
+ # Defaults to two dice.
3
+ class Dice < Array
4
+ # Dice collectiond defaults to 2d6
5
+ def initialize(amount=2, sides=6)
6
+ amount.times { self << Die.new(sides) }
7
+ end
8
+
9
+ # Roll all the dice
10
+ def roll
11
+ self.inject(0) { |total, current| total += current.roll }
12
+ end
13
+
14
+ # Check the current roll for all dice
15
+ def total
16
+ self.inject(0) { |total, current| total += current.last_roll }
17
+ end
18
+
19
+ def to_s
20
+ "A collection of dice #{self.collect { |i| i.last_roll }}, total: #{total}."
21
+ end
22
+ end
data/lib/game_dice.rb CHANGED
@@ -1 +1,2 @@
1
1
  require 'game_dice/die'
2
+ require 'game_dice/dice'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: game_dice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-03 00:00:00.000000000 Z
12
+ date: 2012-10-30 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! "This is a simple library for dealing with RPG dice systems. \n It
15
15
  comes packaged with some scripts for rolling dice and \n dealing
@@ -23,6 +23,7 @@ extra_rdoc_files: []
23
23
  files:
24
24
  - lib/game_dice.rb
25
25
  - lib/game_dice/die.rb
26
+ - lib/game_dice/dice.rb
26
27
  - bin/roll
27
28
  homepage: https://github.com/nevern02/game_dice
28
29
  licenses: []