java – Field class as a basis for a role play

My programs I've written so far only included a few lines of source code. When I was trying to write bigger programs, it usually failed because I did not master software engineering. This time, I want to play caution and now publish parts of the program from time to time, which should be my first big successful project.

I have the intention of writing a text role play.

In my role play, the environment should be represented as a two-dimensional field. All surrounding objects, such as houses, natural objects, and NPCs must be represented as points in the field. With special orders, you will also be able to see your inventory, your statistics, etc., but that will come later.

I have therefore written a field class and a base class for all the entities that can appear on the field. It was a little more complex than I expected. I would like to know if these two classes can be used as a starting point to represent the game's environment objects, or if my code is inappropriate and should be improved, or even a completely different concept should be put in artwork.

Thanks in advance!

Entity.java

Public class Entity {
name of public channel;
public character symbol;
Boolean public accessible on foot;
// decide if the entity can appear simultaneously on several positions
multiple Boolean public;

public entity (string name, character symbol, walking boolean) {
this.name = name;
this.symbol = symbol;
this.walkable = walkable;
this.multifarious = false;
}

public entity (string name, character symbol, walkable boolean, multifarious boolean) {
this (name, symbol, walk);
this.multifarious = multifarious;
}

public boolean isWalkable () {
back on foot;
}

public boolean isMultifarious () {
multiple return;
}

public String getName () {
return the name;
}

public char getSymbol () {
return symbol;
}

@Override
public channel toString () {
return name + "," + symbol + ", walkable:" + walkable;
}
}

Field.java

import java.util.List;
import java.util.ArrayList;

Public class Field {
private int height;
private int width;
private list <list <list>> positions;
private boolean multipleEntitiesOnPosition;
private character emptyPositionRepresentation;
private list placed entities;

public field (int height, int width, boolean multipleEntitiesOnPosition) {
this.height = height;
this.width = width;

positions = new ArrayList <List <List>> ();
for (int i = 0; i <height; i ++) {
positions.add (new ArrayList <List> ());
for (int j = 0; j <width; j ++) {
positions.get (i) .add (new ArrayList());
}
}

this.multipleEntitiesOnPosition = multipleEntitiesOnPosition;
emptyPositionRepresentation = & # 39 ;;
placeEntities = new ArrayList();
}

public field (int height, int width, boolean multipleEntitiesOnPosition, char emptyPositionRepresentation) {
this (height, width, multipleEntitiesOnPosition);
this.emptyPositionRepresentation = emptyPositionRepresentation;
}

public int getHeight () {
height of return;
}

public int getWidth () {
width of return;
}

public void addEntity (entity entity, int x, int y) {
// check if the coordinates are valid
if (x> = height) {
System.err.println ("error: x is greater than height");
return;
}
if (y> = width) {
System.err.println ("error: y is greater than the width");
return;
}
if (x <0 || y <0) {
System.err.println ("error: argument (s) of negative positions");
return;
}

// check if the entity is already active
if (installedEntities.contains (entity) &&! entity.isMultifarious ()) {
System.err.println ("error: the entity is already on the field");
return;
}

listing entityList = positions.get (x) .get (y);

// check if the entity is already at this post
if (entityList.contains (entity)) {
System.err.println ("error: the entity is already on this position");
return;
}

// check if the entity is already in position
if (! multipleEntitiesOnPosition &&! entityList.isEmpty ()) {
System.err.println ("error: multiple entities in the same position are prohibited");
return;
}

// check if the entity is placed on another non-practicable entity
for (Entity ent: entityList) {
if (! ent.isWalkable ()) {
System.err.println ("Error: The entity can not be placed on an entity that is not passable (" + entity + ")");
return;
}
}

placeEntities.add (entity);
entityList.add (entity);
}

public void removeEntity (entity entity) {
if (! placedEntities.contains (entity)) {
System.err.println ("This entity is not in the field.");
return;
}

for (int i = 0; i <height; i ++) {
for (int j = 0; j <width; j ++) {
listing entities = positions.get (i) .get (j);
if (entity.contains (entity)) {
entities. delete (entity);
if (! entity.isMultifarious ()) {
return;
}
}
}
}
}

public channel toString () {
StringBuilder returnValue = new StringBuilder ();
for (int i = 0; i <height; i ++) {
for (int j = 0; j <width; j ++) {
listing entities = positions.get (i) .get (j);
if (! entities.isEmpty ()) {
// only the last entity of a list is drawn on the field
char lastSymbol = entities.get (entities.size () - 1) .getSymbol ();
returnValue.append (lastSymbol);
} other {
returnValue.append (emptyPositionRepresentation);
}
}
returnValue.append (###);
}
return returnValue.toString ();
}
}

Main.java (Test class)

// This class tests the functionality of "Field" and "Entity"
public class Main {
public static void main (String[] args) {
// first try
Field field = new field (20, 40, true, & # 39;.);
Entity player = new entity ("Player 1", #, true);
field.addEntity (player, 10, 20);
System.out.println (field.toString ());
}
}