Class: Card
Overview
Play a card.
Instance Attribute Summary collapse
-
#card_type ⇒ Object
readonly
Returns the value of attribute card_type.
-
#value ⇒ Object
readonly
only for type TAKE_OR_DROP_CARROTS.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(card_type, value = 0) ⇒ Card
constructor
A new instance of Card.
-
#perform!(gamestate) ⇒ Object
Perform the action.
- #type ⇒ Object
Methods inherited from Action
Constructor Details
#initialize(card_type, value = 0) ⇒ Card
Returns a new instance of Card.
73 74 75 76 |
# File 'lib/software_challenge_client/action.rb', line 73 def initialize(card_type, value = 0) @card_type = card_type @value = value end |
Instance Attribute Details
#card_type ⇒ Object (readonly)
Returns the value of attribute card_type.
71 72 73 |
# File 'lib/software_challenge_client/action.rb', line 71 def card_type @card_type end |
#value ⇒ Object (readonly)
only for type TAKE_OR_DROP_CARROTS
69 70 71 |
# File 'lib/software_challenge_client/action.rb', line 69 def value @value end |
Instance Method Details
#==(other) ⇒ Object
120 121 122 123 |
# File 'lib/software_challenge_client/action.rb', line 120 def ==(other) other.card_type == card_type && (card_type != CardType::TAKE_OR_DROP_CARROTS || (other.value == value)) 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.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/software_challenge_client/action.rb', line 79 def perform!(gamestate) gamestate.current_player.must_play_card = false case card_type when CardType::EAT_SALAD valid, = GameRules.is_valid_to_play_eat_salad(gamestate) invalid("Das Ausspielen der EAT_SALAD Karte ist nicht möglich. " + ) unless valid gamestate.current_player.salads -= 1 if gamestate.is_first(gamestate.current_player) gamestate.current_player.carrots += 10 else gamestate.current_player.carrots += 20 end when CardType::FALL_BACK valid, = GameRules.is_valid_to_play_fall_back(gamestate) invalid("Das Ausspielen der FALL_BACK Karte ist nicht möglich. " + ) unless valid gamestate.current_player.index = gamestate.other_player.index - 1 if gamestate.field(gamestate.current_player.index).type == FieldType::HARE gamestate.current_player.must_play_card = true end when CardType::HURRY_AHEAD valid, = GameRules.is_valid_to_play_hurry_ahead(gamestate) invalid("Das Ausspielen der HURRY_AHEAD Karte ist nicht möglich. " + ) unless valid gamestate.current_player.index = gamestate.other_player.index + 1 if gamestate.field(gamestate.current_player.index).type == FieldType::HARE gamestate.current_player.must_play_card = true end when CardType::TAKE_OR_DROP_CARROTS valid, = GameRules.is_valid_to_play_take_or_drop_carrots(gamestate, value) invalid("Das Ausspielen der TAKE_OR_DROP_CARROTS Karte ist nicht möglich. " + ) unless valid gamestate.current_player.carrots += value else raise "Unknown card type #{card_type.inspect}!" end gamestate.set_last_action(self) gamestate.current_player.cards.delete(self.type) end |
#type ⇒ Object
116 117 118 |
# File 'lib/software_challenge_client/action.rb', line 116 def type :card end |