Permalink
Browse files

Initial version of Throne Room and King's Court

  • Loading branch information...
1 parent 2cb6d2c commit 51dcd6fb38a8745f6eb7439df5d08f99fa581ce0 @carter-thaxton committed Aug 14, 2012
Showing with 52 additions and 12 deletions.
  1. +23 −1 lib/cards.rb
  2. +12 −10 lib/player.rb
  3. +1 −1 rakefile.rb
  4. +16 −0 test/test_cards.rb
View
@@ -318,6 +318,17 @@ def pick_a_treasure(cards)
class ThroneRoom < Card
set :base
+ type :action
+ cost 4
+
+ def on_play
+ card = choose_card "Choose a card to play twice", :from => :hand, :required => true
+ if card
+ 2.times do
+ play card, :played_by_card => self
+ end
+ end
+ end
end
class CouncilRoom < Card
@@ -561,7 +572,7 @@ class Conspirator < Card
coins 2
def on_play
- if actions_in_play.count >= 3
+ if actions_played >= 3
draw 1
add_actions 1
end
@@ -1032,6 +1043,17 @@ class Forge < Card
class KingsCourt < Card
set :prosperity
+ type :action
+ cost 7
+
+ def on_play
+ card = choose_card "Choose a card to play thrice", :from => :hand, :required => false
+ if card
+ 3.times do
+ play card, :played_by_card => self
+ end
+ end
+ end
end
class Peddler < Card
View
@@ -14,7 +14,7 @@ class Player
:actions_in_play, :treasures_in_play,
:durations_on_first_turn, :durations_on_second_turn,
:actions_available, :coins_available, :buys_available,
- :vp_tokens, :pirate_ship_tokens,
+ :actions_played, :vp_tokens, :pirate_ship_tokens,
:turn, :card_in_play
def initialize(game, position, identity, strategy)
@@ -33,6 +33,7 @@ def initialize(game, position, identity, strategy)
@coins_available = 0
@buys_available = 0
@vp_tokens = 0
+ @actions_played = 0
@pirate_ship_tokens = 0
@turn = 0
@card_in_play = nil
@@ -80,6 +81,7 @@ def start_turn
@turn += 1
@actions_available = 1
+ @actions_played = 0
@coins_available = 0
@buys_available = 1
move_to_phase :action
@@ -162,12 +164,12 @@ def play(card_or_class, options = {})
raise "#{card} is not playable" unless card.action? || card.treasure?
raise "#{card} is an action card, but currently in #{phase} phase" if card.action? && !action_phase?
- raise "#{card} is an action card, but there are no more actions available" if card.action? && actions_available <= 0
+ raise "#{card} is an action card, but there are no more actions available" if card.action? && actions_available <= 0 unless options[:played_by_card]
move_to_phase :treasure if action_phase? && card.treasure? # automatically move to treasure phase
raise "#{card} is a treasure card, but currently in #{phase} phase" if card.treasure? && !treasure_phase?
- hand.delete card
+ hand.delete card unless options[:played_by_card]
@card_in_play = card
@play_choice = options[:choice]
@@ -179,17 +181,17 @@ def play(card_or_class, options = {})
if card.action?
@actions_in_play << card
- @actions_available -= 1
- draw card.cards
- add_actions card.actions
- add_coins card.coins
- add_buys card.buys
+ @actions_available -= 1 unless options[:played_by_card]
+ @actions_played += 1
elsif card.treasure?
@treasures_in_play << card
- add_coins card.coins
- add_buys card.buys
end
+ draw card.cards
+ add_actions card.actions
+ add_coins card.coins
+ add_buys card.buys
+
card.on_play
@card_in_play = nil
View
@@ -4,7 +4,7 @@
$: << File.dirname(__FILE__) + '/test'
require 'test_setup'
- require 'test_cards'
require 'test_game'
require 'test_big_money'
+ require 'test_cards'
end
View
@@ -386,5 +386,21 @@ def test_bank
player.play Bank
assert_equal 9, player.coins_available
end
+
+ def test_throne_room_kings_court
+ game = Game.new :num_players => 1, :no_cards => true, :kingdom_cards => [ThroneRoom, KingsCourt, Monument]
+ player = game.current_player
+
+ player.gain [ThroneRoom, KingsCourt, Monument, Monument], :to => :hand
+
+ player.strategy = MockStrategy.new([KingsCourt, Monument, Monument])
+
+ player.play ThroneRoom
+
+ assert_equal 12, player.coins_available
+ assert_equal 6, player.vp_tokens
+ assert_equal 0, player.actions_available
+ end
+
end

0 comments on commit 51dcd6f

Please sign in to comment.