Added dice & cards emoji/unicode to games.

This commit is contained in:
Erik C. Thauvin 2021-08-01 00:52:20 -07:00
parent abd34bde80
commit ef6c600dbc
5 changed files with 38 additions and 31 deletions

View file

@ -15,6 +15,7 @@
<ID>LongParameterList:Mobibot.kt$Mobibot$( nick: String, list: List&lt;String&gt;, maxPerLine: Int, isPrivate: Boolean, isBold: Boolean = false, isIndent: Boolean = false )</ID>
<ID>LongParameterList:Twitter.kt$Twitter.Companion$( consumerKey: String?, consumerSecret: String?, token: String?, tokenSecret: String?, handle: String?, message: String, isDm: Boolean )</ID>
<ID>NestedBlockDepth:Addons.kt$Addons$ fun add(command: AbstractCommand, props: Properties)</ID>
<ID>NestedBlockDepth:Calc.kt$Calc$override fun commandResponse( sender: String, cmd: String, args: String, isPrivate: Boolean )</ID>
<ID>NestedBlockDepth:Comment.kt$Comment$override fun commandResponse( sender: String, login: String, args: String, isOp: Boolean, isPrivate: Boolean )</ID>
<ID>NestedBlockDepth:CryptoPrices.kt$CryptoPrices$ override fun run(sender: String, cmd: String, args: String, isPrivate: Boolean)</ID>
<ID>NestedBlockDepth:CurrencyConverter.kt$CurrencyConverter$ override fun run(sender: String, cmd: String, args: String, isPrivate: Boolean)</ID>

View file

