develop #1

Open
HadiSharifi wants to merge 33 commits from develop into main
6 changed files with 64 additions and 17 deletions
Showing only changes of commit 3ab38fddce - Show all commits
@@ -10,6 +10,7 @@ public class Assassin extends Player {
public Assassin() {
super("ASSASSIN",100,100, new Dagger(), new AssassinArmor());
setDefendRate(.7);
setFlask(10,3,false);
}
@Override
@@ -10,6 +10,7 @@ public class Knight extends Player {
public Knight() {
super("Knight",100,90, new Sword(), new KnightArmor());
setDefendRate(.9);
setFlask(20,3,true);
}
@Override
@@ -4,6 +4,8 @@ import org.project.entity.Entity;
import org.project.entity.enemies.Goblin;
import org.project.entity.enemies.Skeleton;
import org.project.item.armors.Armor;
import org.project.item.consumables.Consumable;
import org.project.item.consumables.Flask;
import org.project.item.weapons.Weapon;
@@ -23,6 +25,7 @@ public abstract class Player implements Entity, CombatOptions {
private boolean hasSkeletonKey = false;
private boolean hasVampireKey = false;
private boolean successfulAction = true;
private Consumable flask;
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
this.name = name;
@@ -205,4 +208,12 @@ public abstract class Player implements Entity, CombatOptions {
return successfulAction;
}
public void setFlask(int healAmount, int quantity, boolean isMana) {
flask = new Flask(healAmount, quantity, isMana);
}
public Consumable getFlask() {
return flask;
}
}
@@ -9,6 +9,7 @@ public class Wizard extends Player{
public Wizard() {
super("Wizard",90,90,new Bow(),new WizardArmor());
setDefendRate(.6);
setFlask(30,3,true);
}
@Override
@@ -1,8 +1,28 @@
package org.project.item.consumables;
// TODO: UPDATE IMPLEMENTATION
public abstract class Consumable {
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
}
import org.project.entity.Entity;
import org.project.item.Item;
public abstract class Consumable implements Item {
private String name;
private int quantity;
public Consumable(String name, int quantity) {
this.name = name;
this.quantity = quantity;
}
public abstract void use(Entity target); // distinct from Item.use()
public boolean hasCharges() { return quantity > 0; }
protected void consume() { if (quantity > 0) quantity--; }
public int getQuantity() { return quantity; }
@Override
public String getName() { return name; }
@Override
public void use() { System.out.println("Use " + name + " on a target."); }
}
@@ -2,15 +2,28 @@ package org.project.item.consumables;
import org.project.entity.Entity;
// TODO: UPDATE IMPLEMENTATION
public class Flask {
/*
THIS IS AN EXAMPLE OF A CONSUMABLE DESIGN.
*/
public class Flask extends Consumable {
private int healAmount;
private boolean isMana;
// // TODO: UPDATE USE METHOD
// @Override
// public void use(Entity target) {
// target.heal(target.getMaxHP() / 10);
// }
}
public Flask(int healAmount, int quantity, boolean isMana) {
super(isMana ? "Mana Flask" : "Health Flask", quantity);
this.healAmount = healAmount;
}
@Override
public void use(Entity target) {
if (!hasCharges()) {
System.out.println("Flask is empty!");
return;
}
if (isMana) {
target.setMP(target.getMP() + healAmount);
System.out.println(target.getClass().getSimpleName()
+ " restored " + healAmount + " MP!");
} else {
target.heal(healAmount);
}
consume();
}
}