Skip to content

Commit

Permalink
fix: cannot give jersey + remove auto-pass + game progression
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliboy50 committed Jun 18, 2022
1 parent 1e827d3 commit 5d069b7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion velonimo.game.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function getGameProgression() {
$howManyRounds = (int) self::getGameStateValue(self::GAME_OPTION_HOW_MANY_ROUNDS);
$currentRound = ((int) self::getGameStateValue(self::GAME_STATE_CURRENT_ROUND)) ?: 1;

return ((int) floor(($currentRound - 1) / $howManyRounds)) * 100;
return floor((($currentRound - 1) * 100) / $howManyRounds);
}

////////////////////////////////////////////////////////////////////////////
Expand Down
28 changes: 14 additions & 14 deletions velonimo.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ const PLAYERS_PLACES_BY_NUMBER_OF_PLAYERS = {

// @TODO: the cards picked/gave for the impacted players should be picked/gave consecutively (dojo.queue?)
// @TODO: show cards in logs (especially the cards picked/gave for the impacted players)
// @TODO: update text when player cannot play (i.e. you have to pass)
// @TODO: support 2 players game
// @TODO: support "spectators"
// @TODO: support "zombie mode"
Expand Down Expand Up @@ -340,10 +341,6 @@ function (dojo, declare) {
dojo.addClass(`player-table-${data.args.activePlayerId}`, DOM_CLASS_ACTIVE_PLAYER);

this.howManyCardsToGiveBack = data.args.numberOfCards;

if (this.isCurrentPlayerActive()) {
this.unselectAllCards();
}
break;
}
},
Expand Down Expand Up @@ -382,15 +379,15 @@ function (dojo, declare) {
break;
case 'playerTurn':
this.addActionButton(DOM_ID_ACTION_BUTTON_PASS_TURN, _('Pass'), 'onPassTurn');
// check if player can play or auto-pass its turn
if (!this.currentPlayerCanPlayCards()) {
// click on "Pass" after either 5, 6, 7, 8 or 9 seconds
this.clickActionButtonAfterAFewSeconds(DOM_ID_ACTION_BUTTON_PASS_TURN, Math.floor((Math.random() * 5) + 5));
} else {
// add "play cards" button if player can play
if (this.currentPlayerCanPlayCards()) {
this.setupPlayCardsActionButton();
}
break;
case 'playerGiveCardsBackAfterPicking':
if (this.isCurrentPlayerActive()) {
this.unselectAllCards();
}
this.setupGiveCardsBackAfterPickingActionButton();
break;
}
Expand Down Expand Up @@ -420,7 +417,7 @@ function (dojo, declare) {
switch (this.currentState) {
case 'firstPlayerTurn':
case 'playerTurn':
if (isCurrentPlayerActive) {
if (isCurrentPlayerActive && this.currentPlayerCanPlayCards()) {
this.setupPlayCardsActionButton();
}
break;
Expand Down Expand Up @@ -640,6 +637,11 @@ function (dojo, declare) {
}
},
setupGiveCardsBackAfterPickingActionButton: function () {
if (this.playerHand.isSelected(CARD_ID_JERSEY)) {
this.playerHand.unselectItem(CARD_ID_JERSEY);
}
this.displayCardsAsNonSelectable(this.addJerseyToCards([]));

const selectedCards = this.getSelectedPlayerCards();
if (!$(DOM_ID_ACTION_BUTTON_GIVE_CARDS)) {
this.addActionButton(DOM_ID_ACTION_BUTTON_GIVE_CARDS, _('Give selected cards'), () => this.onSelectCardsToGiveBack());
Expand Down Expand Up @@ -1481,7 +1483,6 @@ function (dojo, declare) {
});

this.unselectAllCards();
this.setupPlayCardsActionButton();
},
onPassTurn: function () {
if (!this.checkAction('passTurn')) {
Expand Down Expand Up @@ -1518,9 +1519,8 @@ function (dojo, declare) {
if (!this.checkAction('selectCardsToGiveBack')) {
return;
}

const selectedCards = this.getSelectedPlayerCards().filter((c) => c.id !== CARD_ID_JERSEY);
if (selectedCards.length <= 0) {
const selectedCards = this.getSelectedPlayerCards();
if (selectedCards.length !== this.howManyCardsToGiveBack) {
return;
}

Expand Down

0 comments on commit 5d069b7

Please sign in to comment.