Class: EatSalad

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

Overview

Eine Salatessen-Aktion. Kann nur auf einem Salatfeld ausgeführt werden. Muss ausgeführt werden, ein Salatfeld betreten wird. Nachdem die Aktion ausgefürht wurde, muss das Salatfeld verlassen werden, oder es muss ausgesetzt werden. Duch eine Salatessen-Aktion wird ein Salat verbraucht und es werden je nachdem ob der Spieler führt oder nicht 10 oder 30 Karotten aufgenommen.

Instance Method Summary collapse

Methods inherited from Action

#invalid

Constructor Details

#initializeEatSalad

Returns a new instance of EatSalad.



150
151
# File 'lib/software_challenge_client/action.rb', line 150

def initialize()
end

Instance Method Details

#==(other) ⇒ Object



157
158
159
# File 'lib/software_challenge_client/action.rb', line 157

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

#perform!(gamestate) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/software_challenge_client/action.rb', line 161

def perform!(gamestate)
  valid, msg = GameRules.is_valid_to_eat(gamestate)
  if valid
    gamestate.current_player.salads -= 1
    if gamestate.is_first(gamestate.current_player)
      gamestate.current_player.carrots += 10
    else
      gamestate.current_player.carrots += 30
    end
    gamestate.set_last_action(self)
  else
    invalid(msg)
  end
end

#typeObject



153
154
155
# File 'lib/software_challenge_client/action.rb', line 153

def type
  :eat_salad
end