Enhance game mechanics to allow extra turns for reaching home positions; fix yellow pawn movement boundary condition
This commit is contained in:
parent
99d24daff2
commit
f142cac64a
@ -15,12 +15,16 @@ module.exports = socket => {
|
||||
const beaten = room.beatPawns(newPositionOfMovedPawn, req.session.color);
|
||||
// If pawn killed any opponent pawns, attacker gets another turn.
|
||||
// Also a roll of 6 grants another turn.
|
||||
if (beaten > 0 || room.rolledNumber === 6) {
|
||||
// Additionally, grant an extra turn when a pawn reaches its final home position.
|
||||
const FINAL_POSITIONS = { red: 73, blue: 79, green: 85, yellow: 91 };
|
||||
const reachedHome = FINAL_POSITIONS[pawn.color] === newPositionOfMovedPawn;
|
||||
const winner = room.getWinner();
|
||||
if ((beaten > 0 || room.rolledNumber === 6 || reachedHome) && !winner) {
|
||||
room.resetTurnForSamePlayer();
|
||||
} else {
|
||||
room.changeMovingPlayer();
|
||||
}
|
||||
const winner = room.getWinner();
|
||||
// const winner = room.getWinner();
|
||||
if (winner) {
|
||||
room.endGame(winner);
|
||||
sendWinner(room._id.toString(), winner);
|
||||
|
||||
@ -85,7 +85,11 @@ const Gameboard = () => {
|
||||
<div className={styles.winnerContainer}>
|
||||
<img src={trophyImage} alt='winner' />
|
||||
<h1>
|
||||
1st: <span style={{ color: winner }}>{winner}</span>
|
||||
{context.color === winner ? (
|
||||
<>You Won!</>
|
||||
) : (
|
||||
<>1st: <span style={{ color: winner }}>{winner}</span></>
|
||||
)}
|
||||
</h1>
|
||||
<button onClick={() => socket.emit('player:exit')}>Play again</button>
|
||||
</div>
|
||||
|
||||
@ -42,7 +42,7 @@ const getPositionAfterMove = (pawn, rolledNumber) => {
|
||||
return position;
|
||||
}
|
||||
case 'yellow':
|
||||
if (pawn.position + rolledNumber <= 85) {
|
||||
if (pawn.position + rolledNumber <= 91) {
|
||||
if (position >= 12 && position <= 15) {
|
||||
return 29;
|
||||
} else if (position <= 67 && position + rolledNumber > 67) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user