Skip to content

Commit f57b271

Browse files
committed
Custom player emojis
Allow player to use any emoji in place of the player by using !play [valid emoji] when starting a game
1 parent ecf1735 commit f57b271

File tree

5 files changed

+35
-16
lines changed

5 files changed

+35
-16
lines changed

build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ repositories {
1717

1818
dependencies {
1919
compile 'net.dv8tion:JDA:4.1.1_162'
20+
compile 'com.vdurmont:emoji-java:5.1.1'
2021
}

src/main/java/Commands.java

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import net.dv8tion.jda.api.events.message.guild.react.GuildMessageReactionAddEvent;
1010
import net.dv8tion.jda.api.hooks.ListenerAdapter;
1111

12+
import com.vdurmont.emoji.EmojiManager;
13+
14+
1215
import java.util.ArrayList;
1316
import java.util.Arrays;
1417
import java.util.HashMap;
@@ -68,6 +71,11 @@ else if ((commandsNoPrefix.contains(args[0].toLowerCase())) || (Character.toStri
6871
{
6972
userInput = userInput.substring(1, userInput.length());
7073
}
74+
if (!games.get(event.getAuthor()).gameActive && userInput.equals("play") && args.length == 2 && EmojiManager.isEmoji(args[1]))
75+
{
76+
System.out.println(args[1]);
77+
games.get(event.getAuthor()).setPlayerEmote(args[1]);
78+
}
7179
games.get(event.getAuthor()).run(event.getGuild(), event.getChannel(), userInput);
7280
if (userInput.equals("stop")) //remove game from hashmap when player quits
7381
{

src/main/java/Game.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@
44
import net.dv8tion.jda.api.entities.User;
55

66
public class Game {
7-
public Message gameMessage;
8-
public User user;
9-
boolean gameActive = false;
7+
Message gameMessage;
8+
User user;
9+
String playerEmote = ":flushed:";
10+
public boolean gameActive = false;
1011
public int level = 1;
1112
int width = 9;
1213
int height = 6;
13-
Grid grid = new Grid(width, height, level);
14+
Grid grid = new Grid(width, height, level, playerEmote);
1415
public Game(User user)
1516
{
1617
this.user = user;
1718
}
19+
public void setPlayerEmote(String emote)
20+
{
21+
playerEmote = emote;
22+
}
1823
public void setGameMessage(Message message)
1924
{
2025
gameMessage = message;
@@ -26,7 +31,7 @@ public void newGame(MessageChannel channel)
2631
level = 1;
2732
width = 9;
2833
height = 6;
29-
grid = new Grid(width, height, level);
34+
grid = new Grid(width, height, level, playerEmote);
3035

3136
gameActive = true;
3237
Commands.sendGameEmbed(channel, String.valueOf(level), grid.toString(), user);
@@ -80,7 +85,7 @@ else if (gameActive)
8085
height += 1;
8186
}
8287
Commands.sendWinEmbed(guild, gameMessage, String.valueOf(level));
83-
grid = new Grid(width, height, level);
88+
grid = new Grid(width, height, level, playerEmote);
8489
}
8590
}
8691
}

src/main/java/Grid.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ public class Grid
1414
int width = 0;
1515
int color = 0;
1616
Player player;
17+
String playerEmote;
1718
Randomizer rand = new Randomizer();
18-
public Grid(int width, int height, int boxCount) //create a random grid with specific width, height, and number of boxes
19+
public Grid(int width, int height, int boxCount, String playerEmote) //create a random grid with specific width, height, and number of boxes
1920
{
21+
this.playerEmote = playerEmote;
2022
player = new Player(2, 2, this);
2123
if (boxCount > MAX_BOXES)
2224
{
@@ -129,31 +131,31 @@ public void updateGrid()
129131
{
130132
for (int j = 0; j < width; j++)
131133
{
132-
grid[j][i] = new Tile(GROUND);
134+
grid[j][i] = new Tile(GROUND, playerEmote);
133135
if (j == 0 || j == width - 1 || i == 0 || i == height - 1)
134136
{
135-
grid[j][i] = new Tile(WALL, color);
137+
grid[j][i] = new Tile(WALL, color, playerEmote);
136138
}
137139
for (int k = 0; k < boxCount; k++)
138140
{
139141
if (destinations[k].getX() == j && destinations[k].getY() == i)
140142
{
141-
grid[j][i] = new Tile(DESTINATION);
143+
grid[j][i] = new Tile(DESTINATION, playerEmote);
142144
}
143145
}
144146
if (player.getX() == j && player.getY() == i)
145147
{
146-
grid[j][i] = new Tile(PLAYER);
148+
grid[j][i] = new Tile(PLAYER, playerEmote);
147149
}
148150
for (int k = 0; k < boxCount; k++)
149151
{
150152
if (boxes[k].getX() == j && boxes[k].getY() == i)
151153
{
152154
if (boxes[k].onDestination())
153155
{
154-
grid[j][i] = new Tile(WALL, color);
156+
grid[j][i] = new Tile(WALL, color, playerEmote);
155157
} else {
156-
grid[j][i] = new Tile(BOX);
158+
grid[j][i] = new Tile(BOX, playerEmote);
157159
}
158160

159161
}

src/main/java/Tile.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ public class Tile
77
final int PLAYER = 4;
88
int color = 0;
99
int status = 0;
10-
public Tile(int status)
10+
String playerEmote;
11+
public Tile(int status, String playerEmote)
1112
{
1213
this.status = status;
14+
this.playerEmote = playerEmote;
1315
}
14-
public Tile(int status, int color)
16+
public Tile(int status, int color, String playerEmote)
1517
{
1618
this.status = status;
1719
this.color = color;
20+
this.playerEmote = playerEmote;
1821
}
1922
public void setStatus(int status)
2023
{
@@ -60,6 +63,6 @@ public String toString()
6063
{
6164
return ":negative_squared_cross_mark:";
6265
}
63-
return ":flushed:";
66+
return playerEmote;
6467
}
6568
}

0 commit comments

Comments
 (0)