The game now has several levels which can be travelled between Fake walls Stairs going uo Stairs going down Binoculars Shields can now be placed on the map Chests can now be randomly filled Inventory has been moved Shiny new health bar The player can use stairs
124 lines
2.8 KiB
Java
124 lines
2.8 KiB
Java
package inf101.v18.rogue101.items;
|
|
|
|
import inf101.v18.rogue101.game.IGame;
|
|
import inf101.v18.rogue101.objects.IItem;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.Random;
|
|
|
|
public class Chest implements IContainer, IStatic {
|
|
private final List<IItem> container;
|
|
private final int MAX_SIZE = 10;
|
|
|
|
public Chest() {
|
|
this.container = new ArrayList<>();
|
|
}
|
|
|
|
/**
|
|
* Randomly fills chest with random items based on dungeon level.
|
|
*
|
|
* @param lvl The current dungeon level
|
|
*/
|
|
public void fill (int lvl) {
|
|
Random random = new Random();
|
|
int itemChance = 5;
|
|
List<IItem> items = new ArrayList<>();
|
|
items.add(new Staff());
|
|
items.add(new Sword());
|
|
items.add(new Bow());
|
|
items.add(new Binoculars());
|
|
items.add(new Shield());
|
|
for (int i = 0; i < MAX_SIZE; i++) {
|
|
int num = random.nextInt(100);
|
|
boolean added = false;
|
|
for (int j = 0; j < items.size(); j++) {
|
|
if (num < (itemChance * (j + 1)) + ((j + 1) * lvl)) {
|
|
addItem(items.get(j));
|
|
items.remove(j); //We don't want duplicates
|
|
added = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!added && num > 70) {
|
|
addItem(new HealthPotion());
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public IItem get(int i) {
|
|
return container.get(i);
|
|
}
|
|
|
|
@Override
|
|
public List<IItem> getContent() {
|
|
return Collections.unmodifiableList(container);
|
|
}
|
|
|
|
@Override
|
|
public boolean isFull() {
|
|
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;
|
|
}
|
|
|
|
@Override
|
|
public int getMaxHealth() {
|
|
return 0;
|
|
}
|
|
|
|
@Override
|
|
public String getName() {
|
|
return "Chest";
|
|
}
|
|
|
|
@Override
|
|
public int getSize() {
|
|
return 10000;
|
|
}
|
|
|
|
public String getPrintSymbol() {
|
|
return "\u001b[94m" + "\uD83D\uDDC3" + "\u001b[0m";
|
|
}
|
|
|
|
@Override
|
|
public String getSymbol() {
|
|
return "C";
|
|
}
|
|
|
|
@Override
|
|
public int handleDamage(IGame game, IItem source, int amount) {
|
|
return 0;
|
|
}
|
|
|
|
@Override
|
|
public boolean addItem(IItem item) {
|
|
if (container.size() < MAX_SIZE) {
|
|
container.add(item);
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void remove(int i) {
|
|
container.remove(i);
|
|
}
|
|
}
|