Skip to content

Commit

Permalink
Update Adventurer to journalling
Browse files Browse the repository at this point in the history
Tests are green
For #128
  • Loading branch information
asilano committed Aug 4, 2016
1 parent 6af1312 commit 2cd15e5
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 59 deletions.
13 changes: 5 additions & 8 deletions app/models/base_game/adventurer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class BaseGame::Adventurer < Card
"Treasure cards. Put those Treasure cards into your " +
"hand, and discard the other revealed cards."

def play(parent_act)
def play
super

# We don't really need to actually reveal the cards here; putting them
Expand All @@ -16,7 +16,7 @@ def play(parent_act)
# shuffle the discard pile under. Then step through the deck (possibly plus
# old discard) and move each card to hand or discard until we're done.
treasure_count = 0
for card in player.cards(true).deck
player.cards.deck.each do |card|
treasure_count += 1 if card.is_treasure?
break if treasure_count == 2
end
Expand All @@ -28,17 +28,14 @@ def play(parent_act)

treasure_count = 0
cards_revealed = []
for card in player.cards.deck
player.cards.deck.each do |card|
cards_revealed << card.class.readable_name
if card.is_treasure?
treasure_count += 1
player.cards.hand << card
card.position = player.cards.hand.size - 1
card.location = "hand"
card.save!
break if treasure_count == 2
else
player.cards.in_discard << card
card.discard
end
end
Expand All @@ -48,8 +45,8 @@ def play(parent_act)
cards_revealed.insert(shuffle_point, "(#{player.name} shuffled their discards)")
end

game.histories.create!(:event => "#{player.name}'s Adventurer revealed: #{cards_revealed.join(', ')}.",
:css_class => "player#{player.seat} card_reveal #{'shuffle' if (shuffle_point > 0 && shuffle_point < cards_revealed.length)}")
game.add_history(:event => "#{player.name}'s Adventurer revealed: #{cards_revealed.join(', ')}.",
:css_class => "player#{player.seat} card_reveal #{'shuffle' if (shuffle_point > 0 && shuffle_point < cards_revealed.length)}")

return "OK"
end
Expand Down
1 change: 0 additions & 1 deletion app/models/card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ def trash
# Raise if the card doesn't have a player
def discard
raise "Card not owned" unless player
player.cards.in_discard << self
self.location = 'discard'
self.position = -1
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ def hack_game_state(journal, check: false)
end

case journal.event
when /^Hack: (.*) (hand) (\+|=) ((?:[a-zA-Z]*::[a-zA-Z]*(?:,\ )?)*)$/
when /^Hack: (.*) (hand|deck|play|discard) (\+|=) *((?:[a-zA-Z]*::[a-zA-Z]*(?:,\ )?)*)$/
player = players.joins { user }.where { user.name == $1 }.first
location = $2

Expand Down
1 change: 0 additions & 1 deletion app/models/player.rb
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,6 @@ def shuffle_discard_under_deck(options = {})
# at the end of the deck array.
renum(:deck)
cards.in_discard.shuffle.each do |card|
cards.deck << card
card.location = "deck"
card.position = cards.deck.count
end
Expand Down
16 changes: 8 additions & 8 deletions features/cards/base_game/adventurer.feature
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
Feature: Adventurer
Reveal cards from your deck until you reveal two Treasure cards.
Feature: Adventurer
Reveal cards from your deck until you reveal two Treasure cards.
Put those Treasure cards into your hand, and discard the other revealed cards.

Background:
Given I am a player in a standard game with Adventurer

Scenario: Adventurer should be set up at game start
Then there should be 10 Adventurer cards in piles
And there should be 0 Adventurer cards not in piles

Scenario Outline: Playing Adventurer
Given my hand contains Adventurer
Given my hand contains Adventurer, Copper
And my deck contains <deck cards>
And I have nothing in play
And I have <discard> in discard
And it is my Play Action phase
When I play Adventurer
Then the following 2 steps should happen at once
Then I should have drawn <from deck> cards
And I should have discarded <discarded>
And I should have discarded <discarded>
And it should be my Play Treasure phase

Examples:
| deck cards | discard | from deck | discarded |
| Copper, Gold then 3 other cards | nothing | 2 | nothing |
Expand Down
63 changes: 24 additions & 39 deletions features/step_definitions/card_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
name = 'Alan' if name == 'my'
player = @test_players[name]

player.cards.deck.destroy_all
@deck_contents[name] = []
rand_top = rand_mid = fixed_bottom = false

Expand All @@ -80,19 +79,16 @@
num_rand_bottom = $1
name_rand_bottom = $2

position = 0
hack_journal = "Hack: #{name} deck = "
hack_cards = []

