Skip to content

Commit

Permalink
feat: add jersey in player hand
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliboy50 committed Jun 18, 2022
1 parent f806ccf commit a9f5a64
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 99 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

- Resize 180px wide PNG card images to be 90px wide and create sprite from them:
```shell
magick montage $(ls blue-*.png) $(ls brown-*.png) $(ls gray-*.png) $(ls green-*.png) $(ls pink-*.png) $(ls red-*.png) $(ls yellow-*.png) $(ls adventurer-*.png) back.png -geometry +0+0 -tile 7x8 -mode concatenate -background none -resize 90 montage.png
magick montage $(ls blue-*.png) $(ls brown-*.png) $(ls gray-*.png) $(ls green-*.png) $(ls pink-*.png) $(ls red-*.png) $(ls yellow-*.png) jersey.png $(ls adventurer-*.png) -geometry +0+0 -tile 7x8 -mode concatenate -background none -resize 90 montage.png
```
- Reduce generated sprite size by ~90% sending it to https://tinypng.com

Expand Down
Binary file modified img/cards.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions modules/constants.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
define('COLOR_RED', 60);
define('COLOR_YELLOW', 70);
define('COLOR_ADVENTURER', 80);
define('COLOR_JERSEY', 90);

// Cards value
define('VALUE_1', 1);
Expand All @@ -43,6 +44,4 @@
define('VALUE_40', 40);
define('VALUE_45', 45);
define('VALUE_50', 50);

