Small fixes and improvements

A boss will drop all its items
A girl will choose a name from a list (not finalized)
Carrots will no longer spawn randomly
Lets a message overflow to the next line
Added a new method for dropping an item at any location (for Boss.java)
Improves backpacks
Improves symbols for existing items
Added an interact-message to all containers, and removed it from IStatic
Makes it possible to get any of the 1-10 items in a chest
Makes an item dropped on the same tile as a static container enter the container
Code improvements
Game end screen
This commit is contained in:
2018-03-19 19:11:09 +01:00
parent bec5f90efd
commit 27e4259f00
17 changed files with 406 additions and 179 deletions

View File

@ -4,6 +4,7 @@ import inf101.v18.rogue101.game.IGame;
import inf101.v18.rogue101.objects.IItem;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Backpack implements IContainer {
@ -14,7 +15,7 @@ public class Backpack implements IContainer {
/**
* The maximum amount of items allowed in a single backpack.
*/
private final int MAX_SIZE = 50;
private final int MAX_SIZE = 5;
@Override
public int getCurrentHealth() {
@ -54,14 +55,10 @@ public class Backpack implements IContainer {
/**
* Retrieves the current size of the Backpack.
*
* @return
* @return The size
*/
public int size() {
int totalSize = 0;
for (IItem item : content) {
totalSize += item.getSize();
}
return totalSize;
return content.size();
}
/**
@ -77,7 +74,7 @@ public class Backpack implements IContainer {
* Tries to add an item to the Backpack
*
* @param item The item to add
* @return
* @return True if the item was added. False if the backpack is full
*/
public boolean add(IItem item) {
if (size() < MAX_SIZE) {
@ -107,13 +104,23 @@ public class Backpack implements IContainer {
return content.get(i);
}
@Override
public boolean addItem(IItem item) {
if (content.size() < MAX_SIZE) {
content.add(item);
return true;
} else {
return false;
}
}
/**
* Gets the content List for direct manipulation.
*
* @return A list of T
*/
public List<IItem> getContent() {
return content;
return Collections.unmodifiableList(content);
}
@Override

View File

@ -40,9 +40,14 @@ public class Bow implements IRangedWeapon {
return 2;
}
@Override
public String getPrintSymbol() {
return "\uD83C\uDFF9";
}
@Override
public String getSymbol() {
return "B";
return "b";
}
@Override

View File

@ -4,32 +4,48 @@ import inf101.v18.rogue101.game.IGame;
import inf101.v18.rogue101.objects.IItem;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Chest implements IContainer, IStatic {
private List<IItem> container;
private int MAX_SIZE = 10;
public Chest() {
this.container = new ArrayList<>();
}
public Chest(int lvl) {
this.container = new ArrayList<>();
fill(lvl);
}
public Chest(List<IItem> items) {
this.container = items;
}
/**
* Randomly fills chest with random items based on dungeon level.
*
* @param lvl The current dungeon level
*/
private void fill (int lvl) {
//TODO: Implement
}
@Override
public IItem get(int i) {
return null;
}
@Override
public List getContent() {
return container;
public List<IItem> getContent() {
return Collections.unmodifiableList(container);
}
@Override
public boolean isFull() {
return false;
return container.size() >= MAX_SIZE;
}
@Override
@ -47,18 +63,13 @@ public class Chest implements IContainer, IStatic {
return "Chest";
}
@Override
public String getInteractMessage() {
return "Items in " + getName() + ": ";
}
@Override
public int getSize() {
return 10000;
}
public String getPrintSymbol() {
return "\uD83D\uDDC3";
return "\u001b[94m" + "\uD83D\uDDC3" + "\u001b[0m";
}
@Override
@ -70,4 +81,14 @@ public class Chest implements IContainer, IStatic {
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;
}
}
}

View File

@ -14,6 +14,14 @@ public interface IContainer extends IItem {
*/
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
*/
boolean addItem(IItem item);
/**
* Gets a list with everything inside a container.
*
@ -27,4 +35,13 @@ public interface IContainer extends IItem {
* @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
*/
default String getInteractMessage() {
return "Items in " + getName() + ": ";
}
}

View File

@ -12,11 +12,4 @@ public interface IStatic extends IItem {
default int getSize() {
return 10000;
}
/**
* A message to display when an interaction with the player happens.
*
* @return A message
*/
String getInteractMessage();
}

View File

@ -40,6 +40,11 @@ public class Staff implements IMagicWeapon {
return 0;
}
@Override
public String getPrintSymbol() {
return "";
}
@Override
public String getSymbol() {
return "s";

View File

@ -40,6 +40,11 @@ public class Sword implements IMeleeWeapon {
return 2;
}
@Override
public String getPrintSymbol() {
return "";
}
@Override
public String getSymbol() {
return "S";