From b96d96c849493c12d814a06d8bd29d6bfe44ac3a Mon Sep 17 00:00:00 2001 From: Matthew Cech Date: Fri, 13 Sep 2019 00:28:18 -0700 Subject: [PATCH] + Added super basic initial implementaiton of realm visualization and input --- src/commands/dew/CommandDew.java | 4 + src/commands/dew/CommandDewInput.java | 27 ++++-- src/commands/dew/CommandDewRealm.java | 82 ++++++++++++++++--- .../dew/adapter/KittyAdapterDewPlayer.java | 66 +++++++++++---- src/commands/dew/core/api/IDewPlayer.java | 2 +- 5 files changed, 146 insertions(+), 35 deletions(-) diff --git a/src/commands/dew/CommandDew.java b/src/commands/dew/CommandDew.java index 28bb585..9354dff 100644 --- a/src/commands/dew/CommandDew.java +++ b/src/commands/dew/CommandDew.java @@ -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)); } } diff --git a/src/commands/dew/CommandDewInput.java b/src/commands/dew/CommandDewInput.java index 6f63df8..52e3f8a 100644 --- a/src/commands/dew/CommandDewInput.java +++ b/src/commands/dew/CommandDewInput.java @@ -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)); } - } diff --git a/src/commands/dew/CommandDewRealm.java b/src/commands/dew/CommandDewRealm.java index d28e78f..fd7ae0e 100644 --- a/src/commands/dew/CommandDewRealm.java +++ b/src/commands/dew/CommandDewRealm.java @@ -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 players; + public CommandDewRealm(KittyRole roleLevel, KittyRating contentRating) { super(roleLevel, contentRating); + realm = new DewRealm(); + players = new ArrayList(); 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(int x = 0; x < realm.map.length; ++x) + for(KittyAdapterDewPlayer player : players) { - out += "`"; - for(int y = 0; y < realm.map[x].length; ++y) + if(player.getUniqueID() == user.uniqueID) { - switch(DewMapTile.values()[realm.map[x][y]]) + return player; + } + } + + KittyAdapterDewPlayer player = new KittyAdapterDewPlayer(realm, user, 10, 10); + players.add(player); + return player; + } + + public static String drawWorld(KittyAdapterDewPlayer player) + { + // 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) + { + 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); } diff --git a/src/commands/dew/adapter/KittyAdapterDewPlayer.java b/src/commands/dew/adapter/KittyAdapterDewPlayer.java index 72d60c6..4ae5b87 100644 --- a/src/commands/dew/adapter/KittyAdapterDewPlayer.java +++ b/src/commands/dew/adapter/KittyAdapterDewPlayer.java @@ -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; } - } diff --git a/src/commands/dew/core/api/IDewPlayer.java b/src/commands/dew/core/api/IDewPlayer.java index b1c2981..06de730 100644 --- a/src/commands/dew/core/api/IDewPlayer.java +++ b/src/commands/dew/core/api/IDewPlayer.java @@ -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(); }