// Jersey value
define('JERSEY_VALUE', 10);
define('VALUE_JERSEY', 10);
38 changes: 9 additions & 29 deletions velonimo.css
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Board
transition-duration: 0.4s;
}
.player-table.is-wearing-jersey .player-table-hand {
margin: 5px 0 0 -5px;
margin: 5px 0 0 -6px;
}
.player-table-hand .number-of-cards {
position: absolute;
Expand Down Expand Up @@ -189,11 +189,11 @@ Board
}
.player-table.is-wearing-jersey .player-table-jersey {
position: absolute;
bottom: 10px;
right: 0;
width: 60px;
height: 83px;
background-size: 60px 83px;
bottom: 7px;
right: -1px;
width: 65px;
height: 90px;
background-size: 65px 90px;
background-image: url('img/jersey.png');
background-repeat: no-repeat;
background-position: center center;
Expand All @@ -204,26 +204,6 @@ Board
.player-table.is-wearing-jersey.has-used-jersey .player-table-jersey {
opacity: 0.2;
}
/* @TODO: try to only reduce opacity of jersey instead of using a cross overlay */
.player-table.is-wearing-jersey.has-used-jersey .jersey-overlay {
display: block;
position: relative;
top: 20px;
height: 50px;
width: 10px;
margin: 0 auto;
background: black;
transform: rotate(45deg);
}
.player-table.is-wearing-jersey.has-used-jersey .jersey-overlay::after {
content: "";
position: absolute;
left: -20px;
top: 20px;
width: 50px;
height: 10px;
background: black;
}
/**
END Board
*/
Expand Down Expand Up @@ -341,9 +321,9 @@ Animations
*/
.moving-jersey {
position: absolute;
width: 60px;
height: 83px;
background-size: 60px 83px;
width: 65px;
height: 90px;
background-size: 65px 90px;
background-image: url('img/jersey.png');
background-repeat: no-repeat;
z-index: 100;
Expand Down
21 changes: 13 additions & 8 deletions velonimo.game.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Velonimo extends Table

private const GAME_STATE_CURRENT_ROUND = 'currentRound';
private const GAME_STATE_JERSEY_HAS_BEEN_USED_IN_THE_CURRENT_ROUND = 'jerseyUsedInRound';
private const GAME_STATE_PREVIOUS_PLAYED_CARDS_VALUE = 'previousValueToBeat';
private const GAME_STATE_LAST_PLAYED_CARDS_VALUE = 'valueToBeat';
private const GAME_STATE_LAST_PLAYED_CARDS_PLAYER_ID = 'playerIdForValueToBeat';
private const GAME_STATE_LAST_SELECTED_NEXT_PLAYER_ID = 'selectedNextPlayerId';
Expand Down Expand Up @@ -65,6 +66,7 @@ function __construct() {
self::GAME_STATE_LAST_NUMBER_OF_CARDS_TO_PICK => 15,
self::GAME_STATE_LAST_NUMBER_OF_CARDS_TO_GIVE_BACK => 16,
self::GAME_STATE_LAST_PLAYER_ID_TO_GIVE_CARDS_BACK => 17,
self::GAME_STATE_PREVIOUS_PLAYED_CARDS_VALUE => 18,
self::GAME_OPTION_HOW_MANY_ROUNDS => 100,
]);

Expand Down Expand Up @@ -118,6 +120,7 @@ protected function setupNewGame($players, $options = []) {

// Init global values with their initial values
self::setGameStateValue(self::GAME_STATE_CURRENT_ROUND, 0);
self::setGameStateValue(self::GAME_STATE_PREVIOUS_PLAYED_CARDS_VALUE, 0);
self::setGameStateValue(self::GAME_STATE_LAST_PLAYED_CARDS_VALUE, 0);
self::setGameStateValue(self::GAME_STATE_LAST_PLAYED_CARDS_PLAYER_ID, 0);
self::setGameStateValue(self::GAME_STATE_LAST_SELECTED_NEXT_PLAYER_ID, 0);
Expand Down Expand Up @@ -217,6 +220,7 @@ protected function getAllDatas() {
$result['previousPlayedCards'] = $this->formatCardsForClient(
$this->fromBgaCardsToVelonimoCards($this->deck->getCardsInLocation(self::CARD_LOCATION_PREVIOUS_PLAYED))
);
$result['previousPlayedCardsValue'] = (int) self::getGameStateValue(self::GAME_STATE_PREVIOUS_PLAYED_CARDS_VALUE);

return $result;
}
Expand Down Expand Up @@ -334,6 +338,7 @@ function playCards(array $playedCardIds, bool $cardsPlayedWithJersey) {
self::setGameStateValue(self::GAME_STATE_JERSEY_HAS_BEEN_USED_IN_THE_CURRENT_ROUND, 1);
}
self::setGameStateValue(self::GAME_STATE_LAST_PLAYED_CARDS_PLAYER_ID, $currentPlayerId);
self::setGameStateValue(self::GAME_STATE_PREVIOUS_PLAYED_CARDS_VALUE, $lastPlayedCardsValue);
self::setGameStateValue(self::GAME_STATE_LAST_PLAYED_CARDS_VALUE, $playedCardsValue);
self::notifyAllPlayers('cardsPlayed', clienttranslate('${playerName} plays ${playedCardsValue}'), [
'playedCardsPlayerId' => $currentPlayerId,
Expand Down Expand Up @@ -681,7 +686,7 @@ function argPlayerGiveCardsBackAfterPicking() {
*/

function stStartRound() {
$this->discardLastPlayedCards();
$this->discardPlayedCards();
// take back all cards and shuffle them
$this->deck->moveAllCardsInLocation(null, self::CARD_LOCATION_DECK);
$this->deck->shuffle(self::CARD_LOCATION_DECK);
Expand Down Expand Up @@ -733,7 +738,7 @@ function stActivateNextPlayer() {
$nextPlayerCanPlay = in_array($nextPlayerId, $playersWhoCanPlayIds, true);
// if the next player is the one who played the last played cards, remove the cards from the table
if ($nextPlayerId === $playerIdWhoPlayedTheLastCards) {
$this->discardLastPlayedCards();
$this->discardPlayedCards();
self::giveExtraTime($nextPlayerId);
if ($nextPlayerCanPlay) {
$this->gamestate->nextState('firstPlayerTurn');
Expand Down Expand Up @@ -806,8 +811,8 @@ function stEndRound() {
// notify points earned by each player
foreach ($players as $player) {
$translatedMessage = ($numberOfPointsForRoundByPlayerId[$player->getId()] > 0)
? clienttranslate('${playerName} does not get any point')
: clienttranslate('${playerName} wins ${points} points');
? clienttranslate('${playerName} wins ${points} points')
: clienttranslate('${playerName} does not get any point');
self::notifyAllPlayers('pointsWon', $translatedMessage, [
'playerName' => $player->getName(),
'points' => $numberOfPointsForRoundByPlayerId[$player->getId()],
Expand Down Expand Up @@ -848,7 +853,7 @@ function stEndRound() {
$this->notifyAllPlayers( 'tableWindow', '', array(
'id' => 'finalScoring',
'title' => sprintf(
clienttranslate('Result of round %s/%s'),
clienttranslate('Results of round %s/%s'),
$currentRound,
$howManyRounds
),
Expand Down Expand Up @@ -999,8 +1004,7 @@ private function getCardsValue(array $cards, bool $withJersey): int {
return 0;
}

$addJerseyValueIfUsed = fn (int $value) => $value + ($withJersey ? JERSEY_VALUE : 0);

$addJerseyValueIfUsed = fn (int $value) => $value + ($withJersey ? VALUE_JERSEY : 0);

if (count($cards) === 1) {
return $addJerseyValueIfUsed($cards[0]->getValue());
Expand Down Expand Up @@ -1196,9 +1200,10 @@ private function getCurrentLoser(array $players): ?VelonimoPlayer {
return null;
}

private function discardLastPlayedCards(): void {
private function discardPlayedCards(): void {
$this->deck->moveAllCardsInLocation(self::CARD_LOCATION_PREVIOUS_PLAYED, self::CARD_LOCATION_DISCARD);
$this->deck->moveAllCardsInLocation(self::CARD_LOCATION_PLAYED, self::CARD_LOCATION_DISCARD);
self::setGameStateValue(self::GAME_STATE_PREVIOUS_PLAYED_CARDS_VALUE, 0);
self::setGameStateValue(self::GAME_STATE_LAST_PLAYED_CARDS_VALUE, 0);
self::setGameStateValue(self::GAME_STATE_LAST_PLAYED_CARDS_PLAYER_ID, 0);
self::notifyAllPlayers('cardsDiscarded', '', []);
Expand Down
Loading

0 comments on commit a9f5a64

Please sign in to comment.