Class: Advance
Overview
Ein Vorwärtszug, um spezifizierte Distanz. Verbrauchte Karroten werden mit k = (distance * (distance + 1)) / 2 berechnet (Gaußsche Summe)
Instance Attribute Summary collapse
-
#distance ⇒ Object
readonly
Returns the value of attribute distance.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(distance) ⇒ Advance
constructor
A new instance of Advance.
-
#perform!(gamestate) ⇒ Object
Perform the action.
- #type ⇒ Object
Methods inherited from Action
Constructor Details
#initialize(distance) ⇒ Advance
Returns a new instance of Advance.
36 37 38 |
# File 'lib/software_challenge_client/action.rb', line 36 def initialize(distance) @distance = distance end |
Instance Attribute Details
#distance ⇒ Object (readonly)
Returns the value of attribute distance.
34 35 36 |
# File 'lib/software_challenge_client/action.rb', line 34 def distance @distance end |
Instance Method Details
#==(other) ⇒ Object
61 62 63 |
# File 'lib/software_challenge_client/action.rb', line 61 def ==(other) other.type == type && other.distance == distance end |
#perform!(gamestate) ⇒ Object
Perform the action.
performed. Performing may change the game state. The action is performed for the current player of the game state.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/software_challenge_client/action.rb', line 45 def perform!(gamestate) valid, = GameRules.is_valid_to_advance(gamestate, distance) invalid() unless valid # perform state changes required_carrots = distance * (distance + 1) / 2 gamestate.current_player.carrots -= required_carrots gamestate.current_player.index += distance if gamestate.current_field.type == FieldType::HARE gamestate.current_player.must_play_card = true end end |
#type ⇒ Object
57 58 59 |
# File 'lib/software_challenge_client/action.rb', line 57 def type :advance end |