Class: Turn
Overview
Turn by #turn_steps.
Instance Attribute Summary collapse
-
#turn_steps ⇒ Object
readonly
Number of steps to turn.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(turn_steps) ⇒ Turn
constructor
A new instance of Turn.
-
#perform!(gamestate, current_player) ⇒ Object
Perform the action.
- #type ⇒ Object
Methods inherited from Action
Constructor Details
#initialize(turn_steps) ⇒ Turn
Returns a new instance of Turn.
84 85 86 |
# File 'lib/software_challenge_client/action.rb', line 84 def initialize(turn_steps) @turn_steps = turn_steps end |
Instance Attribute Details
#turn_steps ⇒ Object (readonly)
Number of steps to turn. Negative values for turning clockwise, positive for counterclockwise.
82 83 84 |
# File 'lib/software_challenge_client/action.rb', line 82 def turn_steps @turn_steps end |
Instance Method Details
#==(other) ⇒ Object
118 119 120 |
# File 'lib/software_challenge_client/action.rb', line 118 def ==(other) other.type == type && other.turn_steps == turn_steps end |
#perform!(gamestate, current_player) ⇒ Object
Perform the action.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/software_challenge_client/action.rb', line 89 def perform!(gamestate, current_player) invalid 'Drehung um 0 ist ungültig' if turn_steps.zero? if gamestate .board .field(current_player.x, current_player.y) .type == FieldType::SANDBANK invalid 'Drehung auf Sandbank nicht erlaubt' end needed_coal = turn_steps.abs needed_coal -= 1 if gamestate.free_turn? if needed_coal > 0 && gamestate.additional_free_turn_after_push? needed_coal -= 1 gamestate.additional_free_turn_after_push = false end if needed_coal > current_player.coal invalid "Nicht genug Kohle für Drehung um #{turn_steps}. "\ "Habe #{current_player.coal}, brauche #{needed_coal}." end current_player.direction = Direction.get_turn_direction(current_player.direction, turn_steps) current_player.coal -= [0, needed_coal].max gamestate.free_turn = false end |
#type ⇒ Object
114 115 116 |
# File 'lib/software_challenge_client/action.rb', line 114 def type :turn end |