Untitled

mail@pastecode.io avatar
unknown
java
a year ago
1.1 kB
6
Indexable
Never
package com.comp301.a02adventure;

public class PlayerImpl implements Player {

  private final String name;
  private Position position;
  private final Inventory inventory;

  public PlayerImpl(String name, int startX, int startY) throws IllegalArgumentException {
    position = new PositionImpl(startX, startY);
    inventory = new InventoryImpl();
    this.name = name;
    if (this.name == null) {
      throw new IllegalArgumentException("Name is null");
    }
  }

  @Override
  public Position getPosition() {
    return position;
  }

  @Override
  public Inventory getInventory() {
    return inventory;
  }

  @Override
  public String getName() {
    return name;
  }

  @Override
  public void move(Direction direction) {
    switch (direction) {
      case NORTH:
        this.position = position.getNeighbor(Direction.NORTH);
      case SOUTH:
        this.position = position.getNeighbor(Direction.SOUTH);
      case EAST:
        this.position = position.getNeighbor(Direction.EAST);
      case WEST:
        this.position = position.getNeighbor(Direction.WEST);
    }
  }
}