Permalink
Browse files

Formulaクラスをインスタンス化して扱うようにした(ストラテジ化)。

  • Loading branch information...
1 parent 5bb6313 commit 9fe13075d1f81eadcacc5775efea20c95cdf04c8 @sakomoko committed Dec 31, 2012
Showing with 27 additions and 20 deletions.
  1. +10 −4 app/lib/arms.rb
  2. +14 −14 app/lib/eretheal/formula.rb
  3. +3 −2 spec/lib/eretheal/formula_spec.rb
View
@@ -2,13 +2,19 @@ module Arms
extend ActiveSupport::Memoizable
attr_reader :action
+ attr_accessor :formula
+
+ def initialize
+ super
+ @formula = Eretheal::Formula.new
+ end
def max_hp
- Eretheal::Formula.max_hp self
+ formula.max_hp self
end
def max_mp
- Eretheal::Formula.max_mp self
+ formula.max_mp self
end
def attack_speed_with_weapon
@@ -20,11 +26,11 @@ def attack_speed_with_weapon
end
def attack_speed_with_magic
- Eretheal::Formula.speed self.total_int
+ formula.speed self.total_int
end
def speed
- Eretheal::Formula.speed self.total_agi
+ formula.speed self.total_agi
end
def weapon_item_type
@@ -1,21 +1,21 @@
module Eretheal
- module Formula
- class << self
- [:hp, :mp].each do |type|
- define_method("max_#{type.to_s}") do |arms|
- case type
- when :hp
- status = "vit"
- when :mp
- status = "mnd"
- end
- ((arms.send("total_#{status}") * 3) + (arms.level * 3) + (1.015 ** arms.level)).to_i
+ class Formula
+
+ [:hp, :mp].each do |type|
+ define_method("max_#{type.to_s}") do |arms|
+ case type
+ when :hp
+ status = "vit"
+ when :mp
+ status = "mnd"
end
+ ((arms.send("total_#{status}") * 3) + (arms.level * 3) + (1.015 ** arms.level)).to_i
end
+ end
- def speed(parameter)
- ((parameter + (10 / parameter)) * 0.4).to_i
- end
+ def speed(parameter)
+ ((parameter + (10 / parameter)) * 0.4).to_i
end
+
end
end
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
describe Eretheal::Formula do
+ let(:formula) { Eretheal::Formula.new }
let(:character) { FactoryGirl.create :character, equip: FactoryGirl.create(:equip) }
let(:enemy) { FactoryGirl.create :enemy }
let(:sword) { FactoryGirl.create :belonging, item: FactoryGirl.create(:sword_item, speed: -1, add_dex: 1), character: character}
@@ -12,11 +13,11 @@
context 'HP/MPの最大値を得られること' do
[:hp, :mp].each do |type|
- it { Eretheal::Formula.send("max_#{type.to_s}", character).should be_integer }
+ it { formula.send("max_#{type.to_s}", character).should be_integer }
end
end
context 'スピード値が整数として得られること' do
- it { Eretheal::Formula.speed(6).should be_integer }
+ it { formula.speed(6).should be_integer }
end
end

0 comments on commit 9fe1307

Please sign in to comment.