Untitled
unknown
java
3 years ago
2.0 kB
9
Indexable
package com.comp301.a02adventure;
public class CellImpl implements Cell {
private final Position position;
private String name;
private String description;
private Inventory chest;
private boolean visited;
public CellImpl(int x, int y, String name, String description) throws IllegalArgumentException {
position = new PositionImpl(x, y);
chest = null;
visited = false;
this.name = name;
if (this.name == null) {
throw new IllegalArgumentException("Name is null");
}
this.description = description;
if (this.description == null) {
throw new IllegalArgumentException("Description is null");
}
}
public CellImpl(int x, int y) {
this(x, y, "", "");
}
@Override
public String getName() {
return name;
}
@Override
public void setName(String name) throws IllegalArgumentException {
this.name = name;
if (this.name == null) {
throw new IllegalArgumentException("Name is null");
}
}
@Override
public String getDescription() {
return description;
}
@Override
public void setDescription(String description) throws IllegalArgumentException {
this.description = description;
if (this.description == null) {
throw new IllegalArgumentException("Description is null");
}
}
@Override
public Position getPosition() {
return position;
}
@Override
public Inventory getChest() {
return chest;
}
@Override
public void setChest(Inventory chest) throws IllegalArgumentException {
this.chest = chest;
if (chest == null) {
throw new IllegalArgumentException("Chest is null");
}
}
@Override
public boolean getIsVisited() {
return visited;
}
@Override
public boolean hasChest() {
if (this.getChest() == null) {
return false;
}
return true;
}
@Override
public void visit() {
visited = true;
}
}
Editor is loading...