Class: Attack
- Inherits:
-
Object
- Object
- Attack
- Includes:
- Comparable
- Defined in:
- lib/middle_earth_challenge_simulator.rb
Constant Summary collapse
- CRITICAL_MISS =
5- CRITICAL_HIT =
96
Instance Attribute Summary collapse
-
#attack_value ⇒ Object
readonly
Returns the value of attribute attack_value.
-
#challenge_rank ⇒ Object
readonly
Returns the value of attribute challenge_rank.
-
#critical_hit ⇒ Object
readonly
Returns the value of attribute critical_hit.
-
#critical_miss ⇒ Object
readonly
Returns the value of attribute critical_miss.
-
#r1 ⇒ Object
readonly
Returns the value of attribute r1.
-
#r2 ⇒ Object
readonly
Returns the value of attribute r2.
Instance Method Summary collapse
- #<=>(a) ⇒ Object
-
#initialize(c, roll1 = rand(99) + 1, roll2 = rand(99)+1) ⇒ Attack
constructor
A new instance of Attack.
- #to_s ⇒ Object
Constructor Details
#initialize(c, roll1 = rand(99) + 1, roll2 = rand(99)+1) ⇒ Attack
Returns a new instance of Attack.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/middle_earth_challenge_simulator.rb', line 42 def initialize(c, roll1 = rand(99) + 1, roll2 = rand(99)+1) @challenge_rank = c @r1 = roll1 @critical_miss = @r1 <= CRITICAL_MISS @critical_hit = @r1 >= CRITICAL_HIT @r2 = 0 @r2 = roll2 if (self.critical_hit || self.critical_miss) @attack_value = @r1 + @challenge_rank @attack_value = @attack_value - @r2 if self.critical_miss @attack_value = @attack_value + @r2 if self.critical_hit end |
Instance Attribute Details
#attack_value ⇒ Object (readonly)
Returns the value of attribute attack_value.
39 40 41 |
# File 'lib/middle_earth_challenge_simulator.rb', line 39 def attack_value @attack_value end |
#challenge_rank ⇒ Object (readonly)
Returns the value of attribute challenge_rank.
39 40 41 |
# File 'lib/middle_earth_challenge_simulator.rb', line 39 def challenge_rank @challenge_rank end |
#critical_hit ⇒ Object (readonly)
Returns the value of attribute critical_hit.
39 40 41 |
# File 'lib/middle_earth_challenge_simulator.rb', line 39 def critical_hit @critical_hit end |
#critical_miss ⇒ Object (readonly)
Returns the value of attribute critical_miss.
39 40 41 |
# File 'lib/middle_earth_challenge_simulator.rb', line 39 def critical_miss @critical_miss end |
#r1 ⇒ Object (readonly)
Returns the value of attribute r1.
39 40 41 |
# File 'lib/middle_earth_challenge_simulator.rb', line 39 def r1 @r1 end |
#r2 ⇒ Object (readonly)
Returns the value of attribute r2.
39 40 41 |
# File 'lib/middle_earth_challenge_simulator.rb', line 39 def r2 @r2 end |
Instance Method Details
#<=>(a) ⇒ Object
54 55 56 |
# File 'lib/middle_earth_challenge_simulator.rb', line 54 def <=> a return self.attack_value <=> a.attack_value end |
#to_s ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/middle_earth_challenge_simulator.rb', line 58 def to_s "Attack {attack_value: #{@attack_value} " \ "challenge_rank #{@challenge_rank} " \ "r1: #{@r1} " \ "critical_hit: #{@critical_hit} " \ "critical_miss: #{@critical_miss} " \ "r2: #{@r2}}" end |