Improves getNeighbours greatly

This commit is contained in:
2018-03-14 14:00:48 +01:00
parent 6a21332877
commit d4c7d08df7
9 changed files with 153 additions and 138 deletions

View File

@ -6,15 +6,15 @@ import inf101.v18.rogue101.objects.IItem;
import java.util.ArrayList;
import java.util.List;
public class Backpack<T extends IItem> implements IContainer {
public class Backpack implements IContainer {
/**
* A list containing everything in the backpack.
*/
private List<T> content = new ArrayList<>();
private List<IItem> content = new ArrayList<>();
/**
* The maximum amount of items allowed in a single backpack.
*/
private final int MAX_SIZE = 5;
private final int MAX_SIZE = 50;
@Override
public int getCurrentHealth() {
@ -57,7 +57,11 @@ public class Backpack<T extends IItem> implements IContainer {
* @return
*/
public int size() {
return content.size();
int totalSize = 0;
for (IItem item : content) {
totalSize += item.getSize();
}
return totalSize;
}
/**
@ -75,8 +79,8 @@ public class Backpack<T extends IItem> implements IContainer {
* @param item The item to add
* @return
*/
public boolean add(T item) {
if (content.size() < MAX_SIZE) {
public boolean add(IItem item) {
if (size() < MAX_SIZE) {
content.add(item);
return true;
} else {
@ -99,7 +103,7 @@ public class Backpack<T extends IItem> implements IContainer {
* @param i The index of an element
* @return An object of type T
*/
public T get(int i) {
public IItem get(int i) {
return content.get(i);
}
@ -108,18 +112,12 @@ public class Backpack<T extends IItem> implements IContainer {
*
* @return A list of T
*/
public List<T> getContent() {
public List<IItem> getContent() {
return content;
}
@Override
public boolean isFull() {
return content.size() >= MAX_SIZE;
}
//This shows as an error, but is necessary to compile.
@Override
public int compareTo(Object o) {
return compareTo((IItem)o);
return size() >= MAX_SIZE;
}
}

View File

@ -3,9 +3,12 @@ package inf101.v18.rogue101.items;
import inf101.v18.rogue101.game.IGame;
import inf101.v18.rogue101.objects.IItem;
import java.util.ArrayList;
import java.util.List;
public class Chest implements IContainer {
private List<IItem> container = new ArrayList<>();
@Override
public IItem get(int i) {
return null;
@ -38,12 +41,12 @@ public class Chest implements IContainer {
@Override
public String getName() {
return null;
return "Chest";
}
@Override
public int getSize() {
return 100;
return 10000;
}
public String getPrintSymbol() {

View File

@ -1,14 +1,10 @@
package inf101.v18.rogue101.items;
import inf101.v18.rogue101.objects.IItem;
import java.util.List;
/**
* A container for storing anything extending IItem.
*
* @param <T> The item type to store
*/
public interface IContainer<T extends IItem> extends IItem {
public interface IContainer extends IItem {
/**
* Retrieves an item from a container in index i
*
@ -23,7 +19,7 @@ public interface IContainer<T extends IItem> extends IItem {
*
* @return A list of Objects extending IItem
*/
List<T> getContent();
List<IItem> getContent();
/**
* Checks if we can add anything at all to the container.