Simplified games output even more.

This commit is contained in:
Erik C. Thauvin 2022-03-27 13:37:16 -07:00
parent c26d5f53d2
commit 61248387d8
4 changed files with 27 additions and 25 deletions

View file

@ -1,5 +1,6 @@
<component name="ProjectCodeStyleConfiguration"> <component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173"> <code_scheme name="Project" version="173">
<option name="WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN" value="true" />
<JetCodeStyleSettings> <JetCodeStyleSettings>
<option name="PACKAGES_TO_USE_STAR_IMPORTS"> <option name="PACKAGES_TO_USE_STAR_IMPORTS">
<value /> <value />

View file

@ -82,24 +82,22 @@ public final class War extends AbstractModule {
int i; int i;
int y; int y;
while (true) { do {
i = RANDOM.nextInt(DECK.length); i = RANDOM.nextInt(DECK.length);
y = RANDOM.nextInt(DECK.length); y = RANDOM.nextInt(DECK.length);
event.respond("you drew " + bold(DECK[i]) + SUITS[RANDOM.nextInt(SUITS.length)]); final String result;
event.getBot().sendIRC().action(channel, "drew " + bold(DECK[y]) + SUITS[RANDOM.nextInt(SUITS.length)]); if (i < y) {
result = bold("lost") + '.';
if (i != y) { } else if (i > y) {
break; result = bold("wins") + '.';
} else {
result = bold("tied") + ". This means " + bold("WAR!");
} }
event.respond("This means " + bold("WAR") + '!'); 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)] +
" and " + result);
if (i < y) { } while (i == y);
event.getBot().sendIRC().action(channel, "lost.");
} else {
event.getBot().sendIRC().action(channel, "wins.");
}
} }
} }

View file

@ -41,7 +41,6 @@ import org.pircbotx.hooks.types.GenericMessageEvent
*/ */
class Dice : AbstractModule() { class Dice : AbstractModule() {
override val name = "Dice" override val name = "Dice"
private val sides = 6
override fun commandResponse(channel: String, cmd: String, args: String, event: GenericMessageEvent) { override fun commandResponse(channel: String, cmd: String, args: String, event: GenericMessageEvent) {
val botRoll = roll() val botRoll = roll()
@ -50,17 +49,21 @@ class Dice : AbstractModule() {
val total = roll.first + roll.second val total = roll.first + roll.second
with(event.bot()) { with(event.bot()) {
event.respond( event.respond(
"you rolled ${roll.first.bold()} and ${roll.second.bold()} for a total of ${total.bold()}" "you rolled 2 dice: ${roll.first.bold()} + ${roll.second.bold()} for a total of ${total.bold()}"
) )
val result = when (winLoseOrTie(botTotal, total)) {
Result.WIN -> "wins"
Result.LOSE -> "lost"
else -> "tied"
}
sendIRC().action( sendIRC().action(
channel, channel,
"rolled ${botRoll.first.bold()} and ${botRoll.second.bold()} for a total of ${botTotal.bold()}" "rolled 2 dice: ${botRoll.first.bold()} + ${botRoll.second.bold()} for a total of ${botTotal.bold()}" +
" and ${result.bold()}."
) )
when (winLoseOrTie(botTotal, total)) {
Result.WIN -> sendIRC().action(channel, "wins.")
Result.LOSE -> sendIRC().action(channel, "lost.")
else -> sendIRC().action(channel, "tied.")
}
} }
} }

View file

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