Skip to content

Commit

Permalink
Improving play restrictions.
Browse files Browse the repository at this point in the history
  • Loading branch information
roccotripaldi committed Jul 29, 2017
1 parent 9dba3e2 commit adfbcef
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 37 deletions.
40 changes: 26 additions & 14 deletions client/build/bundle.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -42214,6 +42214,8 @@

var _board = __webpack_require__(403);

var _game2 = __webpack_require__(402);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
Expand Down Expand Up @@ -42288,8 +42290,8 @@
enumerable: true,
writable: true,
value: function value(event) {
var card = _this.props.player.peggingHand[_this.state.selectedPlayCard];
event.preventDefault();
var card = _this.props.player.peggingHand[_this.state.selectedPlayCard];
_this.setState({ selectedPlayCard: -1 });
_this.props.playerPlays(_this.props.sequence, card, _this.props.playersLowestPeg);
}
Expand Down Expand Up @@ -42319,18 +42321,31 @@
}
}, {
key: 'cardIsClickable',
value: function cardIsClickable(selected) {
value: function cardIsClickable(selected, card) {
if (this.props.paused) {
return false;
} else if (selected) {
return true;
} else if ('Player' === this.props.type && 'playerPlays' === this.props.nextAppointment && this.state.selectedPlayCard === -1 && this.props.playerCanPlay) {
} else if ('Player' === this.props.type && 'playerPlays' === this.props.nextAppointment && this.state.selectedPlayCard === -1 && this.props.playerCanPlay && card.value + this.props.playValue <= 31) {
return true;
} else if ('Player' === this.props.type && 'playerDiscards' === this.props.nextAppointment && this.state.selectedCards.length < 2) {
return true;
}
return false;
}
}, {
key: 'getOnClick',
value: function getOnClick(clickable) {
if (!clickable) {
return null;
}
if ('Player' === this.props.type && 'playerDiscards' === this.props.nextAppointment && !this.props.paused) {
return this.handleDiscardClick;
} else if ('Player' === this.props.type && 'playerPlays' === this.props.nextAppointment && !this.props.paused && this.props.playerCanPlay) {
return this.handlePlayClick;
}
return null;
}
}, {
key: 'renderCrib',
value: function renderCrib() {
Expand Down Expand Up @@ -42390,9 +42405,8 @@
initialDraw = _props$player2.initialDraw,
peggingHand = _props$player2.peggingHand;

var cards = void 0,
onClick = null,
selected = false;
var cards = void 0;

if ((0, _isEmpty2.default)(hand) && (0, _isEmpty2.default)(initialDraw)) {
return null;
}
Expand All @@ -42405,24 +42419,21 @@
cards = hand;
}

if ('Player' === this.props.type && 'playerDiscards' === this.props.nextAppointment && !this.props.paused) {
onClick = this.handleDiscardClick;
} else if ('Player' === this.props.type && 'playerPlays' === this.props.nextAppointment && !this.props.paused && this.props.playerCanPlay) {
onClick = this.handlePlayClick;
}
return _react2.default.createElement(
'div',
{ className: 'cards' },
cards.map(function (card, index) {
var selected = _this3.state.selectedCards.includes(index) || _this3.state.selectedPlayCard === index;
var selected = _this3.state.selectedCards.includes(index) || _this3.state.selectedPlayCard === index,
clickable = _this3.cardIsClickable(selected, card),
onClick = _this3.getOnClick(clickable);
return _react2.default.createElement(_card2.default, {
key: card.name + card.suit,
card: card,
faceDown: _this3.isHandFaceDown(),
onClick: onClick,
index: index,
selected: selected,
clickable: _this3.cardIsClickable(selected)
clickable: clickable
});
})
);
Expand Down Expand Up @@ -42486,7 +42497,8 @@
sequence: (0, _game.getPlaySequence)(state),
playersLowestPeg: (0, _board.getLowestPegForPerson)(state, 'Player'),
peggingCards: (0, _game.getPeggingCards)(state),
playerCanPlay: (0, _game.canPersonPlay)(state, 'player')
playerCanPlay: (0, _game.canPersonPlay)(state, 'player'),
playValue: (0, _game2.getPlayValue)(state)
};
}, { playerDiscards: _player.playerDiscards, playerPlays: _player.playerPlays })(Hand);

Expand Down
2 changes: 1 addition & 1 deletion client/build/bundle.min.js.map

