Added dice & cards emoji/unicode to games.
This commit is contained in:
parent
abd34bde80
commit
ef6c600dbc
5 changed files with 38 additions and 31 deletions
|
@ -15,6 +15,7 @@
|
||||||
<ID>LongParameterList:Mobibot.kt$Mobibot$( nick: String, list: List<String>, maxPerLine: Int, isPrivate: Boolean, isBold: Boolean = false, isIndent: Boolean = false )</ID>
|
<ID>LongParameterList:Mobibot.kt$Mobibot$( nick: String, list: List<String>, 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>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: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: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: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>
|
<ID>NestedBlockDepth:CurrencyConverter.kt$CurrencyConverter$ override fun run(sender: String, cmd: String, args: String, isPrivate: Boolean)</ID>
|
||||||
|
|
|
@ -51,11 +51,17 @@ public final class War extends AbstractModule {
|
||||||
private static final SecureRandom RANDOM = new SecureRandom();
|
private static final SecureRandom RANDOM = new SecureRandom();
|
||||||
// War command
|
// War command
|
||||||
private static final String WAR_CMD = "war";
|
private static final String WAR_CMD = "war";
|
||||||
// Deck of card
|
|
||||||
private static final String[] WAR_DECK =
|
private static final String[] HEARTS =
|
||||||
{"Ace", "King", "Queen", "Jack", "10", "9", "8", "7", "6", "5", "4", "3", "2"};
|
{"🂱", "🂾", "🂽", "🂼", "🂻", "🂺", "🂹", "🂸", "🂷", "🂶", "🂵", "🂴", "🂳", "🂲"};
|
||||||
// Suits for the deck of card
|
private static final String[] SPADES =
|
||||||
private static final String[] WAR_SUITS = {"Hearts", "Spades", "Diamonds", "Clubs"};
|
{"🂡", "🂮", "🂭", "🂬", "🂫", "🂪", "🂩", "🂨", "🂧", "🂦", "🂥", "🂤", "🂣", "🂢"};
|
||||||
|
private static final String[] DIAMONDS =
|
||||||
|
{"🃁", "🃎", "🃍", "🃌", "🃋", "🃊", "🃉", "🃈", "🃇", "🃆", "🃅", "🃄", "🃃", "🃂"};
|
||||||
|
private static final String[] CLUBS =
|
||||||
|
{"🃑", "🃞", "🃝", "🃜", "🃛", "🃚", "🃙", "🃘", "🃗", "🃖", "🃕", "🃔", "🃓", "🃒"};
|
||||||
|
|
||||||
|
private static final String[][] DECK = {HEARTS, SPADES, DIAMONDS, CLUBS};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default constructor.
|
* The default constructor.
|
||||||
|
@ -81,13 +87,11 @@ public final class War extends AbstractModule {
|
||||||
int y;
|
int y;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
i = RANDOM.nextInt(WAR_DECK.length);
|
i = RANDOM.nextInt(HEARTS.length);
|
||||||
y = RANDOM.nextInt(WAR_DECK.length);
|
y = RANDOM.nextInt(HEARTS.length);
|
||||||
|
|
||||||
getBot().send(sender + " drew the " + bold(WAR_DECK[i]) + " of "
|
getBot().send(sender + " drew: " + DECK[RANDOM.nextInt(DECK.length)][i]);
|
||||||
+ bold(WAR_SUITS[RANDOM.nextInt(WAR_SUITS.length)]));
|
getBot().action("drew: " + DECK[RANDOM.nextInt(DECK.length)][y]);
|
||||||
getBot().action("drew the " + bold(WAR_DECK[y]) + " of "
|
|
||||||
+ bold(WAR_SUITS[RANDOM.nextInt(WAR_SUITS.length)]));
|
|
||||||
|
|
||||||
if (i != y) {
|
if (i != y) {
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -99,12 +99,12 @@ object Utils {
|
||||||
* Capitalize a string.
|
* Capitalize a string.
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun String.capitalise(): String = this.replaceFirstChar { it.uppercase() }
|
fun String.capitalise(): String = this.lowercase().replaceFirstChar { it.uppercase() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Capitalize words
|
* Capitalize words
|
||||||
*/
|
*/
|
||||||
fun String.capitalizeWords(): String = split(" ").map { it.lowercase().capitalise() }.joinToString(" ")
|
fun String.capitalizeWords(): String = split(" ").joinToString(" ") { it.capitalise() }
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
package net.thauvin.erik.mobibot.modules
|
package net.thauvin.erik.mobibot.modules
|
||||||
|
|
||||||
import net.thauvin.erik.mobibot.Mobibot
|
import net.thauvin.erik.mobibot.Mobibot
|
||||||
import net.thauvin.erik.mobibot.Utils.bold
|
|
||||||
import net.thauvin.erik.mobibot.Utils.helpFormat
|
import net.thauvin.erik.mobibot.Utils.helpFormat
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
|
@ -46,22 +45,20 @@ class Dice(bot: Mobibot) : AbstractModule(bot) {
|
||||||
args: String,
|
args: String,
|
||||||
isPrivate: Boolean
|
isPrivate: Boolean
|
||||||
) {
|
) {
|
||||||
|
val botRoll = roll()
|
||||||
val roll = roll()
|
val roll = roll()
|
||||||
val playerRoll = roll()
|
val botTotal = botRoll.first + botRoll.second
|
||||||
val total = roll.first + roll.second
|
val total = roll.first + roll.second
|
||||||
val playerTotal = playerRoll.first + playerRoll.second
|
|
||||||
with(bot) {
|
with(bot) {
|
||||||
send(
|
send(
|
||||||
channel,
|
channel,
|
||||||
"$sender rolled two dice: ${bold(playerRoll.first)} and ${bold(playerRoll.second)}"
|
"$sender rolled ${total}: ${DICE_FACES[roll.first]} ${DICE_FACES[roll.second]}",
|
||||||
+ " for a total of ${bold(playerTotal)}",
|
|
||||||
isPrivate
|
isPrivate
|
||||||
)
|
)
|
||||||
action(
|
action(
|
||||||
"rolled two dice: ${bold(roll.first)} and ${bold(roll.second)}" +
|
"rolled ${botTotal}: ${DICE_FACES[botRoll.first]} ${DICE_FACES[botRoll.second]}"
|
||||||
" for a total of ${bold(total)}"
|
|
||||||
)
|
)
|
||||||
when (winLoseOrTie(total, playerTotal)) {
|
when (winLoseOrTie(botTotal, total)) {
|
||||||
Result.WIN -> action("wins.")
|
Result.WIN -> action("wins.")
|
||||||
Result.LOSE -> action("lost.")
|
Result.LOSE -> action("lost.")
|
||||||
else -> action("tied.")
|
else -> action("tied.")
|
||||||
|
@ -74,14 +71,16 @@ class Dice(bot: Mobibot) : AbstractModule(bot) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun roll(): Pair<Int, Int> {
|
private fun roll(): Pair<Int, Int> {
|
||||||
@Suppress("MagicNumber")
|
return Random.nextInt(1, DICE_FACES.size) to Random.nextInt(1, DICE_FACES.size)
|
||||||
return Random.nextInt(1, 7) to Random.nextInt(1, 7)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
// Dice command
|
// Dice command
|
||||||
private const val DICE_CMD = "dice"
|
private const val DICE_CMD = "dice"
|
||||||
|
|
||||||
|
// Dice faces
|
||||||
|
private val DICE_FACES = arrayOf("", "⚀", "⚁", "⚂", "⚃", "⚄", "⚅")
|
||||||
|
|
||||||
fun winLoseOrTie(bot: Int, player: Int): Result {
|
fun winLoseOrTie(bot: Int, player: Int): Result {
|
||||||
return when {
|
return when {
|
||||||
bot > player -> {
|
bot > player -> {
|
||||||
|
|
|
@ -33,10 +33,8 @@
|
||||||
package net.thauvin.erik.mobibot.modules
|
package net.thauvin.erik.mobibot.modules
|
||||||
|
|
||||||
import net.thauvin.erik.mobibot.Mobibot
|
import net.thauvin.erik.mobibot.Mobibot
|
||||||
import net.thauvin.erik.mobibot.Utils.bold
|
import net.thauvin.erik.mobibot.Utils.capitalise
|
||||||
import net.thauvin.erik.mobibot.Utils.green
|
|
||||||
import net.thauvin.erik.mobibot.Utils.helpFormat
|
import net.thauvin.erik.mobibot.Utils.helpFormat
|
||||||
import net.thauvin.erik.mobibot.Utils.red
|
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,19 +65,26 @@ class RockPaperScissors(bot: Mobibot) : AbstractModule(bot) {
|
||||||
override fun beats(hand: Hands): Boolean {
|
override fun beats(hand: Hands): Boolean {
|
||||||
return hand == SCISSORS
|
return hand == SCISSORS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override var emoji = "\u270A"
|
||||||
},
|
},
|
||||||
PAPER("covers") {
|
PAPER("covers") {
|
||||||
override fun beats(hand: Hands): Boolean {
|
override fun beats(hand: Hands): Boolean {
|
||||||
return hand == ROCK
|
return hand == ROCK
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override var emoji = "\u270B"
|
||||||
},
|
},
|
||||||
SCISSORS("cuts") {
|
SCISSORS("cuts") {
|
||||||
override fun beats(hand: Hands): Boolean {
|
override fun beats(hand: Hands): Boolean {
|
||||||
return hand == PAPER
|
return hand == PAPER
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override var emoji = "\u270C"
|
||||||
};
|
};
|
||||||
|
|
||||||
abstract fun beats(hand: Hands): Boolean
|
abstract fun beats(hand: Hands): Boolean
|
||||||
|
abstract var emoji: String
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -100,18 +105,16 @@ class RockPaperScissors(bot: Mobibot) : AbstractModule(bot) {
|
||||||
val hand = Hands.valueOf(cmd.uppercase())
|
val hand = Hands.valueOf(cmd.uppercase())
|
||||||
val botHand = Hands.values()[Random.nextInt(0, Hands.values().size)]
|
val botHand = Hands.values()[Random.nextInt(0, Hands.values().size)]
|
||||||
with(bot) {
|
with(bot) {
|
||||||
|
send("${hand.emoji} vs. ${botHand.emoji}")
|
||||||
when {
|
when {
|
||||||
hand == botHand -> {
|
hand == botHand -> {
|
||||||
send("${green(hand.name)} vs. ${green(botHand.name)}")
|
|
||||||
action("tied.")
|
action("tied.")
|
||||||
}
|
}
|
||||||
hand.beats(botHand) -> {
|
hand.beats(botHand) -> {
|
||||||
send("${green(hand.name)} ${bold(hand.action)} ${red(botHand.name)}")
|
action("lost. ${hand.name.capitalise()} ${hand.action} ${botHand.name.lowercase()}.")
|
||||||
action("lost.")
|
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
send("${green(botHand.name)} ${bold(botHand.action)} ${red(hand.name)}")
|
action("wins. ${botHand.name.capitalise()} ${botHand.action} ${hand.name.lowercase()}.")
|
||||||
action("wins.")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue