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
+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.hooks.ListenerAdapter;
import com.vdurmont.emoji.EmojiManager;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -68,6 +71,11 @@ public class Commands extends ListenerAdapter {
{
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);
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;
public class Game {
public Message gameMessage;
public User user;
boolean gameActive = false;
Message gameMessage;
User user;
String playerEmote = ":flushed:";
public boolean gameActive = false;
public int level = 1;
int width = 9;
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;
@@ -26,7 +31,7 @@ public class Game {
level = 1;
width = 9;
height = 6;
grid = new Grid(width, height, level);
grid = new Grid(width, height, level, playerEmote);
gameActive = true;
Commands.sendGameEmbed(channel, String.valueOf(level), grid.toString(), user);
@@ -80,7 +85,7 @@ public class Game {
height += 1;
}
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 color = 0;
Player player;
String playerEmote;
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);
if (boxCount > MAX_BOXES)
{
@@ -129,21 +131,21 @@ public class Grid
{
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)
{
grid[j][i] = new Tile(WALL, color);
grid[j][i] = new Tile(WALL, color, playerEmote);
}
for (int k = 0; k < boxCount; k++)
{
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)
{
grid[j][i] = new Tile(PLAYER);
grid[j][i] = new Tile(PLAYER, playerEmote);
}
for (int k = 0; k < boxCount; k++)
{
@@ -151,9 +153,9 @@ public class Grid
{
if (boxes[k].onDestination())
{
grid[j][i] = new Tile(WALL, color);
grid[j][i] = new Tile(WALL, color, playerEmote);
} 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;
int color = 0;
int status = 0;
public Tile(int status)
String playerEmote;
public Tile(int status, String playerEmote)
{
this.status = status;
this.playerEmote = playerEmote;
}
public Tile(int status, int color)
public Tile(int status, int color, String playerEmote)
{
this.status = status;
this.color = color;
this.playerEmote = playerEmote;
}
public void setStatus(int status)
{
@@ -60,6 +63,6 @@ public class Tile
{
return ":negative_squared_cross_mark:";
}
return ":flushed:";
return playerEmote;
}
}