Skip to content

Commit

Permalink
Fix counter-countering
Browse files Browse the repository at this point in the history
  • Loading branch information
jaythomas committed Nov 5, 2017
1 parent 213922a commit b272503
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 32 deletions.
11 changes: 3 additions & 8 deletions src/deck.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ const deck = [
attacker.discard = []
player.discard = cards
game.announce('card:grab:counter', { attacker, player })
game.whisperStats(attacker)
},
validatePlay: (player, target, cards, game) => {
if (cards.length < 2) {
Expand All @@ -392,17 +393,13 @@ const deck = [
}
if (cards[1].validateContact) {
const [, ...tail] = cards
if (!cards[1].validateContact(target, player, tail, game)) {
return false
}
return cards[1].validateContact(target, player, tail, game)
}
return true
},
play: (player, target, cards, game) => {
if (target.discard[0]) {
game.contact(target, player, target.discard)
}
game.announce('card:grab:play', { player, target })
game.whisperStats(target)
}
},
{
Expand Down Expand Up @@ -481,8 +478,6 @@ const deck = [
game.announce('card:insurance:counter', { player })
player.afterContact.push(cards[0].afterContact)
game.contact(attacker, player, attacker.discard)
// attacker.discard[0].contact(attacker, player, attacker.discard, game)
// game.discardPile.push(cards[0])
removeOnce(player.afterContact, () => cards[0].afterContact)
game.incrementTurn()
return cards
Expand Down
63 changes: 50 additions & 13 deletions src/deck.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,27 +195,64 @@ Ava.test('Grab should counter', (t) => {
game.start()

const [player1, player2] = game.players
player1.hand = player1.hand.concat([
Deck.getCard('grab'),
Deck.getCard('grab'),
Deck.getCard('gut-punch'),
Deck.getCard('gut-punch')
])
player2.hand = player2.hand.concat([
Deck.getCard('grab'),
Deck.getCard('gut-punch')
])
const grab = Deck.getCard('grab')
const gutPunch = Deck.getCard('gut-punch')
player1.hand = [grab, grab, gutPunch, gutPunch]
player2.hand = [grab, gutPunch]

game.play(player1.id, [Deck.getCard('grab'), Deck.getCard('gut-punch')])
game.play(player2.id, [Deck.getCard('grab'), Deck.getCard('gut-punch')])
game.play(player1.id, [Deck.getCard('grab'), Deck.getCard('gut-punch')])
game.play(player1.id, [grab, gutPunch])
game.play(player2.id, [grab, gutPunch])
game.play(player1.id, [grab, gutPunch])
game.pass(player2.id)
t.is(player1.hp, 8)
t.is(player2.hp, 6)
t.is(game.turns, 1)
t.is(game.discardPile.length, 6)
})

Ava.test('Grab counter should allow another counter', (t) => {
const announceCallback = Sinon.spy()
const whisperCallback = Sinon.spy()
const game = new Junkyard('player1', 'Jay', announceCallback, whisperCallback)
game.addPlayer('user2', 'Kevin')
game.start()

const [player1, player2] = game.players
const grab = Deck.getCard('grab')
const gutPunch = Deck.getCard('gut-punch')
const block = Deck.getCard('block')
player1.hand = [block, grab, gutPunch]
player2.hand = [grab, gutPunch]
game.play(player1, [grab, gutPunch])
game.play(player2, [grab, gutPunch])
game.play(player1, block)

t.true(announceCallback.calledWith('card:block:counter'))
t.is(game.turns, 1)
})

Ava.test('Grab should whisper stats to target when playing and countering', (t) => {
const announceCallback = Sinon.spy()
const whisperCallback = Sinon.spy()
const game = new Junkyard('user1', 'Jay', announceCallback, whisperCallback)
game.addPlayer('user2', 'Kevin')
game.start()

const [player1, player2] = game.players
const grab = Deck.getCard('grab')
const gutPunch = Deck.getCard('gut-punch')
player1.hand = [grab, gutPunch]
player2.hand = [grab, gutPunch]

whisperCallback.reset()
game.play(player1, [grab, gutPunch])
t.true(whisperCallback.calledWith(player2.id, 'player:stats'))

whisperCallback.reset()
game.play(player2, [grab, gutPunch])
t.true(whisperCallback.calledWith(player1.id, 'player:stats'))
})

Ava.test('Acid Coffee should make a player miss a turn', (t) => {
const announceCallback = Sinon.spy()
const game = new Junkyard('player1', 'Jay', announceCallback)
Expand Down
8 changes: 6 additions & 2 deletions src/junkyard.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,12 @@ module.exports = class Junkyard {
this.whisper(player, 'player:not-turn')
return false
}
// Countering the first play
if (this.target && this.target === player) {
// Countering the current-turn player
if (this.target === player) {
return playCounter(player, cards, this)
}
// Countering the target's counter
if (this.target && this.target.discard && player === this.players[0]) {
return playCounter(player, cards, this)
}
let target = null
Expand Down
2 changes: 1 addition & 1 deletion src/phrases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ card:armor:contact:
card:avalanche:
en: Avalanche
card:avalanche:contact:
en: <%= player.name %> causes and avalanche to fall on <%= target.name %>.
en: <%= player.name %> causes an avalanche to fall on <%= target.name %>.
card:block:
en: Block
card:block:counter:
Expand Down
15 changes: 7 additions & 8 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ game.start()

const [player1, player2] = game.players
const grab = Deck.getCard('grab')
const uppercut = Deck.getCard('uppercut')
const insurance = Deck.getCard('insurance')
player1.hand.push(uppercut)
player1.hand.push(grab)
player2.hand.push(insurance)
player2.hp = 5
game.play(player1.id, [grab, uppercut])
game.play(player2.id, insurance)
const gutPunch = Deck.getCard('gut-punch')
const block = Deck.getCard('block')
player1.hand = [block, grab, gutPunch]
player2.hand = [grab, gutPunch]
game.play(player1, [grab, gutPunch])
game.play(player2, [grab, gutPunch])
game.play(player1, block)

0 comments on commit b272503

Please sign in to comment.