@named_cards[name_rand_top] = [] if name_rand_top
if rand_top
num_rand_top.to_i.times do |i|
type = CARD_TYPES.keys[rand(CARD_TYPES.length)]
@deck_contents[name] << type
@named_cards[name_rand_top].andand << type
CARD_TYPES[type].create(:location => 'deck',
:player => player,
:position => position,
:game => player.game)
position += 1
hack_cards << CARD_TYPES[type].name
end
elsif top
top.split(/,\s*/).each do |type|
Expand All @@ -105,11 +101,7 @@

num.times do
@deck_contents[name] << card_name
CARD_TYPES[card_name].create(:location => 'deck',
:player => player,
:position => position,
:game => player.game)
position += 1
hack_cards << CARD_TYPES[card_name].name
end
end
end
Expand All @@ -120,11 +112,7 @@
type = CARD_TYPES.keys[rand(CARD_TYPES.length)]
@deck_contents[name] << type
@named_cards[name_rand_mid].andand << type
CARD_TYPES[type].create(:location => 'deck',
:player => player,
:position => position,
:game => player.game)
position += 1
hack_cards << CARD_TYPES[type].name
end
elsif middle
middle.split(/,\s*/).each do |type|
Expand All @@ -137,11 +125,7 @@

num.times do
@deck_contents[name] << card_name
CARD_TYPES[card_name].create(:location => 'deck',
:player => player,
:position => position,
:game => player.game)
position += 1
hack_cards << CARD_TYPES[card_name].name
end
end
end
Expand All @@ -152,11 +136,7 @@
type = CARD_TYPES.keys[rand(CARD_TYPES.length)]
@deck_contents[name] << type
@named_cards[name_rand_bottom].andand << type
CARD_TYPES[type].create(:location => 'deck',
:player => player,
:position => position,
:game => player.game)
position += 1
hack_cards << CARD_TYPES[type].name
end
elsif bottom
bottom_types = bottom.split(/,\s*/).each do |type|
Expand All @@ -169,25 +149,24 @@

num.times do
@deck_contents[name] << card_name
CARD_TYPES[card_name].create(:location => 'deck',
:player => player,
:position => position,
:game => player.game)
position += 1
hack_cards << CARD_TYPES[card_name].name
end
end
end

player.renum(:deck)
hack_journal << hack_cards.join(", ")
@test_game.add_journal(event: hack_journal)
@test_game.process_journals
end

# Matches:
# I have nothing in play
# Bob has nothing in play
Given /^(\w*) ha(?:ve|s) nothing in play/ do |name|
name = 'Alan' if name == 'I'
@test_players[name].cards.in_play.destroy_all
@play_contents[name] = []
@test_game.add_journal(event: "Hack: #{name} play =")
@test_game.process_journals
end

# Matches:
Expand Down Expand Up @@ -232,8 +211,9 @@
# Bob has nothing in his discard
Given /^(\w*) ha(?:ve|s) nothing in (?:my |his )?discard/ do |name|
name = "Alan" if name == "I"
@test_players[name].cards.in_discard.destroy_all
@discard_contents[name] = []
@test_game.add_journal(event: "Hack: #{name} discard =")
@test_game.process_journals
end

# Matches:
Expand All @@ -244,7 +224,10 @@
Given(/^(\w*) ha(?:ve|s) #{CardList}(?: and )?#{NamedRandCards}? in (?:my |his )?discard/) do |name, fixed_list, num_rand, rand_name|
name = 'Alan' if name == 'I'
player = @test_players[name]
player.cards.in_discard.destroy_all


hack_journal = "Hack: #{name} discard = "
hack_cards = []

fixed_list ||= ""
fixed_list.split(/,\s*/).each do |kind|
Expand All @@ -257,7 +240,7 @@

num.times do
@discard_contents[name] << card_name
CARD_TYPES[card_name].create(:location => 'discard', :player => player, :game => player.game)
hack_cards << CARD_TYPES[card_name].name
end
end

Expand All @@ -266,10 +249,12 @@
type = CARD_TYPES.keys[rand(CARD_TYPES.length)]
@discard_contents[name] << type
@named_cards[rand_name].andand << type
CARD_TYPES[type].create(:location => 'discard', :player => player, :game => player.game)
hack_cars << CARD_TYPES[type].name
end

player.renum(:discard)
hack_journal << hack_cards.join(", ")
@test_game.add_journal(event: hack_journal)
@test_game.process_journals
end

# Matches:
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/pending_action_checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
when "Play Action"
'Play an action.'
when "Play Treasure"
/(play_treasure|player_play_treasures;player=#{@test_players[name].id})/
'Play treasures.'
when "Buy"
'Buy.'
end
Expand Down

0 comments on commit 2cd15e5

Please sign in to comment.