Skip to content

Commit

Permalink
Player can stand, player or house can win the game after stand.
Browse files Browse the repository at this point in the history
  • Loading branch information
mavarius committed Sep 25, 2016
1 parent 219e0f2 commit 02342d8
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 11 deletions.
14 changes: 10 additions & 4 deletions src/actions/DeckActions.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import AppDispatcher from '../AppDispatcher';

const DeckActions = {
shuffle(deck) {
shuffle() {
AppDispatcher.dispatch({
type: 'SHUFFLE_DECK'
})
},

hitMe(deck) {

hitMe() {
AppDispatcher.dispatch({
type: 'HIT_ME'
})
},

stand() {
AppDispatcher.dispatch({
type: 'HIT_ME',
type: 'STAND'
})
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/components/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export default class Table extends Component {
DeckActions.hitMe();
}

_stand() {
DeckActions.stand();
}

_onChange() {
this.setState( DeckStore.getAll() )
}
Expand All @@ -53,8 +57,8 @@ export default class Table extends Component {
</div>
<div className="row buttons">
<button onClick={this._newGame} className="btn btn-success">NEW GAME</button>
{ player.total > 0 && player.total <= 21 ? <button onClick={this._hitMe} className="btn btn-danger">HIT ME</button> : <button onClick={this._hitMe} className="btn btn-danger" disabled>HIT ME</button> }
{ player.total > 0 && player.total <= 21 ? <button className="btn btn-primary">STAND</button> : <button className="btn btn-primary" disabled>STAND</button> }
{ player.total > 0 && player.total <= 21 && dealer.hidden.length !== 0 ? <button onClick={this._hitMe} className="btn btn-danger">HIT ME</button> : <button className="btn btn-danger" disabled>HIT ME</button> }
{ player.total > 0 && player.total <= 21 && dealer.hidden.length !== 0 ? <button onClick={this._stand} className="btn btn-primary">STAND</button> : <button className="btn btn-primary" disabled>STAND</button> }
</div>
</div>
)
Expand Down
2 changes: 1 addition & 1 deletion src/css/stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ h2 {
}

.playerWell {
width: 400px;
width: 500px;
}

.playingCard span {
Expand Down
45 changes: 41 additions & 4 deletions src/stores/DeckStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let _player = { hand: [], total: 0, message: 'Player' };
let _playDeck = [];

let _deck = [
{suit: 'spades', value: [11, 1], img: '🂡'},
{suit: 'spades', value: [1, 11], img: '🂡'},
{suit: 'spades', value: 2, img: '🂢'},
{suit: 'spades', value: 3, img: '🂣'},
{suit: 'spades', value: 4, img: '🂤'},
Expand All @@ -22,7 +22,7 @@ let _deck = [
{suit: 'spades', value: 10, img: '🂫'},
{suit: 'spades', value: 10, img: '🂭'},
{suit: 'spades', value: 10, img: '🂮'},
{suit: 'hearts', value: [11, 1], img: '🂱'},
{suit: 'hearts', value: [1, 11], img: '🂱'},
{suit: 'hearts', value: 2, img: '🂲'},
{suit: 'hearts', value: 3, img: '🂳'},
{suit: 'hearts', value: 4, img: '🂴'},
Expand All @@ -35,7 +35,7 @@ let _deck = [
{suit: 'hearts', value: 10, img: '🂻'},
{suit: 'hearts', value: 10, img: '🂽'},
{suit: 'hearts', value: 10, img: '🂾'},
{suit: 'diamonds', value: [11, 1], img: '🃁'},
{suit: 'diamonds', value: [1, 11], img: '🃁'},
{suit: 'diamonds', value: 2, img: '🃂'},
{suit: 'diamonds', value: 3, img: '🃃'},
{suit: 'diamonds', value: 4, img: '🃄'},
Expand All @@ -48,7 +48,7 @@ let _deck = [
{suit: 'diamonds', value: 10, img: '🃋'},
{suit: 'diamonds', value: 10, img: '🃍'},
{suit: 'diamonds', value: 10, img: '🃎'},
{suit: 'clubs', value: [11, 1], img: '🃑'},
{suit: 'clubs', value: [1, 11], img: '🃑'},
{suit: 'clubs', value: 2, img: '🃒'},
{suit: 'clubs', value: 3, img: '🃓'},
{suit: 'clubs', value: 4, img: '🃔'},
Expand Down Expand Up @@ -82,6 +82,7 @@ class DeckStore extends EventEmitter {
case 'SHUFFLE_DECK':
_playDeck = lodash.shuffle(_deck);
_dealer.hand = [];
_dealer.hidden = [];
_player.hand = [];

_dealer.hidden.push(_playDeck.pop());
Expand All @@ -106,10 +107,46 @@ class DeckStore extends EventEmitter {

if (_player.total > 21 ) {
_player.message = `BUST! ${_player.total}`;
_dealer.message = `House Wins!`;
} else {
_player.message = `Player: ${_player.total}`;
}

this.emit('CHANGE');
break;

case 'STAND':
_dealer.hand.push(_dealer.hidden.pop());
_dealer.total = getTotal(_dealer);
_dealer.message = `Dealer: ${_dealer.total}`;

if (_dealer.total > 21) {
_player.message = `You Win! ${_player.total}`;
_dealer.message = `BUST! ${_dealer.total}`;
} else if (_dealer.total === 21) {
if (_player.total === 21) {
_player.message = `PUSH ${_player.total}`;
_dealer.message = `PUSH ${_dealer.total}`;
} else {
_dealer.message = `House Wins! ${_dealer.total}`;
}
} else if (_dealer.total < 17) {
while (_dealer.total < 21) {
_dealer.hand.push(_playDeck.pop());
_dealer.total = getTotal(_dealer);
_dealer.message = `Dealer: ${_dealer.total}`;
this.emit('CHANGE');
}
if (_dealer.total < _player.total) {
_player.message = `You Win! ${_player.total}`;
} else if (_dealer.total > 21) {
_player.message = `You Win! ${_player.total}`;
_dealer.message = `BUST! ${_dealer.total}`;
} else {
_dealer.message = `House Wins! ${_dealer.total}`;
}
}

this.emit('CHANGE');
break;
}
Expand Down

0 comments on commit 02342d8

Please sign in to comment.