Sha256: c41a672fb1cb2f5b89274fc4b26a2dce9a96419f6255a4f12cdeeaa87021e0c3

Contents?: true

Size: 1.38 KB

Versions: 3

Compression:

Stored size: 1.38 KB

Contents

# frozen string literal: true

require 'dry-initializer'

module SpyAlleyApplication
  module Actions
    class MakeAccusation
      include Dry::Initializer.define -> do
        option :process_eliminating_player, type: ::Types::Callable, reader: :private
        option :process_proceeding_to_next_state, type: ::Types::Callable, reader: :private
      end

      def call(game_board:, change_orders:, target_player_id:, nationality:)
        player = game_board.current_player
        target_player = game_board.players.find{|p| p.id.eql?(target_player_id)}
        at_risk_accusation = game_board.game_state.accept(self)
        execute_if_guess_incorrect =
          at_risk_accusation ? process_eliminating_player : process_proceeding_to_next_state
        if target_player.spy_identity.eql?(nationality)
          process_eliminating_player.(
            game_board: game_board,
            change_orders: change_orders,
            eliminating_player: player,
            eliminated_player: target_player)
        else
          execute_if_incorrect.(
            game_board: game_board,
            change_orders: change_orders,
            target_player_id: target_player_id,
            eliminating_player: target_player,
            eliminated_player: player)
        end
      end

      def handle_spy_eliminator(*args);false;end
      def handle_start_of_turn(*args);true;end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spy_alley_application-0.3.2 lib/spy_alley_application/actions/make_accusation.rb
spy_alley_application-0.3.1 lib/spy_alley_application/actions/make_accusation.rb
spy_alley_application-0.3.0 lib/spy_alley_application/actions/make_accusation.rb