Matin's implement
This commit is contained in:
@@ -0,0 +1,283 @@
|
||||
package org.project;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.entity.enemies.*;
|
||||
import org.project.entity.players.*;
|
||||
import org.project.location.Location;
|
||||
import org.project.item.weapons.Sword;
|
||||
import org.project.item.armors.KnightArmor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class GameLoop
|
||||
{
|
||||
private Player player;
|
||||
private Enemy currentEnemy;
|
||||
private Scanner scanner;
|
||||
private boolean hasGoblinKey;
|
||||
private boolean hasSkeletonKey;
|
||||
private boolean hasVampireKey;
|
||||
private boolean gameRunning;
|
||||
|
||||
public GameLoop() {
|
||||
scanner = new Scanner(System.in);
|
||||
hasGoblinKey = false;
|
||||
hasSkeletonKey = false;
|
||||
hasVampireKey = false;
|
||||
gameRunning = true;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
System.out.println(" Welcome to Java Knight! ");
|
||||
System.out.println("================================");
|
||||
|
||||
chooseClass();
|
||||
|
||||
while (gameRunning) {
|
||||
mainMenu();
|
||||
}
|
||||
|
||||
scanner.close();
|
||||
}
|
||||
|
||||
private void chooseClass() {
|
||||
System.out.println("\nChoose your class:");
|
||||
System.out.println("1. Knight (High HP, High Damage)");
|
||||
System.out.println("2. Wizard (Highest HP, Spellcaster)");
|
||||
System.out.println("3. Assassin (Highest MP, Critical Hits)");
|
||||
System.out.print("Enter choice (1-3): ");
|
||||
|
||||
int choice = scanner.nextInt();
|
||||
scanner.nextLine();
|
||||
|
||||
switch (choice) {
|
||||
case 1:
|
||||
player = new Knight("Sir Duncan");
|
||||
System.out.println("You have chosen the Knight!");
|
||||
break;
|
||||
case 2:
|
||||
player = new Wizard("Merlin");
|
||||
System.out.println("You have chosen the Wizard!");
|
||||
break;
|
||||
case 3:
|
||||
player = new Assassin("Shadow");
|
||||
System.out.println("You have chosen the Assassin!");
|
||||
break;
|
||||
default:
|
||||
player = new Knight("Sir Duncan");
|
||||
System.out.println("Default: Knight chosen!");
|
||||
}
|
||||
|
||||
System.out.println("\n" + player.getName() + " the " + player.getPlayerClass());
|
||||
System.out.println("HP: " + player.getHP() + "/" + player.getMaxHP());
|
||||
System.out.println("MP: " + player.getMP() + "/" + player.getMaxMP());
|
||||
}
|
||||
|
||||
private void mainMenu() {
|
||||
System.out.println("\n=================================");
|
||||
System.out.println("Location: Forest of Shadows");
|
||||
System.out.println("Player: " + player.getName() + " (Level " + player.level() + ")");
|
||||
System.out.println("HP: " + player.getHP() + "/" + player.getMaxHP());
|
||||
System.out.println("MP: " + player.getMP() + "/" + player.getMaxMP());
|
||||
System.out.println("=================================");
|
||||
System.out.println("1.Fight Enemy");
|
||||
System.out.println("2.Move to another location");
|
||||
|
||||
if (hasAllKeys()) {
|
||||
System.out.println("3.Go to Castle to fight the Dragon!");
|
||||
}
|
||||
|
||||
System.out.println("4.Quit Game");
|
||||
System.out.print("Choose: ");
|
||||
|
||||
int choice = scanner.nextInt();
|
||||
scanner.nextLine();
|
||||
|
||||
switch (choice) {
|
||||
case 1:
|
||||
spawnEnemy();
|
||||
combat();
|
||||
break;
|
||||
case 2:
|
||||
System.out.println("You move to a new location...");
|
||||
break;
|
||||
case 3:
|
||||
if (hasAllKeys()) {
|
||||
fightDragon();
|
||||
} else {
|
||||
System.out.println("You need all 3 keys to enter the Castle!");
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
System.out.println("Thanks for playing Java Knight!");
|
||||
gameRunning = false;
|
||||
break;
|
||||
default:
|
||||
System.out.println("Invalid choice!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean hasAllKeys() {
|
||||
return hasGoblinKey && hasSkeletonKey && hasVampireKey;
|
||||
}
|
||||
|
||||
private void spawnEnemy() {
|
||||
int random = (int)(Math.random() * 3);
|
||||
switch (random) {
|
||||
case 0:
|
||||
currentEnemy = new Goblin();
|
||||
break;
|
||||
case 1:
|
||||
currentEnemy = new Skeleton();
|
||||
break;
|
||||
case 2:
|
||||
currentEnemy = new Vampire();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void combat() {
|
||||
System.out.println("\n COMBAT STARTED! ");
|
||||
System.out.println("=================================");
|
||||
|
||||
while (player.isAlive() && currentEnemy.isAlive()) {
|
||||
playerTurn();
|
||||
if (currentEnemy.isAlive()) {
|
||||
enemyTurn();
|
||||
}
|
||||
}
|
||||
|
||||
if (player.isAlive()) {
|
||||
System.out.println("\n VICTORY! ");
|
||||
handleVictory();
|
||||
} else {
|
||||
System.out.println("\n GAME OVER! You have been defeated! ");
|
||||
gameRunning = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void playerTurn() {
|
||||
System.out.println("\n--- YOUR TURN ---");
|
||||
System.out.println("[" + player.getName() + " - " + player.getHP() + "/" + player.getMaxHP() + " HP | "
|
||||
+ player.getMP() + "/" + player.getMaxMP() + " MP]");
|
||||
System.out.println("[" + currentEnemy.getName() + " - " + currentEnemy.getHP() + "/" + currentEnemy.getMaxHP() + " HP]");
|
||||
System.out.println("\nChoose action:");
|
||||
System.out.println("1. Light Attack (0 MP)");
|
||||
System.out.println("2. Heavy Attack (-10 MP)");
|
||||
System.out.println("3. Defend (-6 MP)");
|
||||
System.out.println("4. Heal (-12 MP)");
|
||||
System.out.println("5. Special Ability (-15/18 MP)");
|
||||
System.out.print("Choice: ");
|
||||
|
||||
int choice = scanner.nextInt();
|
||||
scanner.nextLine();
|
||||
|
||||
switch (choice) {
|
||||
case 1:
|
||||
player.lightAttack(currentEnemy);
|
||||
break;
|
||||
case 2:
|
||||
player.heavyAttack(currentEnemy);
|
||||
break;
|
||||
case 3:
|
||||
player.defend();
|
||||
break;
|
||||
case 4:
|
||||
player.heal(25);
|
||||
break;
|
||||
case 5:
|
||||
player.specialAbility(currentEnemy);
|
||||
break;
|
||||
default:
|
||||
System.out.println("Invalid! Using Light Attack.");
|
||||
player.lightAttack(currentEnemy);
|
||||
}
|
||||
|
||||
System.out.println("\nPress Enter to continue...");
|
||||
scanner.nextLine();
|
||||
}
|
||||
|
||||
private void enemyTurn() {
|
||||
System.out.println("\n--- ENEMY TURN ---");
|
||||
currentEnemy.attack(player);
|
||||
System.out.println("\nPress Enter to continue...");
|
||||
scanner.nextLine();
|
||||
}
|
||||
|
||||
private void handleVictory() {
|
||||
int xpReward = currentEnemy.getXpReward();
|
||||
player.gainXp(xpReward);
|
||||
System.out.println("Earned " + xpReward + " XP!");
|
||||
|
||||
checkKeyDrop();
|
||||
|
||||
player.restoreAfterBattle();
|
||||
|
||||
System.out.println("\nPress Enter to continue...");
|
||||
scanner.nextLine();
|
||||
}
|
||||
|
||||
private void checkKeyDrop() {
|
||||
String enemyType = currentEnemy.getEnemyType();
|
||||
int dropChance = 30;
|
||||
|
||||
if (Math.random() * 100 < dropChance) {
|
||||
switch (enemyType) {
|
||||
case "GOBLIN":
|
||||
if (!hasGoblinKey) {
|
||||
hasGoblinKey = true;
|
||||
System.out.println("You obtained the GOBLIN KEY! (1/3)");
|
||||
} else {
|
||||
System.out.println("You already have the Goblin Key.");
|
||||
}
|
||||
break;
|
||||
case "SKELETON":
|
||||
if (!hasSkeletonKey) {
|
||||
hasSkeletonKey = true;
|
||||
System.out.println("You obtained the SKELETON KEY! (2/3)");
|
||||
} else {
|
||||
System.out.println("You already have the Skeleton Key.");
|
||||
}
|
||||
break;
|
||||
case "VAMPIRE":
|
||||
if (!hasVampireKey) {
|
||||
hasVampireKey = true;
|
||||
System.out.println("You obtained the VAMPIRE KEY! (3/3)");
|
||||
} else {
|
||||
System.out.println("You already have the Vampire Key.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
System.out.println("No key dropped this time... Keep fighting!");
|
||||
}
|
||||
}
|
||||
|
||||
private void fightDragon() {
|
||||
System.out.println("\nYou enter the Castle and face the DRAGON!");
|
||||
System.out.println("THE FINAL BOSS APPEARS!");
|
||||
|
||||
currentEnemy = new Dragon();
|
||||
|
||||
while (player.isAlive() && currentEnemy.isAlive()) {
|
||||
playerTurn();
|
||||
if (currentEnemy.isAlive()) {
|
||||
enemyTurn();
|
||||
}
|
||||
}
|
||||
|
||||
if (player.isAlive()) {
|
||||
System.out.println("\nCONGRATULATIONS!");
|
||||
System.out.println("You have slain the Dragon and broken the curse!");
|
||||
System.out.println("The land of Javanest is saved!");
|
||||
System.out.println("YOU WIN!");
|
||||
gameRunning = false;
|
||||
} else {
|
||||
System.out.println("\nThe Dragon has defeated you!");
|
||||
System.out.println("The curse remains... Game Over!");
|
||||
gameRunning = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.project;
|
||||
|
||||
import org.project.location.Location;
|
||||
|
||||
import org.project.GameLoop;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -11,5 +11,7 @@ public class Main {
|
||||
List<Location> locations = new ArrayList<>();
|
||||
|
||||
// TODO: IMPLEMENT GAMEPLAY
|
||||
GameLoop game = new GameLoop();
|
||||
game.start();
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,17 @@ public interface Entity {
|
||||
|
||||
int getMaxHP();
|
||||
|
||||
int getHP();
|
||||
|
||||
int getMaxMP();
|
||||
|
||||
int getMP();
|
||||
|
||||
String getName();
|
||||
|
||||
boolean isAlive();
|
||||
|
||||
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
public class Dragon extends Enemy
|
||||
{
|
||||
|
||||
public Dragon()
|
||||
{
|
||||
super("Dragon", 150, 100, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getXpReward()
|
||||
{
|
||||
return 500;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEnemyType()
|
||||
{
|
||||
return "DRAGON";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(Entity target)
|
||||
{
|
||||
int damage = 35;
|
||||
System.out.println("DRAGON uses FIRE BREATH for " + damage + " damage!");
|
||||
System.out.println("The fire breath bypasses all defenses!");
|
||||
target.takeDamage(damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void takeDamage(int damage)
|
||||
{
|
||||
super.takeDamage(damage);
|
||||
if (isAlive()) {
|
||||
System.out.println("HP: " + getHP() + "/" + getMaxHP());
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int getMaxMP() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,88 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Enemy {
|
||||
public abstract class Enemy implements Entity {
|
||||
Weapon weapon;
|
||||
private int hp;
|
||||
private int maxHp;
|
||||
private int mp;
|
||||
private int maxMp;
|
||||
private String name;
|
||||
|
||||
public Enemy(int hp, int mp, Weapon weapon) {
|
||||
|
||||
public Enemy(String name, int hp, int mp, Weapon weapon) {
|
||||
this.name = name;
|
||||
this.hp = hp;
|
||||
this.maxHp = hp;
|
||||
this.mp = mp;
|
||||
|
||||
this.maxMp = mp;
|
||||
this.weapon = weapon;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
public void takeDamage(int damage)
|
||||
{
|
||||
hp -= damage;
|
||||
if (hp < 0)
|
||||
hp = 0;
|
||||
System.out.println("HP: " + hp + "/" + maxHp);
|
||||
}
|
||||
|
||||
public int getHp() {
|
||||
public int getHP() {
|
||||
return hp;
|
||||
}
|
||||
|
||||
public int getMp() {
|
||||
public int getMaxHP() {return maxHp;}
|
||||
|
||||
public int getMP() {
|
||||
return mp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillMana(int mana)
|
||||
{
|
||||
this.mp += mana;
|
||||
if (mp > maxMp)
|
||||
mp = maxMp;
|
||||
System.out.println( name + " restored " + mana + " MP (" + mp + "/" + maxMp + ")");
|
||||
}
|
||||
|
||||
public Weapon getWeapon() {
|
||||
return weapon;
|
||||
}
|
||||
|
||||
public void setWeapon(Weapon weapon) { this.weapon = weapon; }
|
||||
|
||||
@Override
|
||||
public void defend()
|
||||
{
|
||||
System.out.println(name+" defends!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal(int health)
|
||||
{
|
||||
hp += health;
|
||||
if(hp > maxHp)
|
||||
hp = maxHp;
|
||||
System.out.println(name + " add " + health + " hp (" + hp + "/" + maxHp +")");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {return name;}
|
||||
|
||||
@Override
|
||||
public boolean isAlive(){ return hp > 0;}
|
||||
|
||||
public void setHp(int hp)
|
||||
{
|
||||
this.hp = Math.max(0,Math.min(hp,maxHp));
|
||||
}
|
||||
|
||||
public abstract int getXpReward();
|
||||
public abstract String getEnemyType();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
public class Goblin extends Enemy
|
||||
{
|
||||
|
||||
public Goblin()
|
||||
{
|
||||
super("Goblin", 30, 20, null);
|
||||
}
|
||||
|
||||
public Goblin(Weapon weapon)
|
||||
{
|
||||
super("Goblin", 30, 20, weapon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getXpReward() {
|
||||
return 50;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEnemyType() {
|
||||
return "GOBLIN";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(Entity target)
|
||||
{
|
||||
boolean isCritical = Math.random() < 0.3;
|
||||
int damage = isCritical ? 25 : 12;
|
||||
System.out.print(getName() + " attacks");
|
||||
if (isCritical) {
|
||||
System.out.print(" with CRITICAL hit!");
|
||||
}
|
||||
System.out.println(" for " + damage + " damage!");
|
||||
|
||||
target.takeDamage(damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxMP() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,52 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Skeleton {
|
||||
public class Skeleton extends Enemy {
|
||||
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR
|
||||
private boolean hasRevived = false;
|
||||
|
||||
public Skeleton() {
|
||||
super("Skeleton", 40, 15, null);
|
||||
}
|
||||
|
||||
public Skeleton(Weapon weapon) {
|
||||
super("Skeleton", 40, 15, weapon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(Entity target) {
|
||||
int damage = 15;
|
||||
System.out.println(getName() + " shoots an arrow for " + damage + " damage!");
|
||||
target.takeDamage(damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
super.takeDamage(damage);
|
||||
|
||||
if (!isAlive() && !hasRevived) {
|
||||
hasRevived = true;
|
||||
int revivedHp = getMaxHP() / 2;
|
||||
setHp(revivedHp);
|
||||
System.out.println(getName() + " rises again with " + revivedHp + " HP");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxMP() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getXpReward() {
|
||||
return 70;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEnemyType() {
|
||||
return "SKELETON";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
public class Vampire extends Enemy
|
||||
{
|
||||
|
||||
public Vampire()
|
||||
{
|
||||
super("Vampire", 50, 25, null);
|
||||
}
|
||||
|
||||
public Vampire(Weapon weapon)
|
||||
{
|
||||
super("Vampire", 50, 25, weapon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(Entity target)
|
||||
{
|
||||
int damage = 18;
|
||||
int lifestealAmount = damage / 2;
|
||||
System.out.println(getName() + " bites for " + damage + " damage!");
|
||||
target.takeDamage(damage);
|
||||
int newHp = getHP() + lifestealAmount;
|
||||
setHp(newHp);
|
||||
System.out.println("HP: " + getHP() + "/" + getMaxHP());
|
||||
}
|
||||
@Override
|
||||
public int getXpReward() {
|
||||
return 80;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEnemyType() {
|
||||
return "VAMPIRE";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxMP() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
public class Assassin extends Player
|
||||
{
|
||||
private boolean isInvisible = false;
|
||||
private boolean nextAttackCritical = false;
|
||||
|
||||
public Assassin(String name) {
|
||||
super(name, 70, 100, null, null, "Assassin", 0, 70, 100);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lightAttack(Entity target)
|
||||
{
|
||||
int damage = 15;
|
||||
if (nextAttackCritical)
|
||||
{
|
||||
damage *= 2;
|
||||
System.out.println("CRITICAL HIT! ");
|
||||
nextAttackCritical = false;
|
||||
}
|
||||
System.out.println(name + " (Assassin) used Light Attack! (0 MP)");
|
||||
target.takeDamage(damage);
|
||||
System.out.println(name + " MP: " + getMP() + "/" + getMaxMP());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void specialAbility(Entity target)
|
||||
{
|
||||
if (getMP() >= 15)
|
||||
{
|
||||
fillMana(-15);
|
||||
isInvisible = true;
|
||||
nextAttackCritical = true;
|
||||
System.out.println(name + " turns INVISIBLE! (-15 MP)");
|
||||
System.out.println("Next attack will be a guaranteed CRITICAL HIT!");
|
||||
System.out.println("Will dodge the next incoming attack completely!");
|
||||
}
|
||||
else
|
||||
System.out.println("Not enough MP for Special Ability!");
|
||||
|
||||
System.out.println("MP: " + getMP() + "/" + getMaxMP());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heavyAttack(Entity target)
|
||||
{
|
||||
if (getMP() >= 10)
|
||||
{
|
||||
fillMana(-10);
|
||||
int damage = 28;
|
||||
if (nextAttackCritical)
|
||||
{
|
||||
damage *= 2;
|
||||
System.out.println("CRITICAL HIT! ");
|
||||
nextAttackCritical = false;
|
||||
}
|
||||
System.out.println(name + " used Heavy Attack! (-10 MP)");
|
||||
target.takeDamage(damage);
|
||||
}
|
||||
else
|
||||
System.out.println("Not enough MP!");
|
||||
|
||||
System.out.println("MP: " + getMP() + "/" + getMaxMP());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defend() {
|
||||
if (getMP() >= 6) {
|
||||
fillMana(-6);
|
||||
super.defend();
|
||||
System.out.println("Defensive stance! (-6 MP)");
|
||||
} else {
|
||||
System.out.println("Not enough MP!");
|
||||
}
|
||||
System.out.println("MP: " + getMP() + "/" + getMaxMP());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal(int health) {
|
||||
if (getMP() >= 12) {
|
||||
fillMana(-12);
|
||||
super.heal(health);
|
||||
System.out.println("Healed! (-12 MP)");
|
||||
} else {
|
||||
System.out.println("Not enough MP!");
|
||||
}
|
||||
System.out.println("MP: " + getMP() + "/" + getMaxMP());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,60 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.Sword;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Knight {
|
||||
public class Knight extends Player {
|
||||
// TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR
|
||||
public Knight(String name) {
|
||||
super(name, 80, 50, null, null, "Knight",
|
||||
0, 80, 50);
|
||||
|
||||
}
|
||||
|
||||
public void lightAttack(Entity target) {
|
||||
int damage = 20;
|
||||
System.out.println(name + " (Knight) used Light Attack! (0 MP)");
|
||||
target.takeDamage(damage);
|
||||
System.out.println(name + " MP: " + getMP() + "/" + getMaxMP());
|
||||
}
|
||||
|
||||
public void heavyAttack(Entity target) {
|
||||
if (getMP() >= 8) {
|
||||
fillMana(-8);
|
||||
int damage = 35;
|
||||
System.out.println(name + " (Knight) used Heavy Attack! (-8 MP)");
|
||||
target.takeDamage(damage);
|
||||
}
|
||||
else {
|
||||
System.out.println("Not enough MP for Heavy Attack! (Need 8, have " + getMP() + ")");
|
||||
}
|
||||
System.out.println(name + " MP: " + getMP() + "/" + getMaxMP());
|
||||
}
|
||||
@Override
|
||||
public void heal(int health) {
|
||||
if (getMP() >= 12) {
|
||||
fillMana(-12);
|
||||
super.heal(health);
|
||||
System.out.println(name + " used Heal! (-12 MP)");
|
||||
} else {
|
||||
System.out.println("Not enough MP to heal! (Need 12, have " + getMP() + ")");
|
||||
}
|
||||
System.out.println(name + " MP: " + getMP() + "/" + getMaxMP());
|
||||
}
|
||||
|
||||
public void specialAbility(Entity target) {
|
||||
if (getMP() >= 15) {
|
||||
fillMana(-15);
|
||||
int damage = 40;
|
||||
System.out.println(name + " (Knight) used SHIELD BASH! (-15 MP)");
|
||||
System.out.println("The enemy is STUNNED and loses their next turn!");
|
||||
target.takeDamage(damage);
|
||||
}
|
||||
else
|
||||
System.out.println("Not enough MP for Shield Bash! (Need 15, have " + getMP() + ")");
|
||||
System.out.println(name + " MP: " + getMP() + "/" + getMaxMP());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,22 +5,45 @@ import org.project.item.armors.Armor;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Player {
|
||||
public abstract class Player implements Entity {
|
||||
protected String name;
|
||||
Weapon weapon;
|
||||
private Weapon weapon;
|
||||
Armor armor;
|
||||
private int hp;
|
||||
private int maxHP;
|
||||
private int mp;
|
||||
private int maxMP;
|
||||
private int level;
|
||||
private boolean isAlive;
|
||||
private String playerClass;
|
||||
private int XP;
|
||||
private int XPNeedToNextLevel;
|
||||
private int baseDamage;
|
||||
private int specialDamage;
|
||||
private boolean hasGoblinKey;
|
||||
private boolean hasSkeletonkey;
|
||||
private boolean hasVampireKey;
|
||||
private boolean isDefending;
|
||||
|
||||
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
|
||||
public Player(String name, int hp, int mp, Weapon weapon, Armor armor, String playerClass, int XP,
|
||||
int maxHP, int maxMP) {
|
||||
this.name = name;
|
||||
this.hp = hp;
|
||||
this.mp = mp;
|
||||
|
||||
this.weapon = weapon;
|
||||
this.armor = armor;
|
||||
this.playerClass = playerClass;
|
||||
this.XP = XP;
|
||||
this.maxHP = maxHP;
|
||||
this.maxMP = maxMP;
|
||||
this.level = 1;
|
||||
this.XPNeedToNextLevel = 100;
|
||||
this.isAlive = true ;
|
||||
this.baseDamage = weapon !=null ? weapon.getDamage() : 10;
|
||||
this.hasGoblinKey = false;
|
||||
this.hasSkeletonkey = false;
|
||||
this.hasVampireKey = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -29,14 +52,35 @@ public abstract class Player {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defend() {
|
||||
public void defend()
|
||||
{
|
||||
// TODO
|
||||
this.isDefending = true ;
|
||||
System.out.println(name + " is defending ");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
hp -= damage - armor.getDefense();
|
||||
if (isDefending)
|
||||
{
|
||||
damage /= 2;
|
||||
isDefending = false;
|
||||
System.out.println("Defense halved the damage to " + damage + "!");
|
||||
}
|
||||
if (armor != null)
|
||||
{
|
||||
int finalDamage = damage - armor.getDefense();
|
||||
if (finalDamage >= 0)
|
||||
hp -= finalDamage;
|
||||
}
|
||||
else
|
||||
hp -= damage;
|
||||
if (hp <= 0)
|
||||
{
|
||||
isAlive = false;
|
||||
hp = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,7 +104,7 @@ public abstract class Player {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getHp() {
|
||||
public int getHP() {
|
||||
return hp;
|
||||
}
|
||||
|
||||
@@ -69,7 +113,7 @@ public abstract class Player {
|
||||
return maxHP;
|
||||
}
|
||||
|
||||
public int getMp() {
|
||||
public int getMP() {
|
||||
return mp;
|
||||
}
|
||||
|
||||
@@ -82,8 +126,85 @@ public abstract class Player {
|
||||
return weapon;
|
||||
}
|
||||
|
||||
public void setWeapon(Weapon weapon)
|
||||
{
|
||||
this.weapon = weapon;
|
||||
}
|
||||
|
||||
public Armor getArmor() {
|
||||
return armor;
|
||||
}
|
||||
|
||||
public void setArmor(Armor armor)
|
||||
{
|
||||
this.armor = armor;
|
||||
}
|
||||
|
||||
public int level()
|
||||
{
|
||||
return level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlive()
|
||||
{
|
||||
return isAlive;
|
||||
}
|
||||
|
||||
public abstract void lightAttack(Entity target);
|
||||
public abstract void specialAbility(Entity target);
|
||||
public abstract void heavyAttack(Entity target);
|
||||
|
||||
public String getPlayerClass()
|
||||
{
|
||||
return playerClass;
|
||||
}
|
||||
public void gainXp(int amount) {
|
||||
this.XP += amount;
|
||||
System.out.println(amount + " XP! (Total: " + XP + "/" + XPNeedToNextLevel + ")");
|
||||
|
||||
while (XP >= XPNeedToNextLevel) {
|
||||
XP -= XPNeedToNextLevel;
|
||||
level++;
|
||||
int oldMaxHP = maxHP;
|
||||
int oldMaxMP = maxMP;
|
||||
maxHP += 15;
|
||||
maxMP += 10;
|
||||
hp = maxHP;
|
||||
mp = maxMP;
|
||||
XPNeedToNextLevel = level * 100;
|
||||
|
||||
System.out.println(" LEVEL UP! Now level " + level + "! 🎉");
|
||||
System.out.println(" HP: " + oldMaxHP + " → " + maxHP);
|
||||
System.out.println(" MP: " + oldMaxMP + " → " + maxMP);
|
||||
}
|
||||
}
|
||||
|
||||
public void restoreAfterBattle() {
|
||||
hp = maxHP;
|
||||
mp = maxMP;
|
||||
System.out.println(name + " fully restored!");
|
||||
System.out.println(" HP: " + hp + "/" + maxHP + " | MP: " + mp + "/" + maxMP);
|
||||
}
|
||||
|
||||
public boolean hasGoblinKey() { return hasGoblinKey; }
|
||||
public boolean hasSkeletonKey() { return hasSkeletonkey; }
|
||||
public boolean hasVampireKey() { return hasVampireKey; }
|
||||
|
||||
public void addGoblinKey() { hasGoblinKey = true; }
|
||||
public void addSkeletonKey() { hasSkeletonkey = true; }
|
||||
public void addVampireKey() { hasVampireKey = true; }
|
||||
|
||||
public boolean hasAllKeys() {
|
||||
return hasGoblinKey && hasSkeletonkey && hasVampireKey;
|
||||
}
|
||||
|
||||
public int getXP() {
|
||||
return XP;
|
||||
}
|
||||
|
||||
public int getXPNeedToNextLevel() {
|
||||
return XPNeedToNextLevel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.Weapon;
|
||||
import org.project.item.armors.Armor;
|
||||
|
||||
public class Wizard extends Player
|
||||
{
|
||||
public Wizard(String name)
|
||||
{
|
||||
super(name, 90, 70, null, null, "Wizard", 0, 90, 70);
|
||||
}
|
||||
|
||||
public Wizard(String name, Weapon weapon, Armor armor)
|
||||
{
|
||||
super(name, 90, 70, weapon, armor, "WIZARD", 0, 90, 70);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lightAttack(Entity target)
|
||||
{
|
||||
int damage = 18;
|
||||
System.out.println(name + " (Wizard) used Light Attack! (0 MP)");
|
||||
target.takeDamage(damage);
|
||||
System.out.println(name + " MP: " + getMP() + "/" + getMaxMP());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void specialAbility(Entity target)
|
||||
{
|
||||
if (getMP() >= 18) {
|
||||
fillMana(-18);
|
||||
target.takeDamage(35);
|
||||
super.heal(20);
|
||||
System.out.println("ARCANE NOVA! 35 damage + 20 heal (-18 MP)");
|
||||
} else {
|
||||
System.out.println("Not enough MP for Special Ability!");
|
||||
}
|
||||
System.out.println("MP: " + getMP() + "/" + getMaxMP());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heavyAttack(Entity target)
|
||||
{
|
||||
if (getMP() >= 10)
|
||||
{
|
||||
fillMana(-10);
|
||||
System.out.println(name + " used Heavy Attack! (-10 MP)");
|
||||
target.takeDamage(30);
|
||||
}
|
||||
else
|
||||
System.out.println("Not enough MP!");
|
||||
|
||||
System.out.println("MP: " + getMP() + "/" + getMaxMP());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defend()
|
||||
{
|
||||
if (getMP() >= 6)
|
||||
{
|
||||
fillMana(-6);
|
||||
super.defend();
|
||||
System.out.println("Defensive stance! (-6 MP)");
|
||||
}
|
||||
else
|
||||
System.out.println("Not enough MP!");
|
||||
|
||||
System.out.println("MP: " + getMP() + "/" + getMaxMP());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal(int health)
|
||||
{
|
||||
if (getMP() >= 12)
|
||||
{
|
||||
fillMana(-12);
|
||||
super.heal(health);
|
||||
System.out.println("Healed! (-12 MP)");
|
||||
}
|
||||
else
|
||||
System.out.println("Not enough MP!");
|
||||
|
||||
System.out.println("MP: " + getMP() + "/" + getMaxMP());
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,9 @@ public abstract class Armor {
|
||||
public Armor(int defense, int durability) {
|
||||
this.defense = defense;
|
||||
this.durability = durability;
|
||||
this.maxDefense = defense;
|
||||
this.maxDurability = durability;
|
||||
this.isBroke = false;
|
||||
}
|
||||
|
||||
public void checkBreak() {
|
||||
@@ -36,6 +39,8 @@ public abstract class Armor {
|
||||
return durability;
|
||||
}
|
||||
|
||||
public int getMaxDurability() { return maxDurability; }
|
||||
|
||||
public boolean isBroke() {
|
||||
return isBroke;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
package org.project.item.armors;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class KnightArmor {
|
||||
public class KnightArmor extends Armor
|
||||
{
|
||||
public KnightArmor()
|
||||
{
|
||||
super(15, 50);
|
||||
}
|
||||
public KnightArmor(int defense, int durability)
|
||||
{
|
||||
super(defense, durability);
|
||||
}
|
||||
// TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
|
||||
}
|
||||
@@ -1,8 +1,30 @@
|
||||
package org.project.item.consumables;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Consumable {
|
||||
public abstract class Consumable
|
||||
{
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||
*/
|
||||
protected String name;
|
||||
protected int value;
|
||||
|
||||
public Consumable(String name, int value)
|
||||
{
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
public abstract void use(Entity target);
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,14 +3,20 @@ package org.project.item.consumables;
|
||||
import org.project.entity.Entity;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Flask {
|
||||
public class Flask extends Consumable
|
||||
{
|
||||
public Flask(String name, int value) {
|
||||
super("Flask", 0);
|
||||
}
|
||||
/*
|
||||
THIS IS AN EXAMPLE OF A CONSUMABLE DESIGN.
|
||||
*/
|
||||
|
||||
// TODO: UPDATE USE METHOD
|
||||
@Override
|
||||
public void use(Entity target) {
|
||||
public void use(Entity target)
|
||||
{
|
||||
target.heal(target.getMaxHP() / 10);
|
||||
System.out.println("Used Flask! Healed " + target.getMaxHP() /10 + " HP.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,22 +5,36 @@ import org.project.entity.Entity;
|
||||
import java.util.ArrayList;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Sword {
|
||||
public class Sword extends Weapon {
|
||||
/*
|
||||
THIS IS AN EXAMPLE OF A WEAPON DESIGN.
|
||||
*/
|
||||
|
||||
int abilityCharge;
|
||||
private int abilityCharge;
|
||||
|
||||
public Sword() {
|
||||
// TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
|
||||
super(15,5);
|
||||
this.abilityCharge = 0;
|
||||
}
|
||||
|
||||
public Sword(int damage, int manaCost)
|
||||
{
|
||||
super(damage, manaCost);
|
||||
this.abilityCharge = 0;
|
||||
}
|
||||
|
||||
// TODO: (BONUS) UPDATE THE UNIQUE ABILITY
|
||||
public void uniqueAbility(ArrayList<Entity> targets) {
|
||||
abilityCharge += 2;
|
||||
for (Entity target : targets) {
|
||||
target.takeDamage(getDamage());
|
||||
target.takeDamage(getDamage() + abilityCharge);
|
||||
}
|
||||
System.out.println("Sword's unique ability! Damage: " + (getDamage() + abilityCharge));
|
||||
}
|
||||
|
||||
public int getAbilityCharge()
|
||||
{
|
||||
return abilityCharge;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.project.item.weapons;
|
||||
import org.project.entity.Entity;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Weapon {
|
||||
public class Weapon {
|
||||
private int damage;
|
||||
private int manaCost;
|
||||
|
||||
@@ -16,7 +16,7 @@ public abstract class Weapon {
|
||||
this.manaCost = manaCost;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public void use(Entity target) {
|
||||
target.takeDamage(damage);
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ import java.util.ArrayList;
|
||||
|
||||
public class Location {
|
||||
private String name;
|
||||
|
||||
private ArrayList<Enemy> enemies;
|
||||
private ArrayList<Location> locations;
|
||||
|
||||
public Location(ArrayList<Location> locations, ArrayList<Enemy> enemies) {
|
||||
this.locations = locations;
|
||||
|
||||
Reference in New Issue
Block a user