Minor changes
Adds new method for containers for finding first item of a class Adds health potions Allows the user to use potions
This commit is contained in:
@ -11,7 +11,7 @@ public class Backpack implements IContainer {
|
||||
/**
|
||||
* A list containing everything in the backpack.
|
||||
*/
|
||||
private List<IItem> content = new ArrayList<>();
|
||||
private final List<IItem> content = new ArrayList<>();
|
||||
/**
|
||||
* The maximum amount of items allowed in a single backpack.
|
||||
*/
|
||||
@ -85,15 +85,20 @@ public class Backpack implements IContainer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an element at index i
|
||||
*
|
||||
* @param i The index of an element
|
||||
*/
|
||||
@Override
|
||||
public void remove(int i) {
|
||||
content.remove(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes item from the backpack.
|
||||
*
|
||||
* @param item The item to remove
|
||||
*/
|
||||
public void remove(IItem item) {
|
||||
content.remove(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a T at index i,
|
||||
*
|
||||
@ -127,4 +132,14 @@ public class Backpack implements IContainer {
|
||||
public boolean isFull() {
|
||||
return size() >= MAX_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItem getFirst(Class<?> clazz) {
|
||||
for (IItem item : content) {
|
||||
if (clazz.isInstance(item)) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class Chest implements IContainer, IStatic {
|
||||
private List<IItem> container;
|
||||
private int MAX_SIZE = 10;
|
||||
private final List<IItem> container;
|
||||
private final int MAX_SIZE = 10;
|
||||
|
||||
public Chest() {
|
||||
this.container = new ArrayList<>();
|
||||
@ -48,6 +48,16 @@ public class Chest implements IContainer, IStatic {
|
||||
return container.size() >= MAX_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItem getFirst(Class<?> clazz) {
|
||||
for (IItem item : container) {
|
||||
if (clazz.isInstance(item)) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentHealth() {
|
||||
return 0;
|
||||
@ -91,4 +101,9 @@ public class Chest implements IContainer, IStatic {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(int i) {
|
||||
container.remove(i);
|
||||
}
|
||||
}
|
||||
|
56
src/inf101/v18/rogue101/items/HealthPotion.java
Normal file
56
src/inf101/v18/rogue101/items/HealthPotion.java
Normal file
@ -0,0 +1,56 @@
|
||||
package inf101.v18.rogue101.items;
|
||||
|
||||
import inf101.v18.rogue101.game.IGame;
|
||||
import inf101.v18.rogue101.objects.IItem;
|
||||
|
||||
public class HealthPotion implements IConsumable {
|
||||
@Override
|
||||
public int hpIncrease() {
|
||||
return 100;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int attackIncrease() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int defenceIncrease() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentHealth() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefence() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHealth() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Healing potion";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSymbol() {
|
||||
return "H";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int handleDamage(IGame game, IItem source, int amount) {
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@ package inf101.v18.rogue101.items;
|
||||
import inf101.v18.rogue101.objects.IItem;
|
||||
|
||||
public interface IConsumable extends IItem {
|
||||
void hpIncrease();
|
||||
void attackIncrease();
|
||||
void defenceIncrease();
|
||||
int hpIncrease();
|
||||
int attackIncrease();
|
||||
int defenceIncrease();
|
||||
}
|
||||
|
@ -9,39 +9,54 @@ public interface IContainer extends IItem {
|
||||
* Retrieves an item from a container in index i
|
||||
*
|
||||
* @param i The index of an element
|
||||
* @return An IItem
|
||||
* @throws IndexOutOfBoundsException If the index is out of range.
|
||||
* @return An IItem
|
||||
* @throws IndexOutOfBoundsException If the index is out of range.
|
||||
*/
|
||||
IItem get(int i);
|
||||
|
||||
/**
|
||||
* Adds an item to a container.
|
||||
*
|
||||
* @praram item The item to add to the container
|
||||
* @return True if the container was not full
|
||||
* @praram item The item to add to the container
|
||||
*/
|
||||
boolean addItem(IItem item);
|
||||
|
||||
/**
|
||||
* Gets a list with everything inside a container.
|
||||
*
|
||||
* @return A list of Objects extending IItem
|
||||
* @return A list of Objects extending IItem
|
||||
*/
|
||||
List<IItem> getContent();
|
||||
|
||||
/**
|
||||
* Checks if we can add anything at all to the container.
|
||||
*
|
||||
* @return True if it has no space left
|
||||
* @return True if it has no space left
|
||||
*/
|
||||
boolean isFull();
|
||||
|
||||
/**
|
||||
* Returns the message to show the user upon interacting with the container.
|
||||
*
|
||||
* @return A message
|
||||
* @return A message
|
||||
*/
|
||||
default String getInteractMessage() {
|
||||
return "Items in " + getName() + ": ";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the first item from the container of a specified type.
|
||||
*
|
||||
* @param clazz The class type to accept
|
||||
* @return An IItem or null
|
||||
*/
|
||||
IItem getFirst(Class<?> clazz);
|
||||
|
||||
/**
|
||||
* Removes an element at index i from the container.
|
||||
*
|
||||
* @param i The index of an element
|
||||
*/
|
||||
void remove(int i);
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
package inf101.v18.rogue101.items;
|
||||
|
||||
import inf101.v18.rogue101.game.IGame;
|
||||
import inf101.v18.rogue101.objects.IItem;
|
||||
|
||||
public class Manga implements IItem {
|
||||
private int hp = getMaxHealth();
|
||||
|
||||
/*@Override
|
||||
public boolean draw(ITurtle painter, double w, double h) {
|
||||
painter.save();
|
||||
painter.jump(-10);
|
||||
painter.setInk(Color.BLACK);
|
||||
painter.draw(getSize());
|
||||
painter.turn(90);
|
||||
painter.draw(getSize()/2);
|
||||
painter.turn(90);
|
||||
painter.draw(getSize());
|
||||
painter.turn(90);
|
||||
painter.draw(getSize()/2);
|
||||
painter.restore();
|
||||
return true;
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public int getCurrentHealth() {
|
||||
return hp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefence() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHealth() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Manga";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrintSymbol() {
|
||||
return "🕮";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSymbol() {
|
||||
return "M";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int handleDamage(IGame game, IItem source, int amount) {
|
||||
hp -= amount;
|
||||
return amount;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user