Skip to content

Commit

Permalink
Add support for displaying emojis
Browse files Browse the repository at this point in the history
  • Loading branch information
davidruda committed Dec 28, 2024
1 parent 60f21ac commit d6d5430
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 2 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,23 @@ seperated card aliases, e.g. `-d Tc 2c` for 10♣️ (Ten of Clubs) and 2♣️

```
./joker -h
Usage: joker [-hV] [-b=<card>]... [-d=<card>]... (<card> <card>)...
Usage: joker [-ehV] [-b=<card>]... [-d=<card>]... (<card> <card>)...
(<card> <card>)... Player cards (2 cards per player, 2 to 10 players).
-b, --board=<card> Board cards - flop, turn or river (3 to 5 cards).
-d, --dead=<card> Cards that are no longer in the deck (1 to 19 cards).
-e, --emoji Display emojis for suits instead of letters.
-h, --help Show this help message and exit.
-V, --version Print version information and exit.
```

Also, you can use the `-e` flag to display emojis for suits instead of letters.
```
./joker Jh 9s Ac 2d --emoji
Win Tie
J♥️9♠️: 43,82% 0,43%
A♣️2♦️: 55,75% 0,43%
```

## Examples

Player 1 has A♥️ (Ace of Hearts) and K️♥️ (King of Hearts),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ public static void main(String[] args) {
calculatorArgs.getCommandLine().printVersionHelp(System.out);
return;
}
// Set whether to print emojis for suits or not
Card.setPrintSuitEmojis(calculatorArgs.shouldPrintEmojis());

Calculator calculator = new Calculator(calculatorArgs);
calculator.calculate().printOdds();
} catch (CommandLine.PicocliException | IllegalArgumentException e) {
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/cz/matfyz/rudad/joker/calculator/CalculatorArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ class CalculatorArgs {
)
private final List<Card> deadCards = new ArrayList<>();

@Option(
names = {"-e", "--emoji"},
description = "Display emojis for suits instead of letters."
)
private boolean printEmojis;

private final CommandLine commandLine = new CommandLine(this);

/**
Expand Down Expand Up @@ -98,6 +104,15 @@ List<Card> getDeadCards() {
return deadCards;
}

/**
* Returns whether emojis should be printed instead of letters.
*
* @return true if emojis should be printed, false otherwise
*/
boolean shouldPrintEmojis() {
return printEmojis;
}

/**
* Returns the underlying CommandLine object for advanced usage.
*
Expand Down
22 changes: 21 additions & 1 deletion src/main/java/cz/matfyz/rudad/joker/card/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class Card implements AutoCloseable {
private final Suit suit;
private final int cardId;

private static boolean printSuitEmojis = false;

/**
* Constructs a Card instance with the given card ID.
*
Expand Down Expand Up @@ -130,14 +132,32 @@ public int getCardId() {
return cardId;
}

/**
* Returns if the suit emoji should be printed.
*
* @return {@code true} if the suit emoji should be printed, {@code false} otherwise
*/
public static boolean isPrintSuitEmojis() {
return printSuitEmojis;
}

/**
* Sets if the suit emoji should be printed.
*
* @param printSuitEmojis {@code true} if the suit emoji should be printed, {@code false} otherwise
*/
public static void setPrintSuitEmojis(boolean printSuitEmojis) {
Card.printSuitEmojis = printSuitEmojis;
}

/**
* Returns the string representation of the card.
*
* @return the string representation
*/
@Override
public String toString() {
return rank.toString() + suit;
return rank.toString() + (printSuitEmojis ? suit.emoji() : suit);
}

}
26 changes: 26 additions & 0 deletions src/main/java/cz/matfyz/rudad/joker/card/Suit.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ public enum Suit {
SuitAlias.SPADES, SPADES
);

private static final Map<Character, String> emojiMap = Map.of(
SuitAlias.CLUBS, SuitEmoji.CLUBS,
SuitAlias.DIAMONDS, SuitEmoji.DIAMONDS,
SuitAlias.HEARTS, SuitEmoji.HEARTS,
SuitAlias.SPADES, SuitEmoji.SPADES
);

private final char alias;

/**
Expand Down Expand Up @@ -75,6 +82,15 @@ public char getAlias() {
public String toString() {
return String.valueOf(alias);
}

/**
* Returns the emoji representation of the suit.
*
* @return the emoji representation
*/
public String emoji() {
return String.valueOf(emojiMap.get(alias));
}
}

/**
Expand All @@ -86,3 +102,13 @@ class SuitAlias {
static final char HEARTS = 'h';
static final char SPADES = 's';
}

/**
* Contains emojis for the suits.
*/
class SuitEmoji {
static final String CLUBS = "♣️";
static final String DIAMONDS = "♦️";
static final String HEARTS = "♥️";
static final String SPADES = "♠️";
}

0 comments on commit d6d5430

Please sign in to comment.