complete players and enemies
This commit is contained in:
@@ -0,0 +1,157 @@
|
|||||||
|
package org.project.game;
|
||||||
|
|
||||||
|
import org.project.entity.enemies.Enemy;
|
||||||
|
import org.project.entity.enemies.Goblin;
|
||||||
|
import org.project.entity.players.Knight;
|
||||||
|
import org.project.entity.players.Player;
|
||||||
|
import org.project.entity.players.Warrior;
|
||||||
|
import org.project.location.Location;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class setupGame {
|
||||||
|
|
||||||
|
private Player player;
|
||||||
|
|
||||||
|
private Location currentLocation;
|
||||||
|
|
||||||
|
private Scanner scanner;
|
||||||
|
|
||||||
|
public setupGame() {
|
||||||
|
|
||||||
|
scanner = new Scanner(System.in);
|
||||||
|
|
||||||
|
setupGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupGame() {
|
||||||
|
|
||||||
|
|
||||||
|
player = new Knight("Hero");
|
||||||
|
|
||||||
|
// Create Locations
|
||||||
|
Location village = new Location("Village");
|
||||||
|
Location forest = new Location("Forest");
|
||||||
|
Location dungeon = new Location("Dungeon");
|
||||||
|
|
||||||
|
// Connect Locations
|
||||||
|
village.connectLocation(forest);
|
||||||
|
forest.connectLocation(village);
|
||||||
|
|
||||||
|
forest.connectLocation(dungeon);
|
||||||
|
dungeon.connectLocation(forest);
|
||||||
|
|
||||||
|
// Add Enemies
|
||||||
|
forest.addEnemy(new Goblin());
|
||||||
|
|
||||||
|
// Starting Location
|
||||||
|
currentLocation = village;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startGame() {
|
||||||
|
|
||||||
|
boolean running = true;
|
||||||
|
|
||||||
|
System.out.println("=== RPG Game Started ===");
|
||||||
|
|
||||||
|
while (running) {
|
||||||
|
|
||||||
|
System.out.println("\nCurrent Location: " + currentLocation.getName());
|
||||||
|
|
||||||
|
System.out.println("1. Move");
|
||||||
|
System.out.println("2. Fight");
|
||||||
|
System.out.println("3. Show Inventory");
|
||||||
|
System.out.println("4. Exit");
|
||||||
|
|
||||||
|
int choice = scanner.nextInt();
|
||||||
|
|
||||||
|
switch (choice) {
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
move();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
fight();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
player.getInventory().showInventory();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
running = false;
|
||||||
|
System.out.println("Game Over.");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
System.out.println("Invalid choice.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void move() {
|
||||||
|
|
||||||
|
if (currentLocation.getConnectedLocations().isEmpty()) {
|
||||||
|
System.out.println("No connected locations.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Where do you want to go?");
|
||||||
|
|
||||||
|
for (int i = 0; i < currentLocation.getConnectedLocations().size(); i++) {
|
||||||
|
|
||||||
|
System.out.println(
|
||||||
|
(i + 1) + ". " +
|
||||||
|
currentLocation.getConnectedLocations().get(i).getName()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
int choice = scanner.nextInt();
|
||||||
|
|
||||||
|
if (choice < 1 || choice > currentLocation.getConnectedLocations().size()) {
|
||||||
|
|
||||||
|
System.out.println("Invalid location.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentLocation =
|
||||||
|
currentLocation.getConnectedLocations().get(choice - 1);
|
||||||
|
|
||||||
|
System.out.println("You moved to " + currentLocation.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fight() {
|
||||||
|
|
||||||
|
if (currentLocation.getEnemies().isEmpty()) {
|
||||||
|
|
||||||
|
System.out.println("No enemies here.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Enemy enemy = currentLocation.getEnemies().get(0);
|
||||||
|
|
||||||
|
System.out.println("A wild " + enemy.getName() + " appeared!");
|
||||||
|
|
||||||
|
while (player.isAlive() && enemy.isAlive()) {
|
||||||
|
|
||||||
|
player.lightAttack(enemy);
|
||||||
|
|
||||||
|
if (enemy.isAlive()) {
|
||||||
|
enemy.attack(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!enemy.isAlive()) {
|
||||||
|
|
||||||
|
System.out.println(enemy.getName() + " defeated!");
|
||||||
|
|
||||||
|
currentLocation.removeEnemy(enemy);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!player.isAlive()) {
|
||||||
|
|
||||||
|
System.out.println("You died.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package org.project;
|
||||||
|
|
||||||
|
public class Inventory {
|
||||||
|
}
|
||||||
@@ -1,70 +1,128 @@
|
|||||||
package org.project.entity;
|
package org.project.entity;
|
||||||
|
|
||||||
|
import org.project.item.weapons.Weapon;
|
||||||
|
|
||||||
public abstract class Entity {
|
public abstract class Entity {
|
||||||
|
|
||||||
protected String name;
|
protected String name;
|
||||||
protected int hp;
|
protected int hp;
|
||||||
protected int maxHP;
|
protected int maxHp;
|
||||||
protected int mp;
|
|
||||||
protected int maxMP;
|
protected int mana;
|
||||||
protected boolean alive = true;
|
protected int maxMana;
|
||||||
|
|
||||||
|
protected Weapon weapon;
|
||||||
|
|
||||||
|
protected boolean isDefending;
|
||||||
|
|
||||||
|
public Entity(String name, int hp, int mana, Weapon weapon) {
|
||||||
|
|
||||||
public Entity(String name , int maxHP , int maxMP){
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.maxHP = maxHP;
|
|
||||||
this.hp = maxHP;
|
this.hp = hp;
|
||||||
this.maxMP = maxMP;
|
this.maxHp = hp;
|
||||||
this.mp = maxMP;
|
|
||||||
|
this.mana = mana;
|
||||||
|
this.maxMana = mana;
|
||||||
|
|
||||||
|
this.weapon = weapon;
|
||||||
|
|
||||||
|
this.isDefending = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void attack(Entity target);
|
public boolean useMana(int amount) {
|
||||||
|
|
||||||
public abstract void defend();
|
if (mana >= amount) {
|
||||||
|
|
||||||
public void heal(int amount){
|
mana -= amount;
|
||||||
hp += amount;
|
return true;
|
||||||
if(hp > maxHP) hp=maxHP;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void consumeMana(int amount){
|
return false;
|
||||||
mp -= amount;
|
|
||||||
if(mp < 0 ) mp=0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fillMana(int amount){
|
public void takeDamage(int damage) {
|
||||||
mp += amount;
|
|
||||||
if(mp > maxMP) mp=maxMP;
|
if (isDefending) {
|
||||||
|
damage /= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void takeDamage(int damage){
|
|
||||||
hp -= damage;
|
hp -= damage;
|
||||||
if(hp <= 0 ){
|
|
||||||
hp=0;
|
if (hp < 0) {
|
||||||
alive = false;
|
hp = 0;
|
||||||
System.out.println(name + " failed! ");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAlive(){
|
System.out.println(name + " took " + damage + " damage.");
|
||||||
return alive;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHp(){
|
public void heal(int amount) {
|
||||||
return hp;
|
|
||||||
|
hp += amount;
|
||||||
|
|
||||||
|
if (hp > maxHp) {
|
||||||
|
hp = maxHp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMp(){
|
System.out.println(name + " healed for " + amount + " HP.");
|
||||||
return mp;
|
|
||||||
}
|
|
||||||
public int getMaxHP(){
|
|
||||||
return maxHP;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxMP(){
|
public boolean isAlive() {
|
||||||
return maxMP;
|
return hp > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void defend() {
|
||||||
|
|
||||||
|
isDefending = true;
|
||||||
|
|
||||||
|
System.out.println(name + " is defending.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetDefending() {
|
||||||
|
isDefending = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getHp() {
|
||||||
|
return hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHp(int hp) {
|
||||||
|
this.hp = hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxHp() {
|
||||||
|
return maxHp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMana() {
|
||||||
|
return mana;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMana(int mana) {
|
||||||
|
this.mana = mana;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxMana() {
|
||||||
|
return maxMana;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Weapon getWeapon() {
|
||||||
|
return weapon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWeapon(Weapon weapon) {
|
||||||
|
this.weapon = weapon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDefending() {
|
||||||
|
return isDefending;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDefending(boolean defending) {
|
||||||
|
isDefending = defending;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,24 @@
|
|||||||
package org.project.entity.enemies;
|
package org.project.entity.enemies;
|
||||||
|
|
||||||
import org.project.item.weapons.Weapon;
|
import org.project.entity.Entity;
|
||||||
|
import org.project.item.weapons.Staff;
|
||||||
|
|
||||||
public class Dragon extends Enemy {
|
public class Dragon extends Enemy {
|
||||||
|
|
||||||
public Dragon(Weapon weapon) {
|
public Dragon() {
|
||||||
super("Dragon", 100, 50, weapon);
|
super("Dragon", 300, 100, new Staff() , 150);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void specialAbility(Entity target) {
|
||||||
|
int damage = getWeapon().getDamage() * 3;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
target.takeDamage(damage);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(getName() + " uses Breath Fire!");
|
||||||
|
System.out.println(target.getName() + " takes " + damage + " fire damage.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,71 +1,69 @@
|
|||||||
package org.project.entity.enemies;
|
package org.project.entity.enemies;
|
||||||
|
|
||||||
import org.project.entity.Entity;
|
import org.project.entity.Entity;
|
||||||
|
import org.project.item.Item;
|
||||||
|
import org.project.item.Key;
|
||||||
|
import org.project.item.consumables.Flask;
|
||||||
import org.project.item.weapons.Weapon;
|
import org.project.item.weapons.Weapon;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public abstract class Enemy extends Entity {
|
public abstract class Enemy extends Entity {
|
||||||
|
|
||||||
protected Weapon weapon;
|
protected int xpReward;
|
||||||
protected boolean isDefending;
|
|
||||||
|
|
||||||
public Enemy(String name, int maxHP, int maxMP, Weapon weapon) {
|
public Enemy(String name, int hp, int mana, Weapon weapon, int xpReward) {
|
||||||
super(name, maxHP, maxMP);
|
|
||||||
|
|
||||||
this.weapon = weapon;
|
super(name, hp, mana, weapon);
|
||||||
this.isDefending = false;
|
|
||||||
|
this.xpReward = xpReward;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getXpReward() {
|
||||||
|
return xpReward;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void attack(Entity target) {
|
public void attack(Entity target) {
|
||||||
|
|
||||||
|
int damage = 0;
|
||||||
|
|
||||||
int manaCost = weapon.getManaCost();
|
if (weapon != null) {
|
||||||
|
damage = weapon.getDamage();
|
||||||
if (mp < manaCost) {
|
|
||||||
System.out.println(name + " tried to attack but does not have enough MP!");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
target.takeDamage(damage);
|
||||||
|
|
||||||
mp -= manaCost;
|
System.out.println(name + " attacks " + target.getName());
|
||||||
|
|
||||||
System.out.println(
|
target.resetDefending();
|
||||||
name + " attacks " + target.getName() +
|
|
||||||
" with " + weapon.getClass().getSimpleName() + "!"
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
weapon.use(target);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void defend() {
|
public void defend() {
|
||||||
isDefending = true;
|
|
||||||
System.out.println(name + " is defending!");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
setDefending(true);
|
||||||
public void takeDamage(int damage) {
|
|
||||||
|
|
||||||
if (damage <= 0) return;
|
System.out.println(name + " is defending.");
|
||||||
|
|
||||||
|
|
||||||
if (isDefending) {
|
|
||||||
damage /= 2;
|
|
||||||
isDefending = false;
|
|
||||||
System.out.println(name + " defended and reduced the damage!");
|
|
||||||
}
|
|
||||||
|
|
||||||
hp -= damage;
|
|
||||||
if (hp < 0) hp = 0;
|
|
||||||
|
|
||||||
System.out.println(
|
|
||||||
name + " took " + damage + " damage. (" + hp + "/" + maxHP + ")"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Weapon getWeapon() {
|
public Item dropLoot() {
|
||||||
return weapon;
|
|
||||||
|
Random random = new Random();
|
||||||
|
|
||||||
|
int chance = random.nextInt(100);
|
||||||
|
|
||||||
|
if (chance < 30) {
|
||||||
|
return new Flask();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (chance >= 30 && chance < 40) {
|
||||||
|
return new Key("Castle Key");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public abstract void specialAbility(Entity target);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,22 @@
|
|||||||
package org.project.entity.enemies;
|
package org.project.entity.enemies;
|
||||||
|
|
||||||
import org.project.item.weapons.Weapon;
|
import org.project.entity.Entity;
|
||||||
|
import org.project.item.weapons.Dagger;
|
||||||
|
|
||||||
public class Goblin extends Enemy {
|
public class Goblin extends Enemy {
|
||||||
|
|
||||||
public Goblin(Weapon weapon) {
|
public Goblin() {
|
||||||
super("Goblin", 30, 10, weapon);
|
super("Goblin", 80, 0, new Dagger() , 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void specialAbility(Entity target) {
|
||||||
|
int damage = getWeapon().getDamage() + 5;
|
||||||
|
|
||||||
|
target.takeDamage(damage);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("Goblin uses Sneak Attack!");
|
||||||
|
System.out.println(target.getName() + " takes " + damage + " damage.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,18 @@
|
|||||||
package org.project.entity.enemies;
|
package org.project.entity.enemies;
|
||||||
|
|
||||||
import org.project.item.weapons.Weapon;
|
import org.project.entity.Entity;
|
||||||
|
import org.project.item.weapons.Sword;
|
||||||
|
|
||||||
public class Skeleton extends Enemy {
|
public class Skeleton extends Enemy {
|
||||||
|
|
||||||
public Skeleton(Weapon weapon) {
|
public Skeleton() {
|
||||||
super("Skeleton", 35, 10, weapon);
|
super("Skeleton", 100, 0, new Sword() , 30);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void specialAbility(Entity target) {
|
||||||
|
defend();
|
||||||
|
|
||||||
|
System.out.println("Skeleton raises its shield.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,24 @@
|
|||||||
package org.project.entity.enemies;
|
package org.project.entity.enemies;
|
||||||
|
|
||||||
import org.project.item.weapons.Weapon;
|
import org.project.entity.Entity;
|
||||||
|
import org.project.item.weapons.Dagger;
|
||||||
|
|
||||||
public class Vampire extends Enemy {
|
public class Vampire extends Enemy {
|
||||||
|
|
||||||
public Vampire(Weapon weapon) {
|
public Vampire() {
|
||||||
super("Vampire", 45, 20, weapon);
|
super("Vampire", 120, 50, new Dagger() , 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void specialAbility(Entity target) {
|
||||||
|
int damage = getWeapon().getDamage() * 2;
|
||||||
|
|
||||||
|
target.takeDamage(damage);
|
||||||
|
|
||||||
|
|
||||||
|
setHp(getHp() + damage / 2);
|
||||||
|
|
||||||
|
System.out.println("Vampire uses Life Drain!");
|
||||||
|
System.out.println(target.getName() + " takes " + damage + " damage.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,76 @@
|
|||||||
package org.project.entity.players;
|
package org.project.entity.players;
|
||||||
|
|
||||||
import org.project.item.armors.Armor;
|
import org.project.entity.Entity;
|
||||||
import org.project.item.weapons.Weapon;
|
import org.project.item.armors.AssassinArmor;
|
||||||
|
import org.project.item.weapons.Dagger;
|
||||||
|
|
||||||
public class Assassin extends Player{
|
public class Assassin extends Player {
|
||||||
public Assassin(String name , Weapon weapon , Armor armor){
|
|
||||||
super(name , 75 , 50 , weapon , armor);
|
public Assassin(String name) {
|
||||||
|
super(name, 120, 80, new Dagger());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void heavyAttack(Entity target) {
|
||||||
|
|
||||||
|
int manaCost = 15;
|
||||||
|
|
||||||
|
if (getMana() < manaCost) {
|
||||||
|
System.out.println("Not enough mana!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
useMana(manaCost);
|
||||||
|
|
||||||
|
int damage = weapon.getDamage() * 2;
|
||||||
|
|
||||||
|
if (target.isDefending()) {
|
||||||
|
damage /= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
target.takeDamage(damage);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(name + " performs a deadly strike!");
|
||||||
|
System.out.println(target.getName() + " takes " + damage + " damage.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void heal() {
|
||||||
|
|
||||||
|
int healAmount = 20;
|
||||||
|
int manaGain = 20;
|
||||||
|
|
||||||
|
setHp(Math.min(getHp() + healAmount, getMaxHp()));
|
||||||
|
|
||||||
|
setMana(Math.min(getMana() + manaGain, getMaxMana()));
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(name + " regains " + healAmount + " HP and " + manaGain + " mana.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void specialAbility(Entity target) {
|
||||||
|
|
||||||
|
int manaCost = 30;
|
||||||
|
|
||||||
|
if (getMana() < manaCost) {
|
||||||
|
System.out.println("Not enough mana!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
useMana(manaCost);
|
||||||
|
|
||||||
|
int damage = weapon.getDamage() * 3;
|
||||||
|
|
||||||
|
if (target.isDefending()) {
|
||||||
|
damage /= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
target.takeDamage(damage);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(name + " uses Shadow Strike!");
|
||||||
|
System.out.println(target.getName() + " takes " + damage + " damage.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package org.project.entity.players;
|
||||||
|
|
||||||
|
public class CombatActions {
|
||||||
|
}
|
||||||
@@ -1,11 +1,54 @@
|
|||||||
package org.project.entity.players;
|
package org.project.entity.players;
|
||||||
|
|
||||||
import org.project.item.armors.Armor;
|
import org.project.entity.Entity;
|
||||||
import org.project.item.weapons.Weapon;
|
import org.project.item.armors.KnightArmor;
|
||||||
|
import org.project.item.weapons.Sword;
|
||||||
|
|
||||||
public class Knight extends Player {
|
public class Knight extends Player {
|
||||||
|
|
||||||
public Knight(String name, Weapon weapon , Armor armor) {
|
public Knight(String name) {
|
||||||
super(name, 100, 30, weapon , armor);
|
super(name, 150, 50, new Sword());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void heavyAttack(Entity target) {
|
||||||
|
|
||||||
|
int damage = weapon.getDamage() * 2;
|
||||||
|
|
||||||
|
if (target.isDefending()) {
|
||||||
|
damage /= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
target.takeDamage(damage);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(name + " performs a heavy sword strike!");
|
||||||
|
System.out.println(target.getName() + " takes " + damage + " damage.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void heal() {
|
||||||
|
|
||||||
|
int healAmount = 30;
|
||||||
|
setHp(Math.min(getHp() + healAmount, getMaxHp()));
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(name + " recovers " + healAmount + " HP.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void specialAbility(Entity target) {
|
||||||
|
|
||||||
|
int damage = weapon.getDamage() + 20;
|
||||||
|
|
||||||
|
if (target.isDefending()) {
|
||||||
|
damage /= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
target.takeDamage(damage);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(name + " uses Shield Bash!");
|
||||||
|
System.out.println(target.getName() + " takes " + damage + " damage.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
package org.project.entity.players;
|
|
||||||
|
|
||||||
import org.project.item.armors.Armor;
|
|
||||||
import org.project.item.weapons.Weapon;
|
|
||||||
|
|
||||||
public class Mage extends Player{
|
|
||||||
public Mage(String name , Weapon weapon , Armor armor){
|
|
||||||
super(name , 60 , 100 , weapon , armor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,70 +1,138 @@
|
|||||||
package org.project.entity.players;
|
package org.project.entity.players;
|
||||||
|
|
||||||
import org.project.Main;
|
|
||||||
import org.project.entity.Entity;
|
import org.project.entity.Entity;
|
||||||
|
import org.project.inventory.Inventory;
|
||||||
import org.project.item.weapons.Weapon;
|
import org.project.item.weapons.Weapon;
|
||||||
import org.project.item.armors.Armor;
|
|
||||||
|
|
||||||
public abstract class Player extends Entity {
|
public abstract class Player extends Entity implements CombatActions {
|
||||||
|
|
||||||
protected Weapon weapon;
|
protected Inventory inventory;
|
||||||
protected Armor armor;
|
|
||||||
boolean isDefending = false;
|
|
||||||
|
|
||||||
public Player(String name, int maxHP, int maxMP, Weapon weapon, Armor armor) {
|
protected int level;
|
||||||
super(name, maxHP, maxMP);
|
protected int xp;
|
||||||
this.weapon = weapon;
|
protected int xpToNextLevel;
|
||||||
this.armor = armor;
|
|
||||||
|
protected int baseDamage;
|
||||||
|
|
||||||
|
public Player(String name,
|
||||||
|
int hp,
|
||||||
|
int mana,
|
||||||
|
Weapon weapon) {
|
||||||
|
|
||||||
|
super(name, hp, mana, weapon);
|
||||||
|
|
||||||
|
this.inventory = new Inventory();
|
||||||
|
|
||||||
|
this.level = 1;
|
||||||
|
this.xp = 0;
|
||||||
|
this.xpToNextLevel = 100;
|
||||||
|
|
||||||
|
this.baseDamage = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Inventory getInventory() {
|
||||||
|
return inventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLevel() {
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getXp() {
|
||||||
|
return xp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBaseDamage() {
|
||||||
|
return baseDamage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void gainXP(int amount) {
|
||||||
|
|
||||||
|
xp += amount;
|
||||||
|
|
||||||
|
System.out.println(name + " gained " + amount + " XP!");
|
||||||
|
|
||||||
|
while (xp >= xpToNextLevel) {
|
||||||
|
levelUp();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void levelUp() {
|
||||||
|
|
||||||
|
level++;
|
||||||
|
|
||||||
|
xp -= xpToNextLevel;
|
||||||
|
|
||||||
|
xpToNextLevel += 50;
|
||||||
|
|
||||||
|
maxHp += 20;
|
||||||
|
hp = maxHp;
|
||||||
|
|
||||||
|
maxMana += 10;
|
||||||
|
mana = maxMana;
|
||||||
|
|
||||||
|
baseDamage += 5;
|
||||||
|
|
||||||
|
System.out.println("\n=== LEVEL UP ===");
|
||||||
|
System.out.println(name + " reached level " + level);
|
||||||
|
System.out.println("HP increased!");
|
||||||
|
System.out.println("Mana increased!");
|
||||||
|
System.out.println("Damage increased!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void attack(Entity target) {
|
public void lightAttack(Entity target) {
|
||||||
if (weapon == null) {
|
|
||||||
System.out.println(name + " has no weapon!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mp < weapon.getManaCost()) {
|
System.out.println(
|
||||||
System.out.println(name + " doesn't have enough mana!");
|
this.name +
|
||||||
return;
|
" uses a light attack on " +
|
||||||
}
|
target.getName()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (weapon != null) {
|
||||||
|
|
||||||
mp -= weapon.getManaCost();
|
|
||||||
weapon.use(target);
|
weapon.use(target);
|
||||||
|
|
||||||
System.out.println(name + " attacked " + target.getName() +
|
} else {
|
||||||
" with " + weapon.getClass().getSimpleName());
|
|
||||||
|
target.takeDamage(baseDamage);
|
||||||
|
|
||||||
|
System.out.println("Basic attack dealt " +
|
||||||
|
baseDamage +
|
||||||
|
" damage.");
|
||||||
|
}
|
||||||
|
|
||||||
|
target.resetDefending();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void defend() {
|
public void defend() {
|
||||||
|
|
||||||
isDefending = true;
|
isDefending = true;
|
||||||
System.out.println(name + " is defending! ");
|
|
||||||
|
System.out.println(name + " is defending!");
|
||||||
}
|
}
|
||||||
|
public int getKeyCount() {
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
for (var item : inventory.getItems()) {
|
||||||
|
|
||||||
|
if (item.getName().equals("Castle Key")) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void takeDamage(int damage) {
|
public abstract void heavyAttack(Entity target);
|
||||||
if (damage <= 0) return;
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract void heal();
|
||||||
|
|
||||||
if (armor != null) {
|
@Override
|
||||||
damage -= armor.getDefense();
|
public abstract void specialAbility(Entity target);
|
||||||
System.out.println(name + "'s armor reduced damage by " + armor.getDefense());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (isDefending) {
|
|
||||||
damage /= 2;
|
|
||||||
isDefending = false;
|
|
||||||
System.out.println(name + " defended and reduced damage!");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
damage = Math.max(0, damage);
|
|
||||||
|
|
||||||
hp -= damage;
|
|
||||||
if (hp < 0) hp = 0;
|
|
||||||
|
|
||||||
System.out.println(name + " took " + damage + " damage. (" + hp + "/" + maxHP + ")");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package org.project.entity.players;
|
||||||
|
|
||||||
|
import org.project.entity.Entity;
|
||||||
|
import org.project.item.weapons.Staff;
|
||||||
|
|
||||||
|
public class Wizard extends Player {
|
||||||
|
|
||||||
|
public Wizard(String name) {
|
||||||
|
super(name, 100, 150, new Staff());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void heavyAttack(Entity target) {
|
||||||
|
|
||||||
|
int manaCost = 20;
|
||||||
|
|
||||||
|
if (getMana() < manaCost) {
|
||||||
|
System.out.println("Not enough mana!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
useMana(manaCost);
|
||||||
|
|
||||||
|
int damage = weapon.getDamage() * 2;
|
||||||
|
|
||||||
|
if (target.isDefending()) {
|
||||||
|
damage /= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
target.takeDamage(damage);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(name + " casts a powerful fire spell!");
|
||||||
|
System.out.println(target.getName() + " takes " + damage + " damage.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void heal() {
|
||||||
|
|
||||||
|
int manaCost = 15;
|
||||||
|
|
||||||
|
if (getMana() < manaCost) {
|
||||||
|
System.out.println("Not enough mana!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
useMana(manaCost);
|
||||||
|
|
||||||
|
int healAmount = 40;
|
||||||
|
setHp(Math.min(getHp() + healAmount, getMaxHp()));
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(name + " casts a healing spell and restores " + healAmount + " HP.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void specialAbility(Entity target) {
|
||||||
|
|
||||||
|
int manaCost = 40;
|
||||||
|
|
||||||
|
if (getMana() < manaCost) {
|
||||||
|
System.out.println("Not enough mana!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
useMana(manaCost);
|
||||||
|
|
||||||
|
int damage = weapon.getDamage() * 3;
|
||||||
|
|
||||||
|
if (target.isDefending()) {
|
||||||
|
damage /= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
target.takeDamage(damage);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(name + " unleashes Lightning Storm!");
|
||||||
|
System.out.println(target.getName() + " takes " + damage + " damage.");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package org.project.item;
|
||||||
|
|
||||||
|
public class Key {
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package org.project.item.armors;
|
||||||
|
|
||||||
|
public class AssassinArmor {
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package org.project.item.armors;
|
||||||
|
|
||||||
|
public class MageArmor {
|
||||||
|
}
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package org.project.item.weapons;
|
|
||||||
|
|
||||||
import org.project.entity.Entity;
|
|
||||||
|
|
||||||
public class BasicWeapon extends Weapon {
|
|
||||||
|
|
||||||
public BasicWeapon() {
|
|
||||||
super(5, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void use(Entity target) {
|
|
||||||
target.takeDamage(damage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package org.project.item.weapons;
|
||||||
|
|
||||||
|
public class Dragger {
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package org.project.item.weapons;
|
||||||
|
|
||||||
|
public class Staff {
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user