Skip to content

Commit

Permalink
feat(hand): inherit from ICardPile
Browse files Browse the repository at this point in the history
  • Loading branch information
mitch-b committed Oct 1, 2017
1 parent 3272e9c commit feb0e29
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/models/cardCollection/hand.interface.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ICard } from '../card/card.interface'
import { ICardCollection } from './cardCollection.interface'
import { ICardPile } from './cardPile.interface'
import { IRankSet } from '../card/rankSet.interface'

export interface IHand extends ICardCollection {
export interface IHand extends ICardPile {
sortCards (cardRank: IRankSet): IHand
playCard (card: ICard): void
}
10 changes: 4 additions & 6 deletions src/models/cardCollection/hand.model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Suit } from '../card/suit.model'
import { CardCollection } from './cardCollection.model'
import { CardPile } from './cardPile.model'
import { MapExtensions } from '../../common/mapExtensions.model'
import { IHand } from './hand.interface'
import { ICard } from '../card/card.interface'
Expand All @@ -8,14 +8,12 @@ import { IRankSet } from '../card/rankSet.interface'
/**
* Represents a group of cards assigned to an IPlayer
*/
export class Hand extends CardCollection implements IHand {

export class Hand extends CardPile implements IHand {
public name = 'Hand'
public suitOrder: Suit[] = [Suit.Clubs, Suit.Spades, Suit.Diamonds, Suit.Hearts]

constructor (cards: ICard[] = []) {
super(cards) // CardCollection.constructor

this.friendlyName = 'Hand' // default name
super(cards) // CardPile.constructor
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/models/cardCollection/hand.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ test('is empty with no cards', async t => {
t.true(hand.isEmpty(), 'isEmpty() should have been true')
})

test('has default name', async t => {
const hand = new Hand()
t.deepEqual(hand.name, 'Hand')
})

test('can assign name', async t => {
const hand = new Hand()
hand.name = 'Player 1 Hand'
t.deepEqual(hand.name, 'Player 1 Hand')
})

test('has cards when initialized with them', async t => {
const cards: ICard[] = [
new PlayingCard(CardName.Eight, Suit.Diamonds),
Expand Down

0 comments on commit feb0e29

Please sign in to comment.