From 6829aa96f06ee2fc3eb20cb124611827928d16a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 19 Nov 2023 12:14:21 +0100 Subject: Spaces/Forces : add #activate(num) && specs --- lib/colonial_twilight/forces.rb | 7 +++++++ lib/colonial_twilight/spaces.rb | 4 ++++ spec/forces_spec.rb | 8 ++++++++ spec/spaces_spec.rb | 6 ++++++ 4 files changed, 25 insertions(+) diff --git a/lib/colonial_twilight/forces.rb b/lib/colonial_twilight/forces.rb index f2b4149..6d26dea 100644 --- a/lib/colonial_twilight/forces.rb +++ b/lib/colonial_twilight/forces.rb @@ -119,6 +119,13 @@ module ColonialTwilight update_control end + def activate(num) + raise "can't activate #{num}" if @fln_underground < num + + @fln_underground -= num + @fln_active += num + end + private def add_base(type, num = 1) diff --git a/lib/colonial_twilight/spaces.rb b/lib/colonial_twilight/spaces.rb index d85954f..83d9082 100644 --- a/lib/colonial_twilight/spaces.rb +++ b/lib/colonial_twilight/spaces.rb @@ -177,6 +177,10 @@ module ColonialTwilight raise "unknown shift direction : #{towards}" end end + + def activate(num) + @forces.activate(num) + end end class City < Sector diff --git a/spec/forces_spec.rb b/spec/forces_spec.rb index ce6316f..110139e 100644 --- a/spec/forces_spec.rb +++ b/spec/forces_spec.rb @@ -132,6 +132,14 @@ describe ColonialTwilight::Forces do expect { @f.add :wrong, 1 }.to raise_error(Exception) end + it 'activate raise' do + expect { @f.activate(7) }.to raise_error(Exception) + end + + it 'activate' do + expect(@f.activate(6)).to eq 13 + end + it 'data' do d = @f.data @data.keys do |k, v| diff --git a/spec/spaces_spec.rb b/spec/spaces_spec.rb index e1d75ca..0e05707 100644 --- a/spec/spaces_spec.rb +++ b/spec/spaces_spec.rb @@ -136,6 +136,12 @@ describe ColonialTwilight::Sector do expect(@s.resettled?).to be true expect(@s.pop).to eq 0 end + + it 'activate' do + @s.add :fln_active, 1 + @s.add :fln_underground, 2 + expect(@s.activate(2)).to eq 3 + end end describe ColonialTwilight::City do -- cgit v1.1-2-g2b99