Legger til en del fremdeles uimplementerte items
This commit is contained in:
parent
478a8f02a3
commit
d1b4f4a316
@ -73,5 +73,10 @@ c)
|
|||||||
|
|
||||||
# Del C
|
# Del C
|
||||||
## Oversikt over designvalg og hva du har gjort
|
## Oversikt over designvalg og hva du har gjort
|
||||||
* ... blah, blah, er implementert i klassen [KurtMario](src/inf101/v18/rogue101/player/KurtMario.java), blah, blah `ITurtleShell` ...
|
*
|
||||||
|
|
||||||
|
### Tredjepartsfiler
|
||||||
|
* Bow Fire Arrow Sound fra http://soundbible.com av Stephan Schutze
|
||||||
|
* Sword Swing Sound fra http://soundbible.com av Mike Koenig
|
||||||
|
* Large Fireball Sound fra http://soundbible.com av Mike Koenig
|
||||||
|
|
||||||
|
BIN
audio/Bow_Fire_Arrow-Stephan_Schutze-2133929391.wav
Normal file
BIN
audio/Bow_Fire_Arrow-Stephan_Schutze-2133929391.wav
Normal file
Binary file not shown.
BIN
audio/Large Fireball-SoundBible.com-301502490.wav
Normal file
BIN
audio/Large Fireball-SoundBible.com-301502490.wav
Normal file
Binary file not shown.
BIN
audio/Sword Swing-SoundBible.com-639083727.wav
Normal file
BIN
audio/Sword Swing-SoundBible.com-639083727.wav
Normal file
Binary file not shown.
@ -88,7 +88,7 @@ public class Main extends Application {
|
|||||||
printer.setTextMode(MAIN_TEXT_MODE, true);
|
printer.setTextMode(MAIN_TEXT_MODE, true);
|
||||||
|
|
||||||
// Font with emojis – need separate download
|
// Font with emojis – need separate download
|
||||||
// printer.setFont(Printer.FONT_SYMBOLA);
|
printer.setFont(Printer.FONT_SYMBOLA);
|
||||||
|
|
||||||
if (grid)
|
if (grid)
|
||||||
printer.drawCharCells();
|
printer.drawCharCells();
|
||||||
|
@ -14,17 +14,17 @@ import java.util.List;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class Girl implements INonPlayer {
|
public class Girl implements INonPlayer {
|
||||||
private String name = randomName();
|
private final String name = randomName();
|
||||||
private Age age = Age.getRandom();
|
private final Age age = Age.getRandom();
|
||||||
private Personality personality = Personality.getRandom();
|
private final Personality personality = Personality.getRandom();
|
||||||
private Occupation occupation = Occupation.getRandom();
|
private final Occupation occupation = Occupation.getRandom();
|
||||||
private int maxhp;
|
private int maxhp;
|
||||||
private int hp;
|
private int hp;
|
||||||
private int attack;
|
private int attack;
|
||||||
private int defence;
|
private int defence;
|
||||||
private int visibility;
|
private int visibility;
|
||||||
private IItem equipped;
|
private IItem equipped;
|
||||||
private static Random random = new Random();
|
private static final Random random = new Random();
|
||||||
|
|
||||||
public Girl() {
|
public Girl() {
|
||||||
setStats();
|
setStats();
|
||||||
@ -94,7 +94,7 @@ public class Girl implements INonPlayer {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case AFRAID:
|
case AFRAID:
|
||||||
if (!NPC.flee(game)) {
|
if (NPC.flee(game)) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
attack = true;
|
attack = true;
|
||||||
@ -129,6 +129,10 @@ public class Girl implements INonPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Occupation getOccupation() {
|
||||||
|
return occupation;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAttack() {
|
public int getAttack() {
|
||||||
return attack;
|
return attack;
|
||||||
@ -164,6 +168,11 @@ public class Girl implements INonPlayer {
|
|||||||
return 8;
|
return 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPrintSymbol() {
|
||||||
|
return "𓀠";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSymbol() {
|
public String getSymbol() {
|
||||||
return "G";
|
return "G";
|
||||||
|
@ -5,9 +5,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import inf101.v18.gfx.gfxmode.ITurtle;
|
import inf101.v18.gfx.gfxmode.ITurtle;
|
||||||
import inf101.v18.grid.GridDirection;
|
import inf101.v18.grid.GridDirection;
|
||||||
import inf101.v18.grid.ILocation;
|
|
||||||
import inf101.v18.rogue101.game.IGame;
|
import inf101.v18.rogue101.game.IGame;
|
||||||
import inf101.v18.rogue101.objects.IActor;
|
|
||||||
import inf101.v18.rogue101.objects.IItem;
|
import inf101.v18.rogue101.objects.IItem;
|
||||||
import inf101.v18.rogue101.objects.INonPlayer;
|
import inf101.v18.rogue101.objects.INonPlayer;
|
||||||
import inf101.v18.rogue101.shared.NPC;
|
import inf101.v18.rogue101.shared.NPC;
|
||||||
|
@ -43,6 +43,12 @@ public class Game implements IGame {
|
|||||||
* Useful random generator
|
* Useful random generator
|
||||||
*/
|
*/
|
||||||
private Random random = new Random();
|
private Random random = new Random();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves the last three messages
|
||||||
|
*/
|
||||||
|
private List<String> lastMessages = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The game map. {@link IGameMap} gives us a few more details than
|
* The game map. {@link IGameMap} gives us a few more details than
|
||||||
* {@link IMapView} (write access to item lists); the game needs this but
|
* {@link IMapView} (write access to item lists); the game needs this but
|
||||||
@ -69,7 +75,7 @@ public class Game implements IGame {
|
|||||||
// inputGrid will be filled with single-character strings indicating what (if
|
// inputGrid will be filled with single-character strings indicating what (if
|
||||||
// anything)
|
// anything)
|
||||||
// should be placed at that map square
|
// should be placed at that map square
|
||||||
IGrid<String> inputGrid = MapReader.readFile("maps/level1.txt");
|
IGrid<String> inputGrid = MapReader.readFile("maps/testmap.txt");
|
||||||
if (inputGrid == null) {
|
if (inputGrid == null) {
|
||||||
System.err.println("Map not found – falling back to builtin map");
|
System.err.println("Map not found – falling back to builtin map");
|
||||||
inputGrid = MapReader.readString(Main.BUILTIN_MAP);
|
inputGrid = MapReader.readString(Main.BUILTIN_MAP);
|
||||||
@ -159,7 +165,7 @@ public class Game implements IGame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// process actors one by one; for the IPlayer, we return and wait for keypresses
|
// process actors one by one; for the IPlayer, we return and wait for keypresses
|
||||||
// Possible TODO: for INonPlayer, we could also return early (returning
|
// Possible for INonPlayer, we could also return early (returning
|
||||||
// *false*), and then insert a little timer delay between each non-player move
|
// *false*), and then insert a little timer delay between each non-player move
|
||||||
// (the timer
|
// (the timer
|
||||||
// is already set up in Main)
|
// is already set up in Main)
|
||||||
@ -179,6 +185,7 @@ public class Game implements IGame {
|
|||||||
((INonPlayer) currentActor).doTurn(this);
|
((INonPlayer) currentActor).doTurn(this);
|
||||||
// remove any dead items from current location
|
// remove any dead items from current location
|
||||||
map.clean(currentLocation);
|
map.clean(currentLocation);
|
||||||
|
return false;
|
||||||
} else if (currentActor instanceof IPlayer) {
|
} else if (currentActor instanceof IPlayer) {
|
||||||
if (currentActor.isDestroyed()) {
|
if (currentActor.isDestroyed()) {
|
||||||
// a dead human player gets removed from the game
|
// a dead human player gets removed from the game
|
||||||
@ -289,11 +296,23 @@ public class Game implements IGame {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void displayMessage(String s) {
|
public void displayMessage(String s) {
|
||||||
// it should be safe to print to lines Main.LINE_MSG1, Main.LINE_MSG2,
|
if (lastMessages.size() >= 3) {
|
||||||
// Main.LINE_MSG3
|
lastMessages.remove(2);
|
||||||
// TODO: you can save the last three lines, and display/scroll them
|
}
|
||||||
|
lastMessages.add(0, s);
|
||||||
printer.clearLine(Main.LINE_MSG1);
|
printer.clearLine(Main.LINE_MSG1);
|
||||||
printer.printAt(1, Main.LINE_MSG1, s);
|
printer.clearLine(Main.LINE_MSG2);
|
||||||
|
printer.clearLine(Main.LINE_MSG3);
|
||||||
|
System.out.println(lastMessages.size());
|
||||||
|
if (lastMessages.size() > 0) {
|
||||||
|
printer.printAt(1, Main.LINE_MSG1, lastMessages.get(0));
|
||||||
|
}
|
||||||
|
if (lastMessages.size() > 1) {
|
||||||
|
printer.printAt(1, Main.LINE_MSG2, lastMessages.get(1));
|
||||||
|
}
|
||||||
|
if (lastMessages.size() > 2) {
|
||||||
|
printer.printAt(1, Main.LINE_MSG3, lastMessages.get(2));
|
||||||
|
}
|
||||||
System.out.println("Message: «" + s + "»");
|
System.out.println("Message: «" + s + "»");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -425,11 +444,19 @@ public class Game implements IGame {
|
|||||||
@Override
|
@Override
|
||||||
public IItem pickUp(IItem item) {
|
public IItem pickUp(IItem item) {
|
||||||
if (item != null && map.has(currentLocation, item)) {
|
if (item != null && map.has(currentLocation, item)) {
|
||||||
// TODO: bruk getAttack()/getDefence() til å avgjøre om man får til å plukke opp
|
if (item instanceof IActor) {
|
||||||
// tingen
|
if (item.getCurrentHealth() / item.getMaxHealth() < 3) {
|
||||||
// evt.: en IActor kan bare plukkes opp hvis den har få/ingen helsepoeng igjen
|
map.remove(currentLocation, item);
|
||||||
map.remove(currentLocation, item);
|
return item;
|
||||||
return item;
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else if (currentActor.getAttack() > item.getDefence()) {
|
||||||
|
map.remove(currentLocation, item);
|
||||||
|
return item;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -440,13 +467,13 @@ public class Game implements IGame {
|
|||||||
ILocation loc = currentLocation;
|
ILocation loc = currentLocation;
|
||||||
int damage = (currentActor.getAttack() + random.nextInt(20) + 1)
|
int damage = (currentActor.getAttack() + random.nextInt(20) + 1)
|
||||||
/ loc.gridDistanceTo(map.getLocation(target)); //Close attacks will take more damage.
|
/ loc.gridDistanceTo(map.getLocation(target)); //Close attacks will take more damage.
|
||||||
if (damage >= target.getDefence() + 10) {
|
if (damage >= target.getDefence()) {
|
||||||
int actualDamage = target.handleDamage(this, target, damage);
|
int actualDamage = target.handleDamage(this, target, damage);
|
||||||
formatMessage("%s hits %s for %d damage", currentActor.getName(), target.getName(), actualDamage);
|
formatMessage("%s hits %s for %d damage", currentActor.getName(), target.getName(), actualDamage);
|
||||||
} else {
|
} else {
|
||||||
displayMessage("The attack missed.");
|
displayMessage("The attack missed.");
|
||||||
}
|
}
|
||||||
map.clean(loc);
|
map.clean(map.getLocation(target));
|
||||||
if (target.isDestroyed() && map.has(currentLocation.go(dir), target)) {
|
if (target.isDestroyed() && map.has(currentLocation.go(dir), target)) {
|
||||||
return move(dir);
|
return move(dir);
|
||||||
} else {
|
} else {
|
||||||
|
52
src/inf101/v18/rogue101/items/Bow.java
Normal file
52
src/inf101/v18/rogue101/items/Bow.java
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
package inf101.v18.rogue101.items;
|
||||||
|
|
||||||
|
import inf101.v18.rogue101.game.IGame;
|
||||||
|
import inf101.v18.rogue101.objects.IItem;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class Bow implements IRangedWeapon {
|
||||||
|
private static final Random random = new Random();
|
||||||
|
private final int damage = 3 + random.nextInt(20);
|
||||||
|
private final int hp = getMaxHealth();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getWeaponDamage() {
|
||||||
|
return damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCurrentHealth() {
|
||||||
|
return hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDefence() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxHealth() {
|
||||||
|
return 110;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Unknown bow";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSize() {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSymbol() {
|
||||||
|
return "B";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int handleDamage(IGame game, IItem source, int amount) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
33
src/inf101/v18/rogue101/items/IBuffItem.java
Normal file
33
src/inf101/v18/rogue101/items/IBuffItem.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package inf101.v18.rogue101.items;
|
||||||
|
|
||||||
|
import inf101.v18.rogue101.objects.IItem;
|
||||||
|
|
||||||
|
interface IBuffItem extends IItem {
|
||||||
|
/**
|
||||||
|
* Retrieve damage increase done by the buff item.
|
||||||
|
*
|
||||||
|
* @return An int, May be 0
|
||||||
|
*/
|
||||||
|
int getBuffDamage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve defence increase done by the buff item.
|
||||||
|
*
|
||||||
|
* @return An int, May be 0
|
||||||
|
*/
|
||||||
|
int getBuffDefence();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve defence increase done by the buff item.
|
||||||
|
*
|
||||||
|
* @return An int, May be 0
|
||||||
|
*/
|
||||||
|
int getBuffDamageReduction();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve visibility increase done by the buff item.
|
||||||
|
*
|
||||||
|
* @return An int, May be 0
|
||||||
|
*/
|
||||||
|
int getBuffVisibility();
|
||||||
|
}
|
9
src/inf101/v18/rogue101/items/IConsumable.java
Normal file
9
src/inf101/v18/rogue101/items/IConsumable.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package inf101.v18.rogue101.items;
|
||||||
|
|
||||||
|
import inf101.v18.rogue101.objects.IItem;
|
||||||
|
|
||||||
|
public interface IConsumable extends IItem {
|
||||||
|
void hpIncrease();
|
||||||
|
void attackIncrease();
|
||||||
|
void defenceIncrease();
|
||||||
|
}
|
12
src/inf101/v18/rogue101/items/IMagicWeapon.java
Normal file
12
src/inf101/v18/rogue101/items/IMagicWeapon.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package inf101.v18.rogue101.items;
|
||||||
|
|
||||||
|
import inf101.v18.rogue101.objects.IItem;
|
||||||
|
|
||||||
|
interface IMagicWeapon extends IItem {
|
||||||
|
/**
|
||||||
|
* Retrieves the damage points of a weapon.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int getWeaponDamage();
|
||||||
|
}
|
12
src/inf101/v18/rogue101/items/IMeleeWeapon.java
Normal file
12
src/inf101/v18/rogue101/items/IMeleeWeapon.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package inf101.v18.rogue101.items;
|
||||||
|
|
||||||
|
import inf101.v18.rogue101.objects.IItem;
|
||||||
|
|
||||||
|
interface IMeleeWeapon extends IItem {
|
||||||
|
/**
|
||||||
|
* Retrieves the damage points of a weapon.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int getWeaponDamage();
|
||||||
|
}
|
12
src/inf101/v18/rogue101/items/IRangedWeapon.java
Normal file
12
src/inf101/v18/rogue101/items/IRangedWeapon.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package inf101.v18.rogue101.items;
|
||||||
|
|
||||||
|
import inf101.v18.rogue101.objects.IItem;
|
||||||
|
|
||||||
|
interface IRangedWeapon extends IItem {
|
||||||
|
/**
|
||||||
|
* Retrieves the damage points of a weapon.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int getWeaponDamage();
|
||||||
|
}
|
@ -1,12 +1,10 @@
|
|||||||
package inf101.v18.rogue101.items;
|
package inf101.v18.rogue101.items;
|
||||||
|
|
||||||
import inf101.v18.gfx.gfxmode.ITurtle;
|
|
||||||
import inf101.v18.rogue101.game.IGame;
|
import inf101.v18.rogue101.game.IGame;
|
||||||
import inf101.v18.rogue101.objects.IItem;
|
import inf101.v18.rogue101.objects.IItem;
|
||||||
import javafx.scene.paint.Color;
|
|
||||||
|
|
||||||
public class Manga implements IItem {
|
public class Manga implements IItem {
|
||||||
int hp = getMaxHealth();
|
private int hp = getMaxHealth();
|
||||||
|
|
||||||
/*@Override
|
/*@Override
|
||||||
public boolean draw(ITurtle painter, double w, double h) {
|
public boolean draw(ITurtle painter, double w, double h) {
|
||||||
|
63
src/inf101/v18/rogue101/items/Shield.java
Normal file
63
src/inf101/v18/rogue101/items/Shield.java
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
package inf101.v18.rogue101.items;
|
||||||
|
|
||||||
|
import inf101.v18.rogue101.game.IGame;
|
||||||
|
import inf101.v18.rogue101.objects.IItem;
|
||||||
|
|
||||||
|
public class Shield implements IBuffItem {
|
||||||
|
private final int hp = getMaxHealth();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBuffDamage() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBuffDefence() {
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBuffDamageReduction() {
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBuffVisibility() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCurrentHealth() {
|
||||||
|
return hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDefence() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxHealth() {
|
||||||
|
return 150;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Unknown shield";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSize() {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSymbol() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int handleDamage(IGame game, IItem source, int amount) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
53
src/inf101/v18/rogue101/items/Staff.java
Normal file
53
src/inf101/v18/rogue101/items/Staff.java
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
package inf101.v18.rogue101.items;
|
||||||
|
|
||||||
|
import inf101.v18.rogue101.game.IGame;
|
||||||
|
import inf101.v18.rogue101.objects.IItem;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class Staff implements IMagicWeapon {
|
||||||
|
private static final Random random = new Random();
|
||||||
|
private final int damage = 5 + random.nextInt(25);
|
||||||
|
private int hp = getMaxHealth();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getWeaponDamage() {
|
||||||
|
return damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCurrentHealth() {
|
||||||
|
return hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDefence() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxHealth() {
|
||||||
|
return 90;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Unknown staff";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSize() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSymbol() {
|
||||||
|
return "s";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int handleDamage(IGame game, IItem source, int amount) {
|
||||||
|
hp -= amount;
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
}
|
53
src/inf101/v18/rogue101/items/Sword.java
Normal file
53
src/inf101/v18/rogue101/items/Sword.java
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
package inf101.v18.rogue101.items;
|
||||||
|
|
||||||
|
import inf101.v18.rogue101.game.IGame;
|
||||||
|
import inf101.v18.rogue101.objects.IItem;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class Sword implements IMeleeWeapon {
|
||||||
|
private static final Random random = new Random();
|
||||||
|
private final int damage = 5 + random.nextInt(25);
|
||||||
|
private int hp = getMaxHealth();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getWeaponDamage() {
|
||||||
|
return damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCurrentHealth() {
|
||||||
|
return hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDefence() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxHealth() {
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Unknown sword";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSize() {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSymbol() {
|
||||||
|
return "S";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int handleDamage(IGame game, IItem source, int amount) {
|
||||||
|
hp -= amount;
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
}
|
21
src/inf101/v18/rogue101/map/maps/testmap.txt
Normal file
21
src/inf101/v18/rogue101/map/maps/testmap.txt
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
50 20
|
||||||
|
##################################################
|
||||||
|
# #
|
||||||
|
# #
|
||||||
|
# #
|
||||||
|
# G G #
|
||||||
|
# #
|
||||||
|
############### # #
|
||||||
|
# # #
|
||||||
|
# # #
|
||||||
|
# @ ####################### #
|
||||||
|
# # #
|
||||||
|
# # #
|
||||||
|
# # #
|
||||||
|
# G #
|
||||||
|
# G #
|
||||||
|
# #
|
||||||
|
# #
|
||||||
|
# #
|
||||||
|
# G #
|
||||||
|
##################################################
|
@ -3,13 +3,14 @@ package inf101.v18.rogue101.objects;
|
|||||||
import inf101.v18.grid.GridDirection;
|
import inf101.v18.grid.GridDirection;
|
||||||
import inf101.v18.grid.ILocation;
|
import inf101.v18.grid.ILocation;
|
||||||
import inf101.v18.rogue101.game.IGame;
|
import inf101.v18.rogue101.game.IGame;
|
||||||
|
import inf101.v18.rogue101.shared.NPC;
|
||||||
import javafx.scene.input.KeyCode;
|
import javafx.scene.input.KeyCode;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Player implements IPlayer {
|
public class Player implements IPlayer {
|
||||||
private int hp = getMaxHealth();
|
private int hp = getMaxHealth();
|
||||||
private List<IItem> equipped = new ArrayList<>();
|
private final List<IItem> equipped = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyPressed(IGame game, KeyCode key) {
|
public void keyPressed(IGame game, KeyCode key) {
|
||||||
@ -93,6 +94,7 @@ public class Player implements IPlayer {
|
|||||||
if (game.canGo(dir)) {
|
if (game.canGo(dir)) {
|
||||||
game.move(dir);
|
game.move(dir);
|
||||||
} else if (loc.canGo(dir) && game.getMap().hasActors(loc.go(dir))) {
|
} else if (loc.canGo(dir) && game.getMap().hasActors(loc.go(dir))) {
|
||||||
|
NPC.playSound("audio/Sword Swing-SoundBible.com-639083727.wav");
|
||||||
game.attack(dir, game.getMap().getActors(loc.go(dir)).get(0));
|
game.attack(dir, game.getMap().getActors(loc.go(dir)).get(0));
|
||||||
} else {
|
} else {
|
||||||
game.displayMessage("Umm, it is not possible to move in that direction.");
|
game.displayMessage("Umm, it is not possible to move in that direction.");
|
||||||
@ -101,12 +103,12 @@ public class Player implements IPlayer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAttack() {
|
public int getAttack() {
|
||||||
return 10;
|
return 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getDamage() {
|
public int getDamage() {
|
||||||
return 10;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -116,7 +118,7 @@ public class Player implements IPlayer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getDefence() {
|
public int getDefence() {
|
||||||
return 1;
|
return 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,10 +2,15 @@ package inf101.v18.rogue101.shared;
|
|||||||
|
|
||||||
import inf101.v18.grid.GridDirection;
|
import inf101.v18.grid.GridDirection;
|
||||||
import inf101.v18.grid.ILocation;
|
import inf101.v18.grid.ILocation;
|
||||||
|
import inf101.v18.rogue101.enemies.Girl;
|
||||||
import inf101.v18.rogue101.game.IGame;
|
import inf101.v18.rogue101.game.IGame;
|
||||||
import inf101.v18.rogue101.objects.IActor;
|
import inf101.v18.rogue101.objects.IActor;
|
||||||
import inf101.v18.rogue101.objects.IItem;
|
import inf101.v18.rogue101.objects.IItem;
|
||||||
|
import inf101.v18.rogue101.states.Occupation;
|
||||||
|
import javafx.scene.media.Media;
|
||||||
|
import javafx.scene.media.MediaPlayer;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class NPC {
|
public class NPC {
|
||||||
@ -24,6 +29,7 @@ public class NPC {
|
|||||||
GridDirection dir = game.locationDirection(current, neighbour);
|
GridDirection dir = game.locationDirection(current, neighbour);
|
||||||
IActor actor = game.getMap().getActors(neighbour).get(0); //We assume there is only one actor.
|
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()) {
|
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);
|
game.attack(dir, actor);
|
||||||
return true;
|
return true;
|
||||||
} else if (game.canGo(dir)) {
|
} else if (game.canGo(dir)) {
|
||||||
@ -51,6 +57,14 @@ public class NPC {
|
|||||||
GridDirection dir = game.locationDirection(current, neighbour);
|
GridDirection dir = game.locationDirection(current, neighbour);
|
||||||
IActor actor = game.getMap().getActors(neighbour).get(0); //We assume there is only one actor.
|
IActor actor = game.getMap().getActors(neighbour).get(0); //We assume there is only one actor.
|
||||||
if (current.gridDistanceTo(neighbour) <= range && !actor.isDestroyed()) {
|
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);
|
game.rangedAttack(dir, actor);
|
||||||
return true;
|
return true;
|
||||||
} else if (game.canGo(dir)) {
|
} else if (game.canGo(dir)) {
|
||||||
@ -116,4 +130,10 @@ public class NPC {
|
|||||||
return GridDirection.WEST;
|
return GridDirection.WEST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void playSound(String filename) {
|
||||||
|
Media sound = new Media(new File(filename).toURI().toString());
|
||||||
|
MediaPlayer mediaPlayer = new MediaPlayer(sound);
|
||||||
|
mediaPlayer.play();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import java.util.Random;
|
|||||||
public enum Age {
|
public enum Age {
|
||||||
TODDLER, CHILD, TEEN, ADULT, ELDER;
|
TODDLER, CHILD, TEEN, ADULT, ELDER;
|
||||||
|
|
||||||
private static Random random = new Random();
|
private static final Random random = new Random();
|
||||||
|
|
||||||
public static Age getRandom() {
|
public static Age getRandom() {
|
||||||
return values()[random.nextInt(values().length)];
|
return values()[random.nextInt(values().length)];
|
||||||
|
@ -5,7 +5,7 @@ import java.util.Random;
|
|||||||
public enum Occupation {
|
public enum Occupation {
|
||||||
KNIGHT, MAGE, BOWSMAN;
|
KNIGHT, MAGE, BOWSMAN;
|
||||||
|
|
||||||
private static Random random = new Random();
|
private static final Random random = new Random();
|
||||||
|
|
||||||
public static Occupation getRandom() {
|
public static Occupation getRandom() {
|
||||||
return values()[random.nextInt(values().length)];
|
return values()[random.nextInt(values().length)];
|
||||||
|
@ -5,7 +5,7 @@ import java.util.Random;
|
|||||||
public enum Personality {
|
public enum Personality {
|
||||||
AGRESSIVE, CALM, AFRAID;
|
AGRESSIVE, CALM, AFRAID;
|
||||||
|
|
||||||
private static Random random = new Random();
|
private static final Random random = new Random();
|
||||||
|
|
||||||
public static Personality getRandom() {
|
public static Personality getRandom() {
|
||||||
return values()[random.nextInt(values().length)];
|
return values()[random.nextInt(values().length)];
|
||||||
|
@ -11,34 +11,12 @@ import inf101.v18.rogue101.objects.IPlayer;
|
|||||||
import javafx.scene.input.KeyCode;
|
import javafx.scene.input.KeyCode;
|
||||||
|
|
||||||
public class PlayerTest {
|
public class PlayerTest {
|
||||||
//Tiny maps in collaboration with Stian J. Husum
|
|
||||||
private static String NO_WALLS_MAP = "1 1\n"
|
|
||||||
+ "@\n";
|
|
||||||
|
|
||||||
private static String EMPTY_MAP = "5 5\n"
|
|
||||||
+ "#####\n"
|
|
||||||
+ "# #\n"
|
|
||||||
+ "# @ #\n"
|
|
||||||
+ "# #\n"
|
|
||||||
+ "#####\n";
|
|
||||||
|
|
||||||
private static String RABBIT_MAP = "5 5\n"
|
|
||||||
+ "#####\n"
|
|
||||||
+ "#RRR#\n"
|
|
||||||
+ "#R@R#\n"
|
|
||||||
+ "#RRR#\n"
|
|
||||||
+ "#####\n";
|
|
||||||
|
|
||||||
private static String CARROT_MAP = "5 5\n"
|
|
||||||
+ "#####\n"
|
|
||||||
+ "#CCC#\n"
|
|
||||||
+ "#C@C#\n"
|
|
||||||
+ "#CCC#\n"
|
|
||||||
+ "#####\n";
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOutOfBounds() {
|
public void testOutOfBounds() {
|
||||||
Game game = new Game(NO_WALLS_MAP);
|
String NO_WALLS_MAP = "1 1\n"
|
||||||
|
+ "@\n";
|
||||||
|
Game game = new Game(NO_WALLS_MAP);
|
||||||
IPlayer player = (IPlayer) game.setCurrent(0, 0);
|
IPlayer player = (IPlayer) game.setCurrent(0, 0);
|
||||||
ILocation loc = game.getLocation();
|
ILocation loc = game.getLocation();
|
||||||
player.keyPressed(game, KeyCode.LEFT);
|
player.keyPressed(game, KeyCode.LEFT);
|
||||||
@ -47,6 +25,12 @@ public class PlayerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testActor() {
|
public void testActor() {
|
||||||
|
String RABBIT_MAP = "5 5\n"
|
||||||
|
+ "#####\n"
|
||||||
|
+ "#RRR#\n"
|
||||||
|
+ "#R@R#\n"
|
||||||
|
+ "#RRR#\n"
|
||||||
|
+ "#####\n";
|
||||||
Game game = new Game(RABBIT_MAP);
|
Game game = new Game(RABBIT_MAP);
|
||||||
IPlayer player = (IPlayer) game.setCurrent(2, 2);
|
IPlayer player = (IPlayer) game.setCurrent(2, 2);
|
||||||
ILocation loc = game.getLocation();
|
ILocation loc = game.getLocation();
|
||||||
@ -62,6 +46,12 @@ public class PlayerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testItem() {
|
public void testItem() {
|
||||||
|
String CARROT_MAP = "5 5\n"
|
||||||
|
+ "#####\n"
|
||||||
|
+ "#CCC#\n"
|
||||||
|
+ "#C@C#\n"
|
||||||
|
+ "#CCC#\n"
|
||||||
|
+ "#####\n";
|
||||||
Game game = new Game(CARROT_MAP);
|
Game game = new Game(CARROT_MAP);
|
||||||
IPlayer player = (IPlayer) game.setCurrent(2, 2);
|
IPlayer player = (IPlayer) game.setCurrent(2, 2);
|
||||||
ILocation loc = game.getLocation();
|
ILocation loc = game.getLocation();
|
||||||
@ -76,6 +66,12 @@ public class PlayerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWallsAndKeys() { //This probably seems a little overkill, but we need to check all keys.
|
public void testWallsAndKeys() { //This probably seems a little overkill, but we need to check all keys.
|
||||||
|
String EMPTY_MAP = "5 5\n"
|
||||||
|
+ "#####\n"
|
||||||
|
+ "# #\n"
|
||||||
|
+ "# @ #\n"
|
||||||
|
+ "# #\n"
|
||||||
|
+ "#####\n";
|
||||||
Game game = new Game(EMPTY_MAP);
|
Game game = new Game(EMPTY_MAP);
|
||||||
IPlayer player = (IPlayer) game.setCurrent(2, 2);
|
IPlayer player = (IPlayer) game.setCurrent(2, 2);
|
||||||
ILocation loc = game.getLocation();
|
ILocation loc = game.getLocation();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user