Fixes getNeighbourhood counting corners twice

This commit is contained in:
Kristian Knarvik 2018-03-15 00:16:26 +01:00
parent d4c7d08df7
commit bec5f90efd
11 changed files with 192 additions and 36 deletions

View File

@ -81,5 +81,7 @@ d)
### Tredjepartsfiler
* Bow Fire Arrow Sound (http://soundbible.com, Stephan Schutze, Noncommercial 3.0)
* Sword Swing Sound (http://soundbible.com, Mike Koenig, Attribution 3.0)
* Large Fireball Sound (http://soundbible.com av Mike Koenig, Attribution 3.0)
* Large Fireball Sound (http://soundbible.com, Mike Koenig, Attribution 3.0)
* Realistic Punch Sound (http://soundbible.com, Mark DiAngelo, Attribution 3.0)
* Snow Ball Throw And Splat Sound (http://soundbible.com, Mike Koenig, Attribution 3.0)

Binary file not shown.

View File

@ -0,0 +1,78 @@
package inf101.v18.rogue101.enemies;
import inf101.v18.rogue101.game.IGame;
import inf101.v18.rogue101.items.Backpack;
import inf101.v18.rogue101.objects.IItem;
import inf101.v18.rogue101.objects.INonPlayer;
public class Boss implements INonPlayer {
private int hp = getMaxHealth();
Backpack backpack = new Backpack();
@Override
public void doTurn(IGame game) {
}
@Override
public int getAttack() {
return 50;
}
@Override
public int getDamage() {
return 15;
}
@Override
public IItem getItem(Class<?> type) {
for (IItem item : backpack.getContent()) {
if (type.isInstance(item)) {
return item;
}
}
return null;
}
@Override
public int getCurrentHealth() {
return hp;
}
@Override
public int getDefence() {
return 50;
}
@Override
public int getMaxHealth() {
return 500;
}
@Override
public String getName() {
return "Lucifer";
}
@Override
public int getSize() {
return 50;
}
@Override
public String getPrintSymbol() {
return "\uD83D\uDE08";
}
@Override
public String getSymbol() {
return "B";
}
@Override
public int handleDamage(IGame game, IItem source, int amount) {
//TODO: Drop item on death.
hp -= amount;
return amount;
}
}

View File

@ -17,6 +17,7 @@ import inf101.v18.grid.GridDirection;
import inf101.v18.grid.IGrid;
import inf101.v18.grid.ILocation;
import inf101.v18.rogue101.Main;
import inf101.v18.rogue101.enemies.Boss;
import inf101.v18.rogue101.enemies.Girl;
import inf101.v18.rogue101.examples.Carrot;
import inf101.v18.rogue101.items.*;
@ -26,6 +27,7 @@ import inf101.v18.rogue101.map.IGameMap;
import inf101.v18.rogue101.map.IMapView;
import inf101.v18.rogue101.map.MapReader;
import inf101.v18.rogue101.objects.*;
import inf101.v18.rogue101.shared.NPC;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.input.KeyCode;
import javafx.scene.paint.Color;
@ -179,6 +181,12 @@ public class Game implements IGame {
if (!map.has(loc, target)) {
throw new IllegalMoveException("Target isn't there!");
}
IWeapon weapon = (IWeapon) currentActor.getItem(IWeapon.class);
if (weapon != null) {
NPC.playSound(weapon.getSound());
} else {
NPC.playSound("audio/Realistic_Punch-Mark_DiAngelo-1609462330.wav");
}
if (getAttack() >= getDefence(target)) {
int actualDamage = target.handleDamage(this, target, getDamage(target));
formatMessage("%s hits %s for %d damage", currentActor.getName(), target.getName(), actualDamage);
@ -199,6 +207,12 @@ public class Game implements IGame {
@Override
public ILocation rangedAttack(GridDirection dir, IItem target) {
ILocation loc = currentLocation;
IWeapon weapon = (IWeapon) currentActor.getItem(IWeapon.class);
if (weapon != null) {
NPC.playSound(weapon.getSound());
} else {
NPC.playSound("audio/Snow Ball Throw And Splat-SoundBible.com-992042947.wav");
}
if (getAttack() >= getDefence(target)) {
int damage = getDamage(target) / loc.gridDistanceTo(map.getLocation(target));
int actualDamage = target.handleDamage(this, target, damage);
@ -342,6 +356,7 @@ public class Game implements IGame {
itemFactories.put(".", Dust::new);
itemFactories.put("S", Sword::new);
itemFactories.put("c", Chest::new);
itemFactories.put("B", Boss::new);
}
@Override
@ -514,7 +529,7 @@ public class Game implements IGame {
@Override
public IItem pickUp(IItem item) {
if (item != null && map.has(currentLocation, item)) {
if (item != null && map.has(currentLocation, item) && !(item instanceof IStatic)) {
if (item instanceof IActor) {
if (item.getCurrentHealth() / item.getMaxHealth() < 3) {
map.remove(currentLocation, item);

View File

@ -6,8 +6,16 @@ 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<>();
public class Chest implements IContainer, IStatic {
private List<IItem> container;
public Chest() {
this.container = new ArrayList<>();
}
public Chest(List<IItem> items) {
this.container = items;
}
@Override
public IItem get(int i) {
@ -16,7 +24,7 @@ public class Chest implements IContainer {
@Override
public List getContent() {
return null;
return container;
}
@Override
@ -29,11 +37,6 @@ public class Chest implements IContainer {
return 0;
}
@Override
public int getDefence() {
return 0;
}
@Override
public int getMaxHealth() {
return 0;
@ -44,6 +47,11 @@ public class Chest implements IContainer {
return "Chest";
}
@Override
public String getInteractMessage() {
return "Items in " + getName() + ": ";
}
@Override
public int getSize() {
return 10000;

View File

@ -0,0 +1,22 @@
package inf101.v18.rogue101.items;
import inf101.v18.rogue101.objects.IItem;
public interface IStatic extends IItem {
@Override
default int getDefence() {
return 0;
}
@Override
default int getSize() {
return 10000;
}
/**
* A message to display when an interaction with the player happens.
*
* @return A message
*/
String getInteractMessage();
}

View File

@ -355,7 +355,7 @@ public class GameMap implements IGameMap {
int rightX = startX + i;
int topY = startY - i;
int bottomY = startY + i;
for (int x = leftX; x <= rightX; x++) {
for (int x = leftX + 1; x < rightX; x++) {
if (grid.isValid(x, topY)) {
neighbours.add(getLocation(x, topY));
}

View File

@ -15,7 +15,7 @@
# G #
# G #
# c #
# #
# #
# ####
# # B#
# G #
########################################

View File

@ -3,9 +3,7 @@ package inf101.v18.rogue101.objects;
import inf101.v18.grid.GridDirection;
import inf101.v18.grid.ILocation;
import inf101.v18.rogue101.game.IGame;
import inf101.v18.rogue101.items.Backpack;
import inf101.v18.rogue101.items.IMagicWeapon;
import inf101.v18.rogue101.items.IRangedWeapon;
import inf101.v18.rogue101.items.*;
import inf101.v18.rogue101.shared.NPC;
import javafx.scene.input.KeyCode;
import java.util.ArrayList;
@ -19,6 +17,7 @@ public class Player implements IPlayer {
// True if the player wants to drop something using the digit keys
private boolean picking = false;
private boolean writing = false;
private boolean exploringChest = false;
private String text = "";
private String name = "Player";
@ -57,6 +56,10 @@ public class Player implements IPlayer {
pickUp(game, keyValue - 1);
picking = false;
turnConsumed = true;
} else if (exploringChest) {
loot(game, keyValue - 1);
exploringChest = false;
turnConsumed = true;
}
}
} else if (key == KeyCode.N) {
@ -112,6 +115,9 @@ public class Player implements IPlayer {
List<IItem> items = game.getLocalItems();
if (items.size() < 1) {
game.displayMessage("There is nothing to pick up");
} else {
if (items.get(0) instanceof IStatic && items.get(0) instanceof IContainer) { //Static items are always the biggest (and hopefully the only) item on a tile.
openChest(game, items);
} else {
if (items.size() == 1) {
pickUp(game, 0);
@ -125,9 +131,22 @@ public class Player implements IPlayer {
picking = true;
}
}
}
return false;
}
private void openChest(IGame game, List<IItem> items) {
IStatic item = (IStatic)items.get(0);
StringBuilder msg = new StringBuilder(item.getInteractMessage());
IContainer container = (IContainer) item;
items = container.getContent();
for (int i = 0; i < Math.min(items.size(), 5); i++) {
msg.append(" [").append(i + 1).append("] ").append(firstCharToUpper(items.get(i).getName()));
}
game.displayMessage(msg.toString());
exploringChest = true;
}
/**
* Initialized the dropping of an item, and does what is needed.
*
@ -135,14 +154,14 @@ public class Player implements IPlayer {
* @return True if a turn was consumed. False otherwise
*/
private boolean dropInit(IGame game) {
if (equipped.size() == 1) {
if (equipped.getContent().size() == 1) {
drop(game, 0);
return true;
} else if (equipped.size() < 1) {
} else if (equipped.getContent().size() < 1) {
game.displayMessage("You have nothing to drop");
} else {
StringBuilder msg = new StringBuilder("Items to drop:");
for (int i = 0; i < equipped.size(); i++) {
for (int i = 0; i < equipped.getContent().size(); i++) {
msg.append(" [").append(i + 1).append("] ").append(firstCharToUpper(equipped.get(i).getName()));
}
game.displayMessage(msg.toString());
@ -176,6 +195,27 @@ public class Player implements IPlayer {
}
}
/**
* Takes an item from a chest, and gives it to the player.
*/
private void loot(IGame game, int i) {
if (!equipped.isFull()) {
List<IItem> items = game.getLocalItems();
IItem item = items.get(0);
if (item instanceof IStatic && item instanceof IContainer) {
IContainer container = (IContainer) item;
IItem loot = container.getContent().get(i);
equipped.add(loot);
container.getContent().remove(i);
game.displayMessage("Looted " + loot.getName());
} else {
game.displayMessage("It seems you are trying to loot a chest, without a chest nearby.");
}
} else {
game.displayMessage("Your inventory is full.");
}
}
/**
* Drops an item at index i.
*

View File

@ -32,7 +32,6 @@ public class NPC {
GridDirection dir = game.locationDirection(current, neighbour);
IActor actor = game.getMap().getActors(neighbour).get(0); //We assume there is only one actor.
if (current.gridDistanceTo(neighbour) <= 1 && current.canGo(dir) && game.getMap().has(current.go(dir), actor) && !actor.isDestroyed()) {
playSound("audio/Sword Swing-SoundBible.com-639083727.wav");
game.attack(dir, actor);
return true;
} else if (game.canGo(dir)) {
@ -60,14 +59,6 @@ public class NPC {
GridDirection dir = game.locationDirection(current, neighbour);
IActor actor = game.getMap().getActors(neighbour).get(0); //We assume there is only one actor.
if (current.gridDistanceTo(neighbour) <= range && !actor.isDestroyed()) {
if (game.getActor() instanceof Girl) {
Girl girl = (Girl)game.getActor();
if (girl.getOccupation() == Occupation.BOWSMAN) {
playSound("audio/Bow_Fire_Arrow-Stephan_Schutze-2133929391.wav");
} else if (girl.getOccupation() == Occupation.MAGE) {
playSound("audio/Large Fireball-SoundBible.com-301502490.wav");
}
}
game.rangedAttack(dir, actor);
return true;
} else if (game.canGo(dir)) {