Simplified games.

This commit is contained in:
Erik C. Thauvin 2022-03-27 12:35:55 -07:00
parent fa34f47dab
commit c26d5f53d2
7 changed files with 24 additions and 40 deletions

View file

@ -19,6 +19,7 @@
<ID>MagicNumber:CurrencyConverter.kt$CurrencyConverter.Companion$8</ID>
<ID>MagicNumber:Cycle.kt$Cycle$10</ID>
<ID>MagicNumber:Cycle.kt$Cycle$1000L</ID>
<ID>MagicNumber:Dice.kt$Dice$6</ID>
<ID>MagicNumber:Ignore.kt$Ignore$8</ID>
<ID>MagicNumber:Info.kt$Info.Companion$30</ID>
<ID>MagicNumber:Info.kt$Info.Companion$365</ID>
@ -72,5 +73,6 @@
<ID>TooGenericExceptionCaught:StockQuote.kt$StockQuote.Companion$e: NullPointerException</ID>
<ID>TooGenericExceptionCaught:Weather2.kt$Weather2.Companion$e: NullPointerException</ID>
<ID>TooManyFunctions:Tell.kt$Tell : AbstractCommand</ID>
<ID>UnusedPrivateMember:Dice.kt$Dice$private val sides = 6</ID>
</CurrentIssues>
</SmellBaseline>

View file

@ -52,16 +52,8 @@ public final class War extends AbstractModule {
// War command
private static final String WAR_CMD = "war";
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};
private static final String[] DECK = {"A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3", "2"};
private static final String[] SUITS = {"", "", "", ""};
/**
* The default constructor.
@ -91,11 +83,11 @@ public final class War extends AbstractModule {
int y;
while (true) {
i = RANDOM.nextInt(HEARTS.length);
y = RANDOM.nextInt(HEARTS.length);
i = RANDOM.nextInt(DECK.length);
y = RANDOM.nextInt(DECK.length);
event.respond("you drew " + DECK[RANDOM.nextInt(DECK.length)][i]);
event.getBot().sendIRC().action(channel, "drew " + DECK[RANDOM.nextInt(DECK.length)][y]);
event.respond("you drew " + bold(DECK[i]) + SUITS[RANDOM.nextInt(SUITS.length)]);
event.getBot().sendIRC().action(channel, "drew " + bold(DECK[y]) + SUITS[RANDOM.nextInt(SUITS.length)]);
if (i != y) {
break;

View file

@ -40,10 +40,11 @@ import org.pircbotx.hooks.types.GenericMessageEvent
class Versions : AbstractCommand() {
private val allVersions = listOf(
"Version: ${ReleaseInfo.VERSION} (${ReleaseInfo.BUILDDATE.toIsoLocalDate()})",
"Platform: " + System.getProperty("os.name") + ' ' + System.getProperty("os.version")
+ " (" + System.getProperty("os.arch") + ')',
"Runtime: " + System.getProperty("java.runtime.name") + ' ' + System.getProperty("java.runtime.version")
"Version : ${ReleaseInfo.VERSION} (${ReleaseInfo.BUILDDATE.toIsoLocalDate()})",
"Platform : ${System.getProperty("os.name")} ${System.getProperty("os.version")}" +
" (${System.getProperty("os.arch")})",
"Runtime : ${System.getProperty("java.runtime.name")} ${System.getProperty("java.runtime.version")}" +
" (${System.getProperty("java.vendor")})"
)
override val name = "versions"
override val help = listOf("To view the versions data (bot, platform, java, etc.):", helpFormat("%c $name"))

View file

@ -41,6 +41,7 @@ import org.pircbotx.hooks.types.GenericMessageEvent
*/
class Dice : AbstractModule() {
override val name = "Dice"
private val sides = 6
override fun commandResponse(channel: String, cmd: String, args: String, event: GenericMessageEvent) {
val botRoll = roll()
@ -49,11 +50,11 @@ class Dice : AbstractModule() {
val total = roll.first + roll.second
with(event.bot()) {
event.respond(
"you rolled ${DICE_FACES[roll.first]} ${DICE_FACES[roll.second]} for a total of ${total.bold()}"
"you rolled ${roll.first.bold()} and ${roll.second.bold()} for a total of ${total.bold()}"
)
sendIRC().action(
channel,
"rolled ${DICE_FACES[botRoll.first]} ${DICE_FACES[botRoll.second]} for a total of ${botTotal.bold()}"
"rolled ${botRoll.first.bold()} and ${botRoll.second.bold()} for a total of ${botTotal.bold()}"
)
when (winLoseOrTie(botTotal, total)) {
Result.WIN -> sendIRC().action(channel, "wins.")
@ -68,16 +69,13 @@ class Dice : AbstractModule() {
}
private fun roll(): Pair<Int, Int> {
return (1..DICE_FACES.size).random() to (1..DICE_FACES.size).random()
return (1..6).random() to (1..6).random()
}
companion object {
// Dice command
private const val DICE_CMD = "dice"
// Dice faces
private val DICE_FACES = arrayOf("", "", "", "", "", "", "")
@JvmStatic
fun winLoseOrTie(bot: Int, player: Int): Result {
return when {

View file

@ -32,8 +32,8 @@
package net.thauvin.erik.mobibot.modules
import net.thauvin.erik.mobibot.Utils.bold
import net.thauvin.erik.mobibot.Utils.bot
import net.thauvin.erik.mobibot.Utils.capitalise
import net.thauvin.erik.mobibot.Utils.helpFormat
import org.pircbotx.hooks.types.GenericMessageEvent
@ -67,26 +67,19 @@ class RockPaperScissors : AbstractModule() {
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 {
@ -107,21 +100,20 @@ class RockPaperScissors : AbstractModule() {
val hand = Hands.valueOf(cmd.uppercase())
val botHand = Hands.values()[(0..Hands.values().size).random()]
with(event.bot()) {
sendIRC().message(channel, "${hand.emoji} vs. ${botHand.emoji}")
when {
hand == botHand -> {
sendIRC().action(channel, "tied.")
sendIRC().action(channel, "tied: ${hand.name} vs. ${botHand.name}")
}
hand.beats(botHand) -> {
sendIRC().action(
channel,
"lost. ${hand.name.capitalise()} ${hand.action} ${botHand.name.lowercase()}."
"lost: ${hand.name.bold()} ${hand.action} ${botHand.name}"
)
}
else -> {
sendIRC().action(
channel,
"wins. ${botHand.name.capitalise()} ${botHand.action} ${hand.name.lowercase()}."
"wins: ${botHand.name.bold()} ${botHand.action} ${hand.name}"
)
}
}

View file

@ -35,7 +35,6 @@ import assertk.all
import assertk.assertThat
import assertk.assertions.any
import assertk.assertions.contains
import assertk.assertions.isEqualTo
import assertk.assertions.isGreaterThan
import assertk.assertions.isInstanceOf
import assertk.assertions.matches

View file

@ -1,9 +1,9 @@
#Generated by the Semver Plugin for Gradle
#Wed Mar 23 11:53:53 PDT 2022
version.buildmeta=035
#Sun Mar 27 12:29:09 PDT 2022
version.buildmeta=090
version.major=0
version.minor=8
version.patch=0
version.prerelease=rc
version.project=mobibot
version.semver=0.8.0-rc+035
version.semver=0.8.0-rc+090