Class: ExchangeCarrots

Inherits:
Action
  • Object
show all
Defined in:
lib/software_challenge_client/action.rb

Overview

Karottentauschaktion. Es können auf einem Karottenfeld 10 Karotten abgegeben oder aufgenommen werden. Dies kann beliebig oft hintereinander ausgeführt werden.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Action

#invalid

Constructor Details

#initialize(value) ⇒ ExchangeCarrots

Returns a new instance of ExchangeCarrots.



182
183
184
# File 'lib/software_challenge_client/action.rb', line 182

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



180
181
182
# File 'lib/software_challenge_client/action.rb', line 180

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



197
198
199
# File 'lib/software_challenge_client/action.rb', line 197

def ==(other)
  other.type == type && other.value == value
end

#perform!(gamestate) ⇒ Object



186
187
188
189
190
191
# File 'lib/software_challenge_client/action.rb', line 186

def perform!(gamestate)
  valid, message = GameRules.is_valid_to_exchange_carrots(gamestate, value)
  invalid("Es können nicht #{value} Karotten aufgenommen werden. " + message) unless valid
  gamestate.current_player.carrots += value
  gamestate.set_last_action(self)
end

#typeObject



193
194
195
# File 'lib/software_challenge_client/action.rb', line 193

def type
  :exchange_carrots
end