Permalink
Browse files

Handle boolean responses

  • Loading branch information...
1 parent 5e272ad commit 5a22abdf89a1d476cc6366631cf423b971892909 @carter-thaxton committed Aug 8, 2012
Showing with 48 additions and 15 deletions.
  1. +1 −0 Gemfile
  2. +2 −0 Gemfile.lock
  3. +6 −8 lib/cards.rb
  4. +39 −7 lib/player.rb
View
@@ -1,3 +1,4 @@
source 'http://rubygems.org'
gem 'pry'
+gem 'rake'
View
@@ -9,6 +9,7 @@ GEM
method_source (~> 0.6.5)
ruby_parser (~> 2.0.5)
slop (~> 2.1.0)
+ rake (0.9.2.2)
ruby_parser (2.0.6)
sexp_processor (~> 3.0)
sexp_processor (3.0.7)
@@ -19,3 +20,4 @@ PLATFORMS
DEPENDENCIES
pry
+ rake
View
@@ -662,14 +662,12 @@ class Mountebank < Card
def play_action
other_players.each do |player|
- player.reveal :type => Curse, :attack => true do |curse, attack_failed|
- unless attack_failed
- if curse
- player.discard curse
- else
- player.gain Copper
- player.gain Curse
- end
+ player.reveal :type => Curse, :attack => true do |curse|
+ if curse
+ player.discard curse
+ else
+ player.gain Curse
+ player.gain Copper
end
end
end
View
@@ -286,7 +286,33 @@ def respond(response)
@choice_in_progress = nil
response
end
-
+
+ def reveal(options = {})
+ attack_cond options[:attach] do
+ type = options[:type]
+ card = find_card_in_hand(type)
+ if card
+ if options[:required]
+ yield card
+ else
+ ask "Reveal #{card}" do |response|
+ yield card if response
+ end
+ end
+ end
+ end
+ end
+
+ def attack_cond(condition)
+ if condition
+ attack do
+ yield
+ end
+ else
+ yield
+ end
+ end
+
def cards_in_play
actions_in_play + treasures_in_play + durations_on_first_turn + durations_on_second_turn
end
@@ -340,13 +366,19 @@ def handle_response(response)
else
return find_card_in_hand(response)
end
+ else
+ raise "Only cards may be chosen from hand"
end
end
-
+
+ if @choice_in_progress[:type] == :bool && !@choice_in_progress[:multiple]
+ raise "Response must be true or false" unless response == true or response == false
+ end
+
if @choice_in_progress[:multiple] && @choice_in_progress[:max]
raise "At most #{@choice_in_progress[:max]} may be chosen" if response.size > @choice_in_progress[:max]
end
-
+
if @choice_in_progress[:multiple] && @choice_in_progress[:min]
raise "At least #{@choice_in_progress[:min]} must be chosen" if response.size < @choice_in_progress[:min]
end
@@ -355,13 +387,13 @@ def handle_response(response)
end
def find_card_in_hand(card, options = {})
- set = options.fetch :set, hand
+ hand = options.fetch :hand, self.hand
if card.is_a? Card
- raise "#{card} is not in the player's hand" unless set.include?(card)
+ raise "#{card} is not in the player's hand" unless hand.include?(card)
elsif is_card_class(card)
# choose an instance from the player's hand of the given class
card_class = card
- card = set.find {|card| card.is_a? card_class}
+ card = hand.find {|card| card.is_a? card_class}
if options[:required]
raise "No card of type #{card_class} found in hand" unless card
end
@@ -371,7 +403,7 @@ def find_card_in_hand(card, options = {})
def find_cards_in_hand(cards, options = {})
tmp_hand = hand.dup
- options[:set] = tmp_hand
+ options[:hand] = tmp_hand
cards.collect do |card|
card = find_card_in_hand(card, options)

0 comments on commit 5a22abd

Please sign in to comment.