e-champ-durak
Advanced tools
Comparing version 1.4.1 to 1.4.2
@@ -16,3 +16,5 @@ /** | ||
validateBase () { | ||
return this.validatePlayer() && this.validateActiveRound() && this.validateTurned(); | ||
return this.validatePlayer() | ||
&& this.validateActiveRound() | ||
&& this.validateTurned(); | ||
} | ||
@@ -19,0 +21,0 @@ |
@@ -32,4 +32,8 @@ /** | ||
play.addEvent('pass', [this.hand.pos]); | ||
if (this.hand === play.defender && play.changedDefendingCards && !play.options.stopAttackOnPickingUp) { | ||
play.updateTurnedHands(); | ||
if (this.hand === play.defender) { | ||
if (play.changedDefendingCards) { | ||
if (!play.options.stopAttackOnPickingUp) { | ||
play.updateTurnedHands(); | ||
} | ||
} | ||
} | ||
@@ -36,0 +40,0 @@ this.hand.turned = true; |
@@ -48,5 +48,7 @@ /** | ||
const openAttacks = this.countOpenAttacks(); | ||
if (this.options.transferable && openAttacks && openAttacks === this.table.length) { | ||
this.transferTarget = this.getTransferTarget(); | ||
return Number.isInteger(this.transferTarget); | ||
if (this.options.transferable && openAttacks) { | ||
if (openAttacks === this.table.length) { | ||
this.transferTarget = this.getTransferTarget(); | ||
return Number.isInteger(this.transferTarget); | ||
} | ||
} | ||
@@ -94,3 +96,5 @@ } | ||
cards = this.getCardsToDefend(attacking, cards); | ||
return cards.length ? this.filterLowestCards(cards)[0] : null; | ||
return cards.length | ||
? this.filterLowestCards(cards)[0] | ||
: null; | ||
} | ||
@@ -141,3 +145,5 @@ | ||
isLonelyAttack () { | ||
return this.stock === 0 && this.cards.length > 1 && this.isOtherHandsEmpty(); | ||
return this.stock === 0 | ||
&& this.cards.length > 1 | ||
&& this.isOtherHandsEmpty(); | ||
} | ||
@@ -160,3 +166,4 @@ | ||
canDefend (attacking) { | ||
for (const defending of this.hands[this.defender][1]) { | ||
const hands = this.hands[this.defender][1]; | ||
for (const defending of hands) { | ||
if (this.canBeat(attacking, defending)) { | ||
@@ -184,4 +191,6 @@ return true; | ||
for (let i = 0; i < this.hands.length; ++i) { | ||
if (this.attacker !== i && this.defender !== i && this.hands[i][0] > 0) { | ||
return false; | ||
if (this.attacker !== i && this.defender !== i) { | ||
if (this.hands[i][0] > 0) { | ||
return false; | ||
} | ||
} | ||
@@ -227,5 +236,8 @@ } | ||
for (const [attacking, defending] of this.table) { | ||
if (attacking.rank === rank || (siege && defending?.rank === rank)) { | ||
if (attacking.rank === rank) { | ||
return true; | ||
} | ||
if (siege && defending?.rank === rank) { | ||
return true; | ||
} | ||
} | ||
@@ -275,4 +287,10 @@ return false; | ||
} | ||
return this.isTrump(a) ? 1 : this.isTrump(b) ? -1 : a.rank - b.rank; | ||
if (this.isTrump(a)) { | ||
return 1; | ||
} | ||
if (this.isTrump(b)) { | ||
return -1; | ||
} | ||
return a.rank - b.rank; | ||
} | ||
}; |
{ | ||
"name": "e-champ-durak", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"description": "Online card game Durak for the E-Champ platform", | ||
"author": "Maxim Khorin", | ||
"author": { | ||
"name": "Maxim Khorin", | ||
"email": "maksimovichu@gmail.com" | ||
}, | ||
"license": "Apache-2.0", | ||
@@ -7,0 +10,0 @@ "repository": { |
@@ -90,3 +90,4 @@ /** | ||
if (!this.roundLoser) { | ||
return (this.trump && this.getHandWithLowestTrump()) || this.getHandWithLowestCard(); | ||
return (this.trump && this.getHandWithLowestTrump()) | ||
|| this.getHandWithLowestCard(); | ||
} | ||
@@ -183,3 +184,4 @@ return this.options.attackLoser | ||
getHandByPos (pos) { | ||
return this.hands[(pos + this.hands.length) % this.hands.length]; | ||
const index = (pos + this.hands.length) % this.hands.length; | ||
return this.hands[index]; | ||
} | ||
@@ -189,3 +191,4 @@ | ||
const deals = []; | ||
for (const hand of this.sortHandsToDeal()) { | ||
const hands = this.sortHandsToDeal(); | ||
for (const hand of hands) { | ||
const requires = this.countRequiredCards(hand); | ||
@@ -215,3 +218,4 @@ if (requires) { | ||
for (const deal of deals) { | ||
const cards = this.stock.getDealCards(deal.requires > max ? max : deal.requires); | ||
const requires = deal.requires > max ? max : deal.requires; | ||
const cards = this.stock.getDealCards(requires); | ||
if (cards.length) { | ||
@@ -282,3 +286,4 @@ deal.requires -= cards.length; | ||
canDefendAll () { | ||
for (const attacking of this.table.getOpenAttacks()) { | ||
const attacks = this.table.getOpenAttacks(); | ||
for (const attacking of attacks) { | ||
if (!this.canDefend(attacking)) { | ||
@@ -311,5 +316,7 @@ return false; | ||
updateFacedCards () { | ||
if (!this.allCardsFaced && this.emptyHands.length + 2 === this.hands.length && this.stock.isEmpty()) { | ||
this.hands.forEach(card => card.faced = true); | ||
this.allCardsFaced = true; | ||
if (!this.allCardsFaced && this.stock.isEmpty()) { | ||
if (this.emptyHands.length + 2 === this.hands.length) { | ||
this.hands.forEach(card => card.faced = true); | ||
this.allCardsFaced = true; | ||
} | ||
} | ||
@@ -341,3 +348,5 @@ } | ||
if (this.table.countAttacks()) { | ||
this.table.hasOpenAttack() ? this.pickUpTable() : this.discardTable(); | ||
this.table.hasOpenAttack() | ||
? this.pickUpTable() | ||
: this.discardTable(); | ||
} | ||
@@ -364,3 +373,4 @@ this.table.clear(); | ||
discardTable () { | ||
this.discard.add(this.table.getCards()); | ||
const cards = this.table.getCards(); | ||
this.discard.add(cards); | ||
this.addEvent('discard'); | ||
@@ -371,3 +381,4 @@ } | ||
this.picked = true; | ||
this.defender.add(this.table.getCards()); | ||
const cards = this.table.getCards(); | ||
this.defender.add(cards); | ||
this.updateEmptyHands(this.defender); | ||
@@ -384,7 +395,11 @@ this.addEvent('pickUp', [this.defender.pos]); | ||
if (attacker) { | ||
return attacker?.isBot() ? this.startBot(attacker) : null; | ||
return attacker?.isBot() | ||
? this.startBot(attacker) | ||
: null; | ||
} | ||
} | ||
if (!this.defender.turned && this.defender.isBot() && this.table.hasOpenAttack()) { | ||
this.startBot(this.defender); | ||
if (!this.defender.turned && this.defender.isBot()) { | ||
if (this.table.hasOpenAttack()) { | ||
this.startBot(this.defender); | ||
} | ||
} | ||
@@ -394,3 +409,4 @@ } | ||
startBot (hand) { | ||
hand.player.createSolver(this.createSnapshot(hand)); | ||
const data = this.createSnapshot(hand); | ||
hand.player.createSolver(data); | ||
} | ||
@@ -416,3 +432,4 @@ | ||
for (const hand of this.hands) { | ||
result.push(hand.serializeFacedCards()); | ||
const data = hand.serializeFacedCards(); | ||
result.push(data); | ||
} | ||
@@ -419,0 +436,0 @@ return result; |
@@ -120,3 +120,4 @@ /** | ||
for (let i = 0; i < counter; ++i) { | ||
const player = this.getPlayer((this.attacker.pos + i) % counter); | ||
const pos = (this.attacker.pos + i) % counter; | ||
const player = this.getPlayer(pos); | ||
if (this.isReadyToAttack(player)) { | ||
@@ -134,4 +135,6 @@ return player; | ||
for (let num = 1; num < Club.Durak.MAX_PLAYERS; ++num) { | ||
$opponents.append(this.resolveTemplate('opponent', {num})); | ||
this.players.push(new Club.DurakOpponent(num, this)); | ||
const content = this.resolveTemplate('opponent', {num}); | ||
$opponents.append(content); | ||
const player = new Club.DurakOpponent(num, this); | ||
this.players.push(player); | ||
} | ||
@@ -180,5 +183,7 @@ Jam.t($opponents); | ||
for (let i = 1; i < counter; ++i) { | ||
const player = this.getPlayer((this.defender.pos + i) % counter); | ||
if (player.cards.count() > 0) { | ||
return player.cards.count() > this.table.countAttacks() ? player : null; | ||
const pos = (this.defender.pos + i) % counter; | ||
const player = this.getPlayer(pos); | ||
const numCards = player.cards.count(); | ||
if (numCards) { | ||
return numCards > this.table.countAttacks() ? player : null; | ||
} | ||
@@ -205,3 +210,5 @@ } | ||
isReadyToAttack (player) { | ||
return !player.turned && player !== this.defender && player.cards.count(); | ||
return !player.turned | ||
&& player !== this.defender | ||
&& player.cards.count(); | ||
} | ||
@@ -208,0 +215,0 @@ |
@@ -59,5 +59,5 @@ /** | ||
afterCardMove ([card, data, player]) { | ||
data ? this.openCard(card, data) | ||
: this.closeCard(card); | ||
player.cards.setCardOrder(card, player.getRightSidePlayerLastCard()); | ||
data ? this.openCard(card, data) : this.closeCard(card); | ||
const last = player.getRightSidePlayerLastCard(); | ||
player.cards.setCardOrder(card, last); | ||
} | ||
@@ -64,0 +64,0 @@ |
@@ -65,4 +65,5 @@ /** | ||
openCard (card, index) { | ||
card.open(this.items[index][1].rank, this.items[index][1].suit); | ||
const {rank, suit} = this.items[index][1]; | ||
card.open(rank, suit); | ||
} | ||
}; |
@@ -28,3 +28,4 @@ /** | ||
const list = Club.getElementRect(this.$cards); | ||
this.cards.setCardOrder(this.cards.get(0), this.getRightSidePlayerLastCard()); | ||
const last = this.getRightSidePlayerLastCard(); | ||
this.cards.setCardOrder(this.cards.get(0), last); | ||
this.cards.setOffset(rect.x + list.x, rect.y + list.y, list.w); | ||
@@ -31,0 +32,0 @@ this.cards.arrange(); |
@@ -150,8 +150,10 @@ /** | ||
incrementStatCounter ($stat) { | ||
$stat.html(parseInt($stat.html()) + 1); | ||
const counter = parseInt($stat.html()) + 1; | ||
$stat.html(counter); | ||
} | ||
getStatusOffset () { | ||
return this.play.getOffset(this.$container.find('.player-status').first()); | ||
const $status = this.$container.find('.player-status').first(); | ||
return this.play.getOffset($status); | ||
} | ||
}; |
@@ -40,5 +40,3 @@ /** | ||
this.cards.arrange(); | ||
if (this.trumpCard) { | ||
this.trumpCard.setOffset(rect.x, rect.y); | ||
} | ||
this.trumpCard?.setOffset(rect.x, rect.y); | ||
} | ||
@@ -45,0 +43,0 @@ |
@@ -20,5 +20,8 @@ /** | ||
for (const [attacking, defending] of this.pairs) { | ||
if (attacking.getRank() === rank || (defending?.getRank() === rank)) { | ||
if (attacking.getRank() === rank) { | ||
return true; | ||
} | ||
if (defending?.getRank() === rank) { | ||
return true; | ||
} | ||
} | ||
@@ -124,3 +127,4 @@ } | ||
const cards = []; | ||
for (const attacking of this.getOpenAttackingCards()) { | ||
const attacks = this.getOpenAttackingCards(); | ||
for (const attacking of attacks) { | ||
if (this.play.canBeat(attacking, defending)) { | ||
@@ -144,3 +148,4 @@ cards.push(attacking); | ||
getAttackingOffset (card) { | ||
const [dx, dy] = this.getOffsetStep(this.countAttacks()); | ||
const attacks = this.countAttacks(); | ||
const [dx, dy] = this.getOffsetStep(attacks); | ||
const index = this.getAttackingIndex(card); | ||
@@ -154,3 +159,4 @@ return [ | ||
getAttackingIndex (card) { | ||
for (let i = 0; i < this.countAttacks(); ++i) { | ||
const attacks = this.countAttacks(); | ||
for (let i = 0; i < attacks; ++i) { | ||
if (this.pairs[i][0] === card) { | ||
@@ -163,3 +169,4 @@ return i; | ||
getDefendingOffset (card) { | ||
const [dx, dy] = this.getOffsetStep(this.countAttacks()); | ||
const attacks = this.countAttacks(); | ||
const [dx, dy] = this.getOffsetStep(attacks); | ||
const index = this.getDefendingIndex(card); | ||
@@ -173,3 +180,4 @@ return [ | ||
getDefendingIndex (card) { | ||
for (let i = 0; i < this.countAttacks(); ++i) { | ||
const attacks = this.countAttacks(); | ||
for (let i = 0; i < attacks; ++i) { | ||
if (this.pairs[i][1] === card) { | ||
@@ -182,4 +190,5 @@ return i; | ||
getOffsetStep (total) { | ||
const space = this.constructor.MAX_CARD_SPACE; | ||
const cardWidth = this.play.getCardWidth(); | ||
return [Club.getOffsetStep(this.rect.w, cardWidth, total, this.constructor.MAX_CARD_SPACE), 0]; | ||
return [Club.getOffsetStep(this.rect.w, cardWidth, total, space), 0]; | ||
} | ||
@@ -186,0 +195,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
3500
226653