+ Added super basic initial implementaiton of realm visualization and input

This commit is contained in:
Matthew Cech
2019-09-13 00:28:26 -07:00
parent e81e0972a3
commit b96d96c849
5 changed files with 146 additions and 35 deletions
+4
View File
@@ -30,5 +30,9 @@ public class CommandDew extends Command {
framework.addCommand("luatest", new CommandDewLuaTest(KittyRole.Dev, KittyRating.Safe));
framework.addCommand("realm", new CommandDewRealm(KittyRole.Dev, KittyRating.Safe));
framework.addCommand("w", new CommandDewInput("w", KittyRole.Dev, KittyRating.Safe));
framework.addCommand("a", new CommandDewInput("a", KittyRole.Dev, KittyRating.Safe));
framework.addCommand("s", new CommandDewInput("s", KittyRole.Dev, KittyRating.Safe));
framework.addCommand("d", new CommandDewInput("d", KittyRole.Dev, KittyRating.Safe));
}
}
+20 -5
View File
@@ -1,5 +1,6 @@
package commands.dew;
import commands.dew.adapter.KittyAdapterDewPlayer;
import core.SubCommand;
import core.SubCommandFormattable;
import dataStructures.KittyChannel;
@@ -11,15 +12,29 @@ import dataStructures.UserInput;
public class CommandDewInput extends SubCommand
{
public CommandDewInput(KittyRole roleLevel, KittyRating contentRating) {
String letter = "";
public CommandDewInput(String letter, KittyRole roleLevel, KittyRating contentRating)
{
super(roleLevel, contentRating);
// TODO Auto-generated constructor stub
this.letter = letter.toLowerCase();
}
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input) {
// TODO Auto-generated method stub
return null;
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
{
KittyAdapterDewPlayer player = CommandDewRealm.getOrCreate(user);
int x = player.getRealmX();
int y = player.getRealmY();
switch(letter)
{
case "w": player.setRealmPos(x, y - 1); break;
case "a": player.setRealmPos(x - 1, y); break;
case "s": player.setRealmPos(x, y + 1); break;
case "d": player.setRealmPos(x + 1, y); break;
}
return new SubCommandFormattable(CommandDewRealm.drawWorld(player));
}
}
+68 -10
View File
@@ -1,5 +1,9 @@
package commands.dew;
import java.util.ArrayList;
import java.util.List;
import commands.dew.adapter.KittyAdapterDewPlayer;
import commands.dew.core.data.DewMapTile;
import commands.dew.core.data.DewRealm;
import core.SubCommand;
@@ -13,11 +17,16 @@ import dataStructures.UserInput;
public class CommandDewRealm extends SubCommand
{
DewRealm realm;
// TODO: CHANGE THIS! THIS IS TEMP STATIC, DO NOT CONTINUE TO DO THIS
private static DewRealm realm;
public static List<KittyAdapterDewPlayer> players;
public CommandDewRealm(KittyRole roleLevel, KittyRating contentRating)
{
super(roleLevel, contentRating);
realm = new DewRealm();
players = new ArrayList<KittyAdapterDewPlayer>();
for(int y = 0; y < realm.map.length; ++y)
{
@@ -28,32 +37,81 @@ public class CommandDewRealm extends SubCommand
}
}
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
public static KittyAdapterDewPlayer getOrCreate(KittyUser user)
{
String out = "";
out += "**Realm ID:** `" + realm.id + "`\n";
for(KittyAdapterDewPlayer player : players)
{
if(player.getUniqueID() == user.uniqueID)
{
return player;
}
}
for(int x = 0; x < realm.map.length; ++x)
KittyAdapterDewPlayer player = new KittyAdapterDewPlayer(realm, user, 10, 10);
players.add(player);
return player;
}
public static String drawWorld(KittyAdapterDewPlayer player)
{
out += "`";
for(int y = 0; y < realm.map[x].length; ++y)
// Build empty world buffer
String[][] worldBuffer = new String[realm.map.length][realm.map[0].length];
// Build world
for(int y = 0; y < realm.map.length; ++y)
{
switch(DewMapTile.values()[realm.map[x][y]])
for(int x = 0; x < realm.map[y].length; ++x)
{
switch(DewMapTile.values()[realm.map[y][x]])
{
case Grass:
out += ",";
worldBuffer[y][x] = ",";
break;
default:
worldBuffer[y][x] = " ";
break;
}
}
}
// Build players
for(KittyAdapterDewPlayer p : players)
{
worldBuffer[p.getRealmY()][p.getRealmX()] = p.getVisual();
}
// Draw world
String out = "";
out += "**Realm ID - ** `" + realm.id + "`\n";
for(int y = 0; y < worldBuffer.length; ++y)
{
out += "`";
for(int x = 0; x < worldBuffer[y].length; ++x)
{
out += worldBuffer[y][x];
}
out += "`";
out += "\n";
}
out += "**Stats**\n";
out += "`Player Name` - `" + player.getName() + "`\n";
out += "`Player Icon` - `" + player.getVisual() + "`\n";
return out;
}
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
{
KittyAdapterDewPlayer player = getOrCreate(user);
String out = drawWorld(player);
return new SubCommandFormattable(out);
}
@@ -1,37 +1,71 @@
package commands.dew.adapter;
import commands.dew.core.api.IDewPlayer;
import commands.dew.core.data.DewRealm;
import dataStructures.KittyUser;
public class KittyAdapterDewPlayer implements IDewPlayer
{
private KittyUser user;
private String realmID;
private int x;
private int y;
public KittyAdapterDewPlayer(DewRealm realm, KittyUser user, int x, int y)
{
this.user = user;
this.realmID = realm.id;
this.x = x;
this.y = y;
}
public String getVisual()
{
return user.name.length() >= 1 ? user.name.substring(0, 1) : "@";
}
public boolean isUser(KittyUser user)
{
return user.uniqueID == user.uniqueID;
}
public void setRealmPos(int x, int y)
{
this.x = x;
this.y = y;
}
////////////////////////////
// Interface requirements //
////////////////////////////
@Override
public String getName() {
// TODO Auto-generated method stub
return null;
public String getName()
{
return user.name;
}
@Override
public String getUniqueID() {
// TODO Auto-generated method stub
return null;
public String getUniqueID()
{
return user.uniqueID;
}
@Override
public String getCurrentRealm() {
// TODO Auto-generated method stub
return "0";
public String getCurrentRealmID()
{
return realmID;
}
@Override
public int getRealmX() {
// TODO Auto-generated method stub
return 0;
public int getRealmX()
{
return x;
}
@Override
public int getRealmY() {
// TODO Auto-generated method stub
return 0;
public int getRealmY()
{
return y;
}
}
+1 -1
View File
@@ -3,7 +3,7 @@ package commands.dew.core.api;
public interface IDewPlayer extends IDewEntity
{
public String getName();
public String getCurrentRealm();
public String getCurrentRealmID();
public int getRealmX();
public int getRealmY();
}