mirror of
https://github.com/opelly27/Sokobot.git
synced 2026-05-20 11:07:39 +00:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 72cf1e742c | |||
| 75ff975e58 | |||
| e69a4672f0 | |||
| 396016eeba | |||
| 7c2a25bbcf | |||
| f57b271bbf | |||
| ecf173568e | |||
| d1077ca9ab | |||
| f39d3a7ac8 | |||
| 9de5a2ae36 | |||
| 79a09651ab | |||
| cf5e579e9d | |||
| 9347174aeb | |||
| 584cf828d5 | |||
| c9522a4362 | |||
| 3d76bc15d4 | |||
| 89bd9a8f30 |
@@ -0,0 +1,42 @@
|
|||||||
|
# Sokobot
|
||||||
|
|
||||||
|
Sokobot is a Discord bot written with [JDA](https://github.com/DV8FromTheWorld/JDA) that lets you play [Sokoban](https://en.wikipedia.org/wiki/Sokoban), the classic box-pushing puzzle game.
|
||||||
|
|
||||||
|
## Screenshots
|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
## Features
|
||||||
|
### Infinite levels
|
||||||
|
The maps in Sokobot are randomly generated, increasing in difficulty as you progress.
|
||||||
|
### Varied controls
|
||||||
|
Sokobot has multiple control options to improve the player's experience, including reactions and wasd commands!
|
||||||
|
### Simultaneous games
|
||||||
|
Thanks to the power of Java HashMaps™️, multiple users can use the bot at the same time without interfering with one another.
|
||||||
|
### Custom prefixes ``New!``
|
||||||
|
To prevent Sokobot from conflicting with other bots, admins can choose any single-character prefix to preface Sokobot's commands.
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
### User
|
||||||
|
- ``!play`` can be used to start a game if you are not currently in one.
|
||||||
|
- ``!stop`` can be used to stop your active game at any time.
|
||||||
|
- ``!info`` provides some useful details about the bot and rules of the game.
|
||||||
|
### Admin ``New!``
|
||||||
|
- ``!prefix [character]`` can be used to change the prefix the bot responds to in the current server.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
### Public host ``New!``
|
||||||
|
Will be available very soon on [top.gg](https://top.gg)!
|
||||||
|
### Self-hosting
|
||||||
|
Grab the [latest .jar](https://github.com/PolyMarsDev/Sokobot/releases) or [build it yourself](#compiling). Then, create a Discord Bot Application [here](https://discord.com/developers/applications/) and paste the bot token into ``token.txt``. Then, ensure the two files are in the same directory and run the .jar file.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Compiling
|
||||||
|
|
||||||
|
Install [Java 8 JDK](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html) and [Gradle](https://gradle.org/).
|
||||||
|
In the root folder of the project, execute ``gradlew shadowJar``.
|
||||||
|
The compiled .jar file will be located in ``build/libs``.
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Feel free to create a fork and use the code for any noncommercial purposes.
|
||||||
+2
-1
@@ -5,7 +5,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group 'com.polymars'
|
group 'com.polymars'
|
||||||
version '1.0'
|
version '1.1'
|
||||||
|
|
||||||
mainClassName = "Bot"
|
mainClassName = "Bot"
|
||||||
sourceCompatibility = 1.8;
|
sourceCompatibility = 1.8;
|
||||||
@@ -17,4 +17,5 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'net.dv8tion:JDA:4.1.1_162'
|
compile 'net.dv8tion:JDA:4.1.1_162'
|
||||||
|
compile 'com.vdurmont:emoji-java:5.1.1'
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-2
@@ -2,22 +2,38 @@ import net.dv8tion.jda.api.AccountType;
|
|||||||
import net.dv8tion.jda.api.JDABuilder;
|
import net.dv8tion.jda.api.JDABuilder;
|
||||||
import net.dv8tion.jda.api.OnlineStatus;
|
import net.dv8tion.jda.api.OnlineStatus;
|
||||||
import net.dv8tion.jda.api.entities.Activity;
|
import net.dv8tion.jda.api.entities.Activity;
|
||||||
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
|
|
||||||
import javax.security.auth.login.LoginException;
|
import javax.security.auth.login.LoginException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class Bot {
|
public class Bot {
|
||||||
static String prefix = "!";
|
static HashMap<Guild, String> prefixes = new HashMap<Guild, String>();
|
||||||
|
|
||||||
public static void main(String[] args) throws LoginException, IOException {
|
public static void main(String[] args) throws LoginException, IOException {
|
||||||
JDABuilder builder = new JDABuilder(AccountType.BOT);
|
JDABuilder builder = new JDABuilder(AccountType.BOT);
|
||||||
String token = new String(Files.readAllBytes(Paths.get("token.txt")));
|
String token = new String(Files.readAllBytes(Paths.get("token.txt")));
|
||||||
builder.setToken(token);
|
builder.setToken(token);
|
||||||
builder.setStatus(OnlineStatus.ONLINE);
|
builder.setStatus(OnlineStatus.ONLINE);
|
||||||
builder.setActivity(Activity.playing("!play to play Sokoban!"));
|
builder.setActivity(Activity.playing("@Sokobot for info!"));
|
||||||
builder.addEventListeners(new Commands());
|
builder.addEventListeners(new Commands());
|
||||||
builder.build();
|
builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void setPrefix(Guild guild, String prefix)
|
||||||
|
{
|
||||||
|
prefixes.put(guild, prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
static String getPrefix(Guild guild)
|
||||||
|
{
|
||||||
|
if (!prefixes.containsKey(guild))
|
||||||
|
{
|
||||||
|
return "!";
|
||||||
|
}
|
||||||
|
return prefixes.get(guild);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+85
-19
@@ -1,17 +1,32 @@
|
|||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.Permission;
|
||||||
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||||
import net.dv8tion.jda.api.entities.User;
|
import net.dv8tion.jda.api.entities.User;
|
||||||
|
import net.dv8tion.jda.api.events.guild.GuildLeaveEvent;
|
||||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
import net.dv8tion.jda.api.events.message.guild.react.GuildMessageReactionAddEvent;
|
import net.dv8tion.jda.api.events.message.guild.react.GuildMessageReactionAddEvent;
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
|
|
||||||
|
import com.vdurmont.emoji.EmojiManager;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class Commands extends ListenerAdapter {
|
public class Commands extends ListenerAdapter {
|
||||||
HashMap<User, Game> games = new HashMap<User, Game>();
|
HashMap<User, Game> games = new HashMap<User, Game>();
|
||||||
ArrayList<String> commands = new ArrayList<String>(Arrays.asList("w", "a", "s", "d", "up", "left", "down", "right", "r", Bot.prefix + "play", Bot.prefix + "continue", Bot.prefix + "stop"));
|
ArrayList<String> commandsPrefix = new ArrayList<String>(Arrays.asList("play", "continue", "stop"));
|
||||||
|
ArrayList<String> commandsNoPrefix = new ArrayList<String>(Arrays.asList("w", "a", "s", "d", "up", "left", "down", "right", "r"));
|
||||||
|
public void onGuildLeave(GuildLeaveEvent event) //removes bot's stored prefix for a server if removed from that server
|
||||||
|
{
|
||||||
|
if (Bot.prefixes.containsKey(event.getGuild()))
|
||||||
|
{
|
||||||
|
Bot.prefixes.remove(event.getGuild());
|
||||||
|
}
|
||||||
|
}
|
||||||
public void onGuildMessageReceived(GuildMessageReceivedEvent event)
|
public void onGuildMessageReceived(GuildMessageReceivedEvent event)
|
||||||
{
|
{
|
||||||
if (event.getAuthor().isBot() && event.getMessage().getEmbeds().get(0).getTitle().charAt(0) == 'L')
|
if (event.getAuthor().isBot() && event.getMessage().getEmbeds().get(0).getTitle().charAt(0) == 'L')
|
||||||
@@ -21,26 +36,60 @@ public class Commands extends ListenerAdapter {
|
|||||||
event.getMessage().addReaction("U+2B06").queue();
|
event.getMessage().addReaction("U+2B06").queue();
|
||||||
event.getMessage().addReaction("U+2B07").queue();
|
event.getMessage().addReaction("U+2B07").queue();
|
||||||
event.getMessage().addReaction("U+1F504").queue();
|
event.getMessage().addReaction("U+1F504").queue();
|
||||||
|
if (games.containsKey(event.getJDA().getUserById(event.getMessage().getEmbeds().get(0).getFields().get(0).getValue().substring(10, event.getMessage().getEmbeds().get(0).getFields().get(0).getValue().length() - 1))))
|
||||||
|
{
|
||||||
|
games.get(event.getJDA().getUserById(event.getMessage().getEmbeds().get(0).getFields().get(0).getValue().substring(10, event.getMessage().getEmbeds().get(0).getFields().get(0).getValue().length() - 1))).setGameMessage(event.getMessage());
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String[] args = event.getMessage().getContentRaw().split("\\s+");
|
|
||||||
|
|
||||||
if (args[0].toLowerCase().equals(Bot.prefix + "info"))
|
String[] args = event.getMessage().getContentRaw().split("\\s+");
|
||||||
|
if (args[0].toLowerCase().equals(Bot.getPrefix(event.getGuild()) + "prefix"))
|
||||||
{
|
{
|
||||||
event.getChannel().sendMessage(info().build()).queue();
|
if (event.getMember().hasPermission(Permission.ADMINISTRATOR)) {
|
||||||
|
if (args.length == 2 && args[1].length() == 1) {
|
||||||
|
Bot.setPrefix(event.getGuild(), args[1].toLowerCase());
|
||||||
|
event.getChannel().sendMessage("Prefix successfully changed to ``" + Bot.getPrefix(event.getGuild()) + "``.").queue();
|
||||||
|
} else {
|
||||||
|
event.getChannel().sendMessage("``" + args[1] + "`` is not a valid prefix!").queue();
|
||||||
}
|
}
|
||||||
else if (commands.contains(args[0].toLowerCase()))
|
event.getMessage().delete().queue();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
event.getChannel().sendMessage(event.getAuthor().getAsMention() + ", you do not have permission to use this command.").queue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ((commandsNoPrefix.contains(args[0].toLowerCase())) || (Character.toString(args[0].toLowerCase().charAt(0)).equals(Bot.getPrefix(event.getGuild())) && commandsPrefix.contains(args[0].toLowerCase().substring(1))))
|
||||||
{
|
{
|
||||||
if (!games.containsKey(event.getAuthor()))
|
if (!games.containsKey(event.getAuthor()))
|
||||||
{
|
{
|
||||||
games.put(event.getAuthor(), new Game());
|
games.put(event.getAuthor(), new Game(event.getAuthor()));
|
||||||
}
|
}
|
||||||
String userInput = args[0].toLowerCase();
|
String userInput = args[0].toLowerCase();
|
||||||
if (Character.toString(userInput.charAt(0)).equals(Bot.prefix))
|
if (Character.toString(userInput.charAt(0)).equals(Bot.getPrefix(event.getGuild())))
|
||||||
{
|
{
|
||||||
userInput = userInput.substring(1, userInput.length());
|
userInput = userInput.substring(1, userInput.length());
|
||||||
}
|
}
|
||||||
games.get(event.getAuthor()).run(event.getChannel(), userInput);
|
if (!games.get(event.getAuthor()).gameActive && userInput.equals("play") && args.length == 2 && EmojiManager.isEmoji(args[1]))
|
||||||
|
{
|
||||||
|
System.out.println(args[1]);
|
||||||
|
games.get(event.getAuthor()).setPlayerEmote(args[1]);
|
||||||
|
}
|
||||||
|
games.get(event.getAuthor()).run(event.getGuild(), event.getChannel(), userInput);
|
||||||
|
if (userInput.equals("stop")) //remove game from hashmap when player quits
|
||||||
|
{
|
||||||
|
if (games.containsKey(event.getAuthor()))
|
||||||
|
{
|
||||||
|
games.remove(event.getAuthor());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.getMessage().delete().queue();
|
||||||
|
}
|
||||||
|
else if (args[0].toLowerCase().equals(Bot.getPrefix(event.getGuild()) + "info") || event.getMessage().getMentionedUsers().get(0).equals(event.getJDA().getSelfUser()))
|
||||||
|
{
|
||||||
|
event.getChannel().sendMessage(info(event.getGuild()).build()).queue();
|
||||||
|
event.getMessage().delete().queue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void onGuildMessageReactionAdd(GuildMessageReactionAddEvent event) {
|
public void onGuildMessageReactionAdd(GuildMessageReactionAddEvent event) {
|
||||||
@@ -50,8 +99,9 @@ public class Commands extends ListenerAdapter {
|
|||||||
}
|
}
|
||||||
if (!games.containsKey(event.getMember().getUser()))
|
if (!games.containsKey(event.getMember().getUser()))
|
||||||
{
|
{
|
||||||
games.put(event.getMember().getUser(), new Game());
|
games.put(event.getMember().getUser(), new Game(event.getMember().getUser()));
|
||||||
}
|
}
|
||||||
|
boolean reactionCommand = true;
|
||||||
String userInput = "";
|
String userInput = "";
|
||||||
switch (event.getReactionEmote().toString())
|
switch (event.getReactionEmote().toString())
|
||||||
{
|
{
|
||||||
@@ -70,10 +120,16 @@ public class Commands extends ListenerAdapter {
|
|||||||
case "RE:U+1f504":
|
case "RE:U+1f504":
|
||||||
userInput = "r";
|
userInput = "r";
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
reactionCommand = false;
|
||||||
}
|
}
|
||||||
games.get(event.getMember().getUser()).run(event.getChannel(), userInput);
|
if (reactionCommand)
|
||||||
|
{
|
||||||
|
games.get(event.getMember().getUser()).run(event.getGuild(), event.getChannel(), userInput);
|
||||||
}
|
}
|
||||||
EmbedBuilder info()
|
event.getReaction().removeReaction(event.getUser()).queue();
|
||||||
|
}
|
||||||
|
EmbedBuilder info(Guild guild)
|
||||||
{
|
{
|
||||||
EmbedBuilder info = new EmbedBuilder();
|
EmbedBuilder info = new EmbedBuilder();
|
||||||
info.setTitle("Sokobot");
|
info.setTitle("Sokobot");
|
||||||
@@ -81,25 +137,35 @@ public class Commands extends ListenerAdapter {
|
|||||||
info.setDescription("Sokobot is a bot that lets you play Sokoban, the classic box-pushing puzzle game.");
|
info.setDescription("Sokobot is a bot that lets you play Sokoban, the classic box-pushing puzzle game.");
|
||||||
info.setColor(0xdd2e53);
|
info.setColor(0xdd2e53);
|
||||||
info.addField("How to Play", "You are a **Sokoban** :flushed:.\nYour job is to push **boxes** :brown_square: on top of their **destinations** :negative_squared_cross_mark:.", false);
|
info.addField("How to Play", "You are a **Sokoban** :flushed:.\nYour job is to push **boxes** :brown_square: on top of their **destinations** :negative_squared_cross_mark:.", false);
|
||||||
info.addField("Features", ":white_small_square:**Infinite levels**\nThe fun never ends thanks to endless, randomly generated maps of increasing difficulty!\n:white_small_square:**Varied controls**\nSokobot has multiple control options to improve the player's experience, including reactions and wasd commands!\n:white_small_square:**Simultaneous games**\nThanks to the power of Java HashMaps:tm:, multiple users can use the bot at the same time without interfering with eachothers' games.", false);
|
info.addField("Features", ":white_small_square:**Infinite levels**\nThe maps in Sokobot are randomly generated, increasing in difficulty as you progress.\n:white_small_square:**Varied controls**\nSokobot has multiple control options to improve the player's experience, including reactions and wasd commands!\n:white_small_square:**Simultaneous games**\nThanks to the power of Java HashMaps:tm:, multiple users can use the bot at the same time without interfering with one another.\n:white_small_square:**Custom prefixes**\nTo prevent Sokobot from conflicting with other bots, admins can choose any single-character prefix to preface Sokobot's commands.", false);
|
||||||
info.addField("Commands", ("``" + Bot.prefix + "play`` can be used to start a game if you are not currently in one.\n``" + Bot.prefix + "stop`` can be used to stop your active game at any time.\n``" + Bot.prefix + "info`` provides some useful details about the bot."), false);
|
info.addField("Commands", ("``" + Bot.getPrefix(guild) + "play`` can be used to start a game if you are not currently in one.\n``" + Bot.getPrefix(guild) + "stop`` can be used to stop your active game at any time.\n``" + Bot.getPrefix(guild) + "info`` provides some useful details about the bot and rules of the game.\n``"+ Bot.getPrefix(guild) + "prefix [character]`` can be used to change the prefix the bot responds to."), false);
|
||||||
info.addField("Source code", "https://github.com/polymarsdev", false);
|
info.addField("Add to your server", "https://top.gg/to-be-added", false);
|
||||||
|
info.addField("Source code", "https://github.com/PolyMarsDev/Sokobot", false);
|
||||||
info.setFooter("created by PolyMars", "https://avatars0.githubusercontent.com/u/51007356?s=460&u=4eb8fd498421a2eee9781edfbadf654386cf06c7&v=4");
|
info.setFooter("created by PolyMars", "https://avatars0.githubusercontent.com/u/51007356?s=460&u=4eb8fd498421a2eee9781edfbadf654386cf06c7&v=4");
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
public static void sendGameEmbed(MessageChannel channel, String level, String game)
|
public static void sendGameEmbed(MessageChannel channel, String level, String game, User user)
|
||||||
{
|
{
|
||||||
EmbedBuilder embed = new EmbedBuilder();
|
EmbedBuilder embed = new EmbedBuilder();
|
||||||
embed.setTitle("Level " + level);
|
embed.setTitle("Level " + level);
|
||||||
embed.setDescription(game);
|
embed.setDescription(game);
|
||||||
embed.setFooter("Enter direction (up, down, left, right, or wasd) or r to reset");
|
embed.addField("Enter direction (``up``, ``down``, ``left``, ``right``/``wasd``) or ``r`` to reset", "Player: " + user.getAsMention(), false);
|
||||||
channel.sendMessage(embed.build()).queue();
|
channel.sendMessage(embed.build()).queue();
|
||||||
}
|
}
|
||||||
public static void sendWinEmbed(MessageChannel channel, String level)
|
public static void updateGameEmbed(Message message, String level, String game, User user)
|
||||||
|
{
|
||||||
|
EmbedBuilder embed = new EmbedBuilder();
|
||||||
|
embed.setTitle("Level " + level);
|
||||||
|
embed.setDescription(game);
|
||||||
|
embed.addField("Enter direction (``up``, ``down``, ``left``, ``right``/``wasd``) or ``r`` to reset", "Player: " + user.getAsMention(), false);
|
||||||
|
message.editMessage(embed.build()).queue();
|
||||||
|
}
|
||||||
|
public static void sendWinEmbed(Guild guild, Message message, String level)
|
||||||
{
|
{
|
||||||
EmbedBuilder embed = new EmbedBuilder();
|
EmbedBuilder embed = new EmbedBuilder();
|
||||||
embed.setTitle("You win!");
|
embed.setTitle("You win!");
|
||||||
embed.setDescription("Type ``" + Bot.prefix + "continue`` to continue to Level " + level + " or ``" + Bot.prefix + "stop`` to quit ");
|
embed.setDescription("Type ``" + Bot.getPrefix(guild) + "continue`` to continue to Level " + level + " or ``" + Bot.getPrefix(guild) + "stop`` to quit ");
|
||||||
channel.sendMessage(embed.build()).queue();
|
embed.setFooter("You can also press any reaction to continue.");
|
||||||
|
message.editMessage(embed.build()).queue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-9
@@ -1,11 +1,29 @@
|
|||||||
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||||
|
import net.dv8tion.jda.api.entities.User;
|
||||||
|
|
||||||
public class Game {
|
public class Game {
|
||||||
boolean gameActive = false;
|
Message gameMessage;
|
||||||
|
User user;
|
||||||
|
String playerEmote = ":flushed:";
|
||||||
|
public boolean gameActive = false;
|
||||||
public int level = 1;
|
public int level = 1;
|
||||||
int width = 9;
|
int width = 9;
|
||||||
int height = 6;
|
int height = 6;
|
||||||
Grid grid = new Grid(width, height, level);
|
Grid grid = new Grid(width, height, level, playerEmote);
|
||||||
|
public Game(User user)
|
||||||
|
{
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
public void setPlayerEmote(String emote)
|
||||||
|
{
|
||||||
|
playerEmote = emote;
|
||||||
|
}
|
||||||
|
public void setGameMessage(Message message)
|
||||||
|
{
|
||||||
|
gameMessage = message;
|
||||||
|
}
|
||||||
public void newGame(MessageChannel channel)
|
public void newGame(MessageChannel channel)
|
||||||
{
|
{
|
||||||
if (!gameActive)
|
if (!gameActive)
|
||||||
@@ -13,17 +31,18 @@ public class Game {
|
|||||||
level = 1;
|
level = 1;
|
||||||
width = 9;
|
width = 9;
|
||||||
height = 6;
|
height = 6;
|
||||||
grid = new Grid(width, height, level);
|
grid = new Grid(width, height, level, playerEmote);
|
||||||
|
|
||||||
gameActive = true;
|
gameActive = true;
|
||||||
Commands.sendGameEmbed(channel, String.valueOf(level), grid.toString());
|
Commands.sendGameEmbed(channel, String.valueOf(level), grid.toString(), user);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void run(MessageChannel channel, String userInput)
|
public void run(Guild guild, MessageChannel channel, String userInput)
|
||||||
{
|
{
|
||||||
if (userInput.equals("stop") && gameActive)
|
if (userInput.equals("stop") && gameActive)
|
||||||
{
|
{
|
||||||
channel.sendMessage("Thanks for playing!").queue();
|
channel.sendMessage("Thanks for playing, " + user.getAsMention() + "!").queue();
|
||||||
gameActive = false;
|
gameActive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +72,7 @@ public class Game {
|
|||||||
grid.reset();
|
grid.reset();
|
||||||
}
|
}
|
||||||
if (!grid.hasWon()) { //need to check again
|
if (!grid.hasWon()) { //need to check again
|
||||||
Commands.sendGameEmbed(channel, String.valueOf(level), grid.toString());
|
Commands.updateGameEmbed(gameMessage, String.valueOf(level), grid.toString(), user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (grid.hasWon()) {
|
if (grid.hasWon()) {
|
||||||
@@ -65,8 +84,8 @@ public class Game {
|
|||||||
{
|
{
|
||||||
height += 1;
|
height += 1;
|
||||||
}
|
}
|
||||||
Commands.sendWinEmbed(channel, String.valueOf(level));
|
Commands.sendWinEmbed(guild, gameMessage, String.valueOf(level));
|
||||||
grid = new Grid(width, height, level);
|
grid = new Grid(width, height, level, playerEmote);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-8
@@ -14,9 +14,11 @@ public class Grid
|
|||||||
int width = 0;
|
int width = 0;
|
||||||
int color = 0;
|
int color = 0;
|
||||||
Player player;
|
Player player;
|
||||||
|
String playerEmote;
|
||||||
Randomizer rand = new Randomizer();
|
Randomizer rand = new Randomizer();
|
||||||
public Grid(int width, int height, int boxCount) //create a random grid with specific width, height, and number of boxes
|
public Grid(int width, int height, int boxCount, String playerEmote) //create a random grid with specific width, height, and number of boxes
|
||||||
{
|
{
|
||||||
|
this.playerEmote = playerEmote;
|
||||||
player = new Player(2, 2, this);
|
player = new Player(2, 2, this);
|
||||||
if (boxCount > MAX_BOXES)
|
if (boxCount > MAX_BOXES)
|
||||||
{
|
{
|
||||||
@@ -97,7 +99,7 @@ public class Grid
|
|||||||
int y = rand.nextInt(height - 4) + 2;
|
int y = rand.nextInt(height - 4) + 2;
|
||||||
for (int j = 0; j < i; j++)
|
for (int j = 0; j < i; j++)
|
||||||
{
|
{
|
||||||
while ((x == boxes[j].getX() && y == boxes[j].getY()) || (x == 2 && y == 2))
|
while ((x == boxes[j].getX() && y == boxes[j].getY()) || (x == 2 && y == 2) || (x - 1 == boxes[j].getX() && y == boxes[j].getY()) || (x + 1 == boxes[j].getX() && y == boxes[j].getY()))
|
||||||
{
|
{
|
||||||
x = rand.nextInt(width - 4) + 2;
|
x = rand.nextInt(width - 4) + 2;
|
||||||
y = rand.nextInt(height - 4) + 2;
|
y = rand.nextInt(height - 4) + 2;
|
||||||
@@ -129,21 +131,21 @@ public class Grid
|
|||||||
{
|
{
|
||||||
for (int j = 0; j < width; j++)
|
for (int j = 0; j < width; j++)
|
||||||
{
|
{
|
||||||
grid[j][i] = new Tile(GROUND);
|
grid[j][i] = new Tile(GROUND, playerEmote);
|
||||||
if (j == 0 || j == width - 1 || i == 0 || i == height - 1)
|
if (j == 0 || j == width - 1 || i == 0 || i == height - 1)
|
||||||
{
|
{
|
||||||
grid[j][i] = new Tile(WALL, color);
|
grid[j][i] = new Tile(WALL, color, playerEmote);
|
||||||
}
|
}
|
||||||
for (int k = 0; k < boxCount; k++)
|
for (int k = 0; k < boxCount; k++)
|
||||||
{
|
{
|
||||||
if (destinations[k].getX() == j && destinations[k].getY() == i)
|
if (destinations[k].getX() == j && destinations[k].getY() == i)
|
||||||
{
|
{
|
||||||
grid[j][i] = new Tile(DESTINATION);
|
grid[j][i] = new Tile(DESTINATION, playerEmote);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (player.getX() == j && player.getY() == i)
|
if (player.getX() == j && player.getY() == i)
|
||||||
{
|
{
|
||||||
grid[j][i] = new Tile(PLAYER);
|
grid[j][i] = new Tile(PLAYER, playerEmote);
|
||||||
}
|
}
|
||||||
for (int k = 0; k < boxCount; k++)
|
for (int k = 0; k < boxCount; k++)
|
||||||
{
|
{
|
||||||
@@ -151,9 +153,9 @@ public class Grid
|
|||||||
{
|
{
|
||||||
if (boxes[k].onDestination())
|
if (boxes[k].onDestination())
|
||||||
{
|
{
|
||||||
grid[j][i] = new Tile(WALL, color);
|
grid[j][i] = new Tile(WALL, color, playerEmote);
|
||||||
} else {
|
} else {
|
||||||
grid[j][i] = new Tile(BOX);
|
grid[j][i] = new Tile(BOX, playerEmote);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,14 +7,17 @@ public class Tile
|
|||||||
final int PLAYER = 4;
|
final int PLAYER = 4;
|
||||||
int color = 0;
|
int color = 0;
|
||||||
int status = 0;
|
int status = 0;
|
||||||
public Tile(int status)
|
String playerEmote;
|
||||||
|
public Tile(int status, String playerEmote)
|
||||||
{
|
{
|
||||||
this.status = status;
|
this.status = status;
|
||||||
|
this.playerEmote = playerEmote;
|
||||||
}
|
}
|
||||||
public Tile(int status, int color)
|
public Tile(int status, int color, String playerEmote)
|
||||||
{
|
{
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
this.playerEmote = playerEmote;
|
||||||
}
|
}
|
||||||
public void setStatus(int status)
|
public void setStatus(int status)
|
||||||
{
|
{
|
||||||
@@ -60,6 +63,6 @@ public class Tile
|
|||||||
{
|
{
|
||||||
return ":negative_squared_cross_mark:";
|
return ":negative_squared_cross_mark:";
|
||||||
}
|
}
|
||||||
return ":flushed:";
|
return playerEmote;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user