@ -51,11 +51,17 @@ public final class War extends AbstractModule {
private static final SecureRandom RANDOM = new SecureRandom();
// War command
private static final String WAR_CMD = "war";
// Deck of card
private static final String[] WAR_DECK =
{"Ace", "King", "Queen", "Jack", "10", "9", "8", "7", "6", "5", "4", "3", "2"};
// Suits for the deck of card
private static final String[] WAR_SUITS = {"Hearts", "Spades", "Diamonds", "Clubs"};
private static final String[] HEARTS =
{"🂱", "🂾", "🂽", "🂼", "🂻", "🂺", "🂹", "🂸", "🂷", "🂶", "🂵", "🂴", "🂳", "🂲"};
private static final String[] SPADES =
{"🂡", "🂮", "🂭", "🂬", "🂫", "🂪", "🂩", "🂨", "🂧", "🂦", "🂥", "🂤", "🂣", "🂢"};
private static final String[] DIAMONDS =
{"🃁", "🃎", "🃍", "🃌", "🃋", "🃊", "🃉", "🃈", "🃇", "🃆", "🃅", "🃄", "🃃", "🃂"};
private static final String[] CLUBS =
{"🃑", "🃞", "🃝", "🃜", "🃛", "🃚", "🃙", "🃘", "🃗", "🃖", "🃕", "🃔", "🃓", "🃒"};
private static final String[][] DECK = {HEARTS, SPADES, DIAMONDS, CLUBS};
/**
* The default constructor.
@ -81,13 +87,11 @@ public final class War extends AbstractModule {
int y;
while (true) {
i = RANDOM.nextInt(WAR_DECK.length);
y = RANDOM.nextInt(WAR_DECK.length);
i = RANDOM.nextInt(HEARTS.length);
y = RANDOM.nextInt(HEARTS.length);
getBot().send(sender + " drew the " + bold(WAR_DECK[i]) + " of "
+ bold(WAR_SUITS[RANDOM.nextInt(WAR_SUITS.length)]));
getBot().action("drew the " + bold(WAR_DECK[y]) + " of "
+ bold(WAR_SUITS[RANDOM.nextInt(WAR_SUITS.length)]));
getBot().send(sender + " drew: " + DECK[RANDOM.nextInt(DECK.length)][i]);
getBot().action("drew: " + DECK[RANDOM.nextInt(DECK.length)][y]);
if (i != y) {
break;

View file

@ -99,12 +99,12 @@ object Utils {
* Capitalize a string.
*/
@JvmStatic
fun String.capitalise(): String = this.replaceFirstChar { it.uppercase() }
fun String.capitalise(): String = this.lowercase().replaceFirstChar { it.uppercase() }
/**
* Capitalize words
*/
fun String.capitalizeWords(): String = split(" ").map { it.lowercase().capitalise() }.joinToString(" ")
fun String.capitalizeWords(): String = split(" ").joinToString(" ") { it.capitalise() }
/**

View file

@ -32,7 +32,6 @@
package net.thauvin.erik.mobibot.modules
import net.thauvin.erik.mobibot.Mobibot
import net.thauvin.erik.mobibot.Utils.bold
import net.thauvin.erik.mobibot.Utils.helpFormat
import kotlin.random.Random
@ -46,22 +45,20 @@ class Dice(bot: Mobibot) : AbstractModule(bot) {
args: String,
isPrivate: Boolean
) {
val botRoll = roll()
val roll = roll()
val playerRoll = roll()
val botTotal = botRoll.first + botRoll.second
val total = roll.first + roll.second
val playerTotal = playerRoll.first + playerRoll.second
with(bot) {
send(
channel,
"$sender rolled two dice: ${bold(playerRoll.first)} and ${bold(playerRoll.second)}"
+ " for a total of ${bold(playerTotal)}",
"$sender rolled ${total}: ${DICE_FACES[roll.first]} ${DICE_FACES[roll.second]}",
isPrivate
)
action(
"rolled two dice: ${bold(roll.first)} and ${bold(roll.second)}" +
" for a total of ${bold(total)}"
"rolled ${botTotal}: ${DICE_FACES[botRoll.first]} ${DICE_FACES[botRoll.second]}"
)
when (winLoseOrTie(total, playerTotal)) {
when (winLoseOrTie(botTotal, total)) {
Result.WIN -> action("wins.")
Result.LOSE -> action("lost.")
else -> action("tied.")
@ -74,14 +71,16 @@ class Dice(bot: Mobibot) : AbstractModule(bot) {
}
private fun roll(): Pair<Int, Int> {
@Suppress("MagicNumber")
return Random.nextInt(1, 7) to Random.nextInt(1, 7)
return Random.nextInt(1, DICE_FACES.size) to Random.nextInt(1, DICE_FACES.size)
}
companion object {
// Dice command
private const val DICE_CMD = "dice"
// Dice faces
private val DICE_FACES = arrayOf("", "", "", "", "", "", "")
fun winLoseOrTie(bot: Int, player: Int): Result {
return when {
bot > player -> {

View file

@ -33,10 +33,8 @@
package net.thauvin.erik.mobibot.modules
import net.thauvin.erik.mobibot.Mobibot
import net.thauvin.erik.mobibot.Utils.bold
import net.thauvin.erik.mobibot.Utils.green
import net.thauvin.erik.mobibot.Utils.capitalise
import net.thauvin.erik.mobibot.Utils.helpFormat
import net.thauvin.erik.mobibot.Utils.red
import kotlin.random.Random
@ -67,19 +65,26 @@ class RockPaperScissors(bot: Mobibot) : AbstractModule(bot) {
override fun beats(hand: Hands): Boolean {
return hand == SCISSORS
}
override var emoji = "\u270A"
},
PAPER("covers") {
override fun beats(hand: Hands): Boolean {
return hand == ROCK
}
override var emoji = "\u270B"
},
SCISSORS("cuts") {
override fun beats(hand: Hands): Boolean {
return hand == PAPER
}
override var emoji = "\u270C"
};
abstract fun beats(hand: Hands): Boolean
abstract var emoji: String
}
companion object {
@ -100,18 +105,16 @@ class RockPaperScissors(bot: Mobibot) : AbstractModule(bot) {
val hand = Hands.valueOf(cmd.uppercase())
val botHand = Hands.values()[Random.nextInt(0, Hands.values().size)]
with(bot) {
send("${hand.emoji} vs. ${botHand.emoji}")
when {
hand == botHand -> {
send("${green(hand.name)} vs. ${green(botHand.name)}")
action("tied.")
}
hand.beats(botHand) -> {
send("${green(hand.name)} ${bold(hand.action)} ${red(botHand.name)}")
action("lost.")
action("lost. ${hand.name.capitalise()} ${hand.action} ${botHand.name.lowercase()}.")
}
else -> {
send("${green(botHand.name)} ${bold(botHand.action)} ${red(hand.name)}")
action("wins.")
action("wins. ${botHand.name.capitalise()} ${botHand.action} ${hand.name.lowercase()}.")
}
}
}