refactor: move GameInstance.toString implementation to GameState

This commit is contained in:
punchready 2021-06-03 04:06:20 +02:00
parent 2fb5a29633
commit bc6846b5b1
2 changed files with 41 additions and 36 deletions

View File

@ -123,41 +123,6 @@ public class GameInstance {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
for(int y = 0; y < _state.mapSize.getY(); y++) {
for(int x = 0; x < _state.mapSize.getX(); x++) {
ArrayList<Entity> entities = _state.entities.findByPosition(new IntVector2(x, y));
if(entities.isEmpty()) {
sb.append(". ");
}else {
switch(entities.get(0).id.type) {
case NPC -> {
switch(entities.get(0).id.id) {
case 0 -> {
sb.append("G ");
}
case 1 -> {
sb.append("S ");
}
case 2 -> {
sb.append("T ");
}
}
}
case P1, P2 -> {
sb.append("X ");
}
case Rocks -> {
sb.append("O ");
}
case InfinityStones -> {
sb.append("# ");
}
}
}
}
sb.append("\n");
}
return sb.toString();
return _state.toString();
}
}

View File

@ -118,4 +118,44 @@ class GameState {
winConditions.cloneFrom(state.winConditions);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
for(int y = 0; y < mapSize.getY(); y++) {
for(int x = 0; x < mapSize.getX(); x++) {
ArrayList<Entity> entities = this.entities.findByPosition(new IntVector2(x, y));
if(entities.isEmpty()) {
sb.append(". ");
}else {
switch(entities.get(0).id.type) {
case NPC -> {
switch(entities.get(0).id.id) {
case 0 -> {
sb.append("G ");
}
case 1 -> {
sb.append("S ");
}
case 2 -> {
sb.append("T ");
}
}
}
case P1, P2 -> {
sb.append("X ");
}
case Rocks -> {
sb.append("O ");
}
case InfinityStones -> {
sb.append("# ");
}
}
}
}
sb.append("\n");
}
return sb.toString();
}
}