-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from vmolero/develop
Change to immutable objects
- Loading branch information
Showing
7 changed files
with
148 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,19 @@ | ||
import Hand from './Hand'; | ||
import Card from './Card'; | ||
import CardDeck from './CardDeck'; | ||
import House from './House'; | ||
import Player from './Player'; | ||
|
||
export default class Deal { | ||
public readonly SCORE_THRESHOLD: number = 21; | ||
|
||
// private cardCount: number = 0; | ||
private dealOver: boolean = false; | ||
private house: House; | ||
private players: Array<Player>; | ||
private cardDeck: CardDeck; | ||
|
||
public constructor(cardDeck?: CardDeck) { | ||
this.cardDeck = cardDeck || CardDeck.createStandard52CardDeck(); | ||
this.house = new House(); | ||
this.players = new Array<Player>(); | ||
this.cardDeck.shuffle(); | ||
} | ||
|
||
public setHouse(house: House): Deal { | ||
this.house = house; | ||
|
||
return this; | ||
} | ||
|
||
public getHouse(): House { | ||
return this.house; | ||
} | ||
|
||
public addPlayer(player: Player) { | ||
this.players.push(player); | ||
} | ||
|
||
public getPlayer(order: number): Player { | ||
if (this.players[order - 1] !== undefined) { | ||
return this.players[order - 1]; | ||
} | ||
throw new Error('Player not found'); | ||
} | ||
|
||
public getPlayerHand(): Hand { | ||
return this.getPlayer(1).getHand(); | ||
} | ||
|
||
public getHouseHand(): Hand { | ||
return this.house.getHand(); | ||
} | ||
|
||
public getPlayerScore(): number { | ||
return this.getPlayerHand().getScore(); | ||
} | ||
|
||
public getHouseScore(): number { | ||
return this.house.getScore(); | ||
} | ||
|
||
public pullPlayerCard() { | ||
try { | ||
let card: Card = this.cardDeck.popCard(); | ||
this.getPlayer(1).pullCard(card); | ||
} catch (doNothingOnEmptyDeck) { | ||
this.dealOver = true; | ||
} | ||
} | ||
|
||
public pullHouseCard() { | ||
public pullCard(): Card { | ||
try { | ||
let card: Card = this.cardDeck.popCard(); | ||
this.getHouseHand().add(card); | ||
|
||
return this.cardDeck.popCard(); | ||
} catch (doNothingOnEmptyDeck) { | ||
this.dealOver = true; | ||
throw Error('No cards'); | ||
} | ||
} | ||
|
||
public setDealOver() { | ||
this.dealOver = true; | ||
} | ||
|
||
public isDealOver(): boolean { | ||
return this.dealOver; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.