summaryrefslogtreecommitdiffstats
path: root/lib/colonial_twilight/game.rb
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2020-09-01 15:41:19 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2020-09-01 15:41:19 +0200
commit2955ea1e1237eebb2ea607731c0f99bd053b40e9 (patch)
tree6c681c9090926b3f18ed6d37089ef295b0d63aae /lib/colonial_twilight/game.rb
parenta537cb64b77793387d2529467d4291198fc7fa70 (diff)
downloadcolonial-twilight-2955ea1e1237eebb2ea607731c0f99bd053b40e9.zip
colonial-twilight-2955ea1e1237eebb2ea607731c0f99bd053b40e9.tar.gz
Game/CLI : in good shape so far
Diffstat (limited to 'lib/colonial_twilight/game.rb')
-rw-r--r--lib/colonial_twilight/game.rb35
1 files changed, 20 insertions, 15 deletions
diff --git a/lib/colonial_twilight/game.rb b/lib/colonial_twilight/game.rb
index 43d6318..a211b3d 100644
--- a/lib/colonial_twilight/game.rb
+++ b/lib/colonial_twilight/game.rb
@@ -15,20 +15,21 @@ module ColonialTwilight
'Full: 1955-1962: Algérie Francaise!'].freeze
@rules = ['Standard Rules - No Support Phase in final Propaganda round',
'Optional Rule 8.5.1 - Conduct Support Phase in final Propaganda round'].freeze
- @states = {
+ @actions = {
:event => 'Event: execute the Event card',
:ope_special => 'Operation & Special Activity: conduct an Operation in any number of spaces with a Special Activity',
:ope_only => 'Operation Only: conduct an Operation in any number of spaces without a Special Activity',
:ope_limited => 'Limited Operation: conduct an Operation in 1 space without a Special Activity',
:pass => 'Pass: increase your Resources'
}.freeze
+ @swap_actions= [:ope_special, :ope_limited]
class << self
- attr_reader :scenarios, :rules, :states, :cards
+ attr_reader :scenarios, :rules, :actions, :cards
end
def rules; Game.rules end
def scenarios; Game.scenarios end
def possible_actions used=nil
- ks = Game.states.keys
+ ks = Game.actions.keys
if not used.nil?
if used == :event
ks.delete :event
@@ -46,10 +47,10 @@ module ColonialTwilight
ks.delete :ope_special
end
end
- Game.states.select { |k,v| ks.include? k }
+ Game.actions.select { |k,v| ks.include? k }
end
- attr_reader :scenario, :ruleset, :board, :ui, :cards
+ attr_reader :options, :scenario, :ruleset, :board, :ui, :cards, :actions
def initialize options
@options = options
@board = ColonialTwilight::Board.new
@@ -73,27 +74,31 @@ module ColonialTwilight
while true
ui.turn_start @turn, *@players
c = ui.pull_card @max_card
- @cards << @deck.pull(1) # FIXME
+ c = 1 # FIXME
+ @cards << @deck.pull(c)
ui.show_card @cards[-1]
- continue? @players[0].instance_of? FLNBot
+ ui.continue? @players[0].instance_of? FLNBot
ui.player @players[0], true
- @actions[0] = @players[0].play possible_actions
+ @actions[0] = @players[0].play @cards[-1], possible_actions
+ @ui.adjust_track @board.compute_victory_points
- continue? @players[1].instance_of? FLNBot
+ ui.continue? @players[1].instance_of? FLNBot
ui.player @players[1], false
- @actions[1] = @players[1].play possible_actions @actions[0]
+ @actions[1] = @players[1].play possible_actions @cards[-1], @actions[0]
+ @ui.adjust_track @board.compute_victory_points
@cards.shift if @cards.length > 2
@turn += 1
- # TURN END ...
+ if eligibility_swap?
+ @players[0], @players[1] = @players[1], @players[0]
+ end
+ @actions.clear
end
end
- def continue? bot
- l = bot ? ["FLN :\t\tlet the FLN bot play", "Pivotal Event:\tplay a Pivotal Event"] : ["Play:\t\tplay your turn"]
- ret = ui.chose('Next action', l, true) { |s| a = s.split(':'); a[0] = a[0].yellow; a.join(':') }
- exit(0) if ret < 0
+ def eligibility_swap?
+ Game.swap_actions.include? @actions[0]
end
end