summaryrefslogtreecommitdiffstats
path: root/lib/colonial_twilight/board.rb
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2020-09-03 15:45:54 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2020-09-03 15:45:54 +0200
commit1ea408bc51382058fbeb54e88678432a459a44c9 (patch)
tree05317cbcae29d3c18a85f882c04dd697141d1951 /lib/colonial_twilight/board.rb
parentc18b41671efabbd20a743e01dd8498d71d550eb9 (diff)
downloadcolonial-twilight-1ea408bc51382058fbeb54e88678432a459a44c9.zip
colonial-twilight-1ea408bc51382058fbeb54e88678432a459a44c9.tar.gz
Board/Cli : introduce Box class, clean up CLI
Diffstat (limited to 'lib/colonial_twilight/board.rb')
-rw-r--r--lib/colonial_twilight/board.rb22
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/colonial_twilight/board.rb b/lib/colonial_twilight/board.rb
index ba6956b..6ddd97b 100644
--- a/lib/colonial_twilight/board.rb
+++ b/lib/colonial_twilight/board.rb
@@ -137,6 +137,14 @@ module ColonialTwilight
end
+ class Box < Forces
+ attr_reader :name
+ def initialize sym
+ super sym
+ @name = sym
+ end
+ end
+
class Sector
MOUNTAIN=1
@@ -265,9 +273,9 @@ module ColonialTwilight
@names = []
@spaces_h = {}
@capabilities = []
- @available = Forces.new :available
- @casualties = Forces.new :casualties
- @out_of_play = Forces.new :out_of_play
+ @available = Box.new :available
+ @casualties = Box.new :casualties
+ @out_of_play = Box.new :out_of_play
feed
@spaces = @spaces_h.values
@sectors = @spaces.select { |s| not s.country? }
@@ -283,10 +291,12 @@ module ColonialTwilight
end
def transfer n, what, from, to, towhat=nil
- from = (from.is_a?(Sector) ? from : get_local(from) )
- to = (to.is_a?(Sector) ? to : get_local(to) )
+ towhat = what if towhat.nil?
+ from = get_var from if from.is_a? Symbol
+ to = get_var to if to.is_a? Symbol
from.add what, -n
to.add towhat, n
+ { :n => n, :what => what, :from=>from, :to => to, :towhat=> towhat }
end
def terror where, n
@@ -394,7 +404,7 @@ module ColonialTwilight
private
- def get_local sym
+ def get_var sym
case sym
when :available; return @available
when :casualties; return @casualties