Large diffs are not rendered by default.

57 changes: 35 additions & 22 deletions client/components/hand/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { getNextAppointment, isPaused } from 'state/selectors/controller';
import { playerDiscards, playerPlays } from 'state/actions/player';
import { getDealer, getScore, getPlaySequence, getPeggingCards, canPersonPlay } from 'state/selectors/game';
import { getLowestPegForPerson } from 'state/selectors/board';
import { getPlayValue } from "../../state/selectors/game";

class Hand extends Component {
constructor( props ) {
Expand Down Expand Up @@ -91,8 +92,8 @@ class Hand extends Component {
};

handlePlay = ( event ) => {
const card = this.props.player.peggingHand[ this.state.selectedPlayCard ];
event.preventDefault();
const card = this.props.player.peggingHand[ this.state.selectedPlayCard ];
this.setState( { selectedPlayCard: -1 } );
this.props.playerPlays(
this.props.sequence,
Expand All @@ -101,7 +102,7 @@ class Hand extends Component {
);
};

cardIsClickable( selected ) {
cardIsClickable( selected, card ) {
if ( this.props.paused ) {
return false;
} else if ( selected ) {
Expand All @@ -110,7 +111,8 @@ class Hand extends Component {
'Player' === this.props.type &&
'playerPlays' === this.props.nextAppointment &&
this.state.selectedPlayCard === -1 &&
this.props.playerCanPlay
this.props.playerCanPlay &&
( card.value + this.props.playValue <= 31 )
) {
return true;
} else if (
Expand All @@ -123,6 +125,27 @@ class Hand extends Component {
return false;
}

getOnClick( clickable ) {
if ( ! clickable ) {
return null;
}
if (
'Player' === this.props.type &&
'playerDiscards' === this.props.nextAppointment &&
! this.props.paused
) {
return this.handleDiscardClick;
} else if (
'Player' === this.props.type &&
'playerPlays' === this.props.nextAppointment &&
! this.props.paused &&
this.props.playerCanPlay
) {
return this.handlePlayClick;
}
return null;
}

renderCrib() {
const { crib } = this.props.player;

Expand Down Expand Up @@ -154,14 +177,15 @@ class Hand extends Component {
if( isEmpty( hand ) && isEmpty( initialDraw ) ) {
return null;
}
person = ( this.props.type === 'Player' ) ? 'Your' : "Opponent's"
person = ( this.props.type === 'Player' ) ? 'Your' : "Opponent's";
label = isEmpty( hand ) ? 'Initial Draw' : person + ' hand:';
return <p>{ label }</p>;
}

renderCards() {
const { hand, initialDraw, peggingHand } = this.props.player;
let cards, onClick = null, selected = false;
let cards;

if( isEmpty( hand ) && isEmpty( initialDraw ) ) {
return null;
}
Expand All @@ -174,25 +198,13 @@ class Hand extends Component {
cards = hand;
}

if (
'Player' === this.props.type &&
'playerDiscards' === this.props.nextAppointment &&
! this.props.paused
) {
onClick = this.handleDiscardClick;
} else if (
'Player' === this.props.type &&
'playerPlays' === this.props.nextAppointment &&
! this.props.paused &&
this.props.playerCanPlay
) {
onClick = this.handlePlayClick;
}
return (
<div className="cards">
{ cards.map( ( card, index ) => {
const selected = this.state.selectedCards.includes( index ) ||
this.state.selectedPlayCard === index;
this.state.selectedPlayCard === index,
clickable = this.cardIsClickable( selected, card ),
onClick = this.getOnClick( clickable );
return (
<Card
key={ card.name + card.suit }
Expand All @@ -201,7 +213,7 @@ class Hand extends Component {
onClick={ onClick }
index={ index }
selected={ selected }
clickable={ this.cardIsClickable( selected ) }
clickable={ clickable }
/>
)
} ) }
Expand Down Expand Up @@ -254,7 +266,8 @@ export default connect(
sequence: getPlaySequence( state ),
playersLowestPeg: getLowestPegForPerson( state, 'Player' ),
peggingCards: getPeggingCards( state ),
playerCanPlay: canPersonPlay( state, 'player' )
playerCanPlay: canPersonPlay( state, 'player' ),
playValue: getPlayValue( state )
}
},
{ playerDiscards, playerPlays }
Expand Down

0 comments on commit adfbcef

Please sign in to comment.