Sha256: 41e5fe4c5db405b51168b67e6a52f821932775bd247fe4cacda8d2f5408989a5

Contents?: true

Size: 1.41 KB

Versions: 6

Compression:

Stored size: 1.41 KB

Contents

# encoding: UTF-8
require_relative 'debug_hint'
require_relative 'action'

# A move that can be performed in Mississippi Queen. A move consists of multiple
# actions in a specific order.
class Move
  # @!attribute [r] actions
  #
  # @return [Array<Action>] List of actions which should be performed in this
  #                         move in the order determined by the array order.
  attr_reader :actions

  # @!attribute [r] hints
  # @return [Array<DebugHint>] the move's hints
  attr_reader :hints

  # Initializer
  #
  def initialize
    @actions = []
    @hints = []
  end

  # adds a hint to the move
  # @param hint [DebugHint] the added hint
  def add_hint(hint)
    @hints.push(hint)
  end

  def ==(other)
    actions.size == other.actions.size &&
      actions.zip(other.actions).map { |a, b| a == b }.all?
  end

  def to_s
    "Move: #{actions}"
  end

  def add_action(action)
    @actions << action
  end

  def add_action_with_order(action, index)
    @actions[index] = action
  end

  def perform!(gamestate, current_player)
    # check if acceleration is only first action
    other_action_before = false
    @actions.each do |a|
      if a.type != :acceleration
        other_action_before = true
      elsif other_action_before
        raise InvalidMoveException.new('Beschleunigung muss am Anfang des Zuges geschehen.', self)
      end
    end
    @actions.each { |a| a.perform!(gamestate, current_player) }
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
software_challenge_client-0.3.4 lib/software_challenge_client/move.rb
software_challenge_client-0.3.3 lib/software_challenge_client/move.rb
software_challenge_client-0.3.2 lib/software_challenge_client/move.rb
software_challenge_client-0.3.1 lib/software_challenge_client/move.rb
software_challenge_client-0.3.0 lib/software_challenge_client/move.rb
software_challenge_client-0.2.0 lib/software_challenge_client/move.rb