Custom player emojis

Allow player to use any emoji in place of the player by using !play [valid emoji] when starting a game
This commit is contained in:
PocketMars
2020-06-30 11:35:03 -05:00
parent ecf173568e
commit f57b271bbf
5 changed files with 35 additions and 16 deletions
+1
View File
@@ -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'
} }
+8
View File
@@ -9,6 +9,9 @@ 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;
@@ -68,6 +71,11 @@ public class Commands extends ListenerAdapter {
{ {
userInput = userInput.substring(1, userInput.length()); userInput = userInput.substring(1, userInput.length());
} }
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); games.get(event.getAuthor()).run(event.getGuild(), event.getChannel(), userInput);
if (userInput.equals("stop")) //remove game from hashmap when player quits if (userInput.equals("stop")) //remove game from hashmap when player quits
{ {
+11 -6
View File
@@ -4,17 +4,22 @@ import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.User;
public class Game { public class Game {
public Message gameMessage; Message gameMessage;
public User user; User user;
boolean gameActive = false; 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) public Game(User user)
{ {
this.user = user; this.user = user;
} }
public void setPlayerEmote(String emote)
{
playerEmote = emote;
}
public void setGameMessage(Message message) public void setGameMessage(Message message)
{ {
gameMessage = message; gameMessage = message;
@@ -26,7 +31,7 @@ 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(), user); Commands.sendGameEmbed(channel, String.valueOf(level), grid.toString(), user);
@@ -80,7 +85,7 @@ public class Game {
height += 1; height += 1;
} }
Commands.sendWinEmbed(guild, gameMessage, String.valueOf(level)); Commands.sendWinEmbed(guild, gameMessage, String.valueOf(level));
grid = new Grid(width, height, level); grid = new Grid(width, height, level, playerEmote);
} }
} }
} }
+9 -7
View File
@@ -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)
{ {
@@ -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);
} }
} }
+6 -3
View File
@@ -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;
} }
} }