diff --git a/Java-Ring/.idea/misc.xml b/Java-Ring/.idea/misc.xml
index f16dea7..bb275c3 100644
--- a/Java-Ring/.idea/misc.xml
+++ b/Java-Ring/.idea/misc.xml
@@ -4,7 +4,7 @@
-
+
\ No newline at end of file
diff --git a/Java-Ring/src/main/java/org/project/Main.java b/Java-Ring/src/main/java/org/project/Main.java
index c2e0550..a58e956 100644
--- a/Java-Ring/src/main/java/org/project/Main.java
+++ b/Java-Ring/src/main/java/org/project/Main.java
@@ -1,15 +1,471 @@
package org.project;
+import org.project.entity.enemies.Dragon;
+import org.project.entity.enemies.Enemy;
+import org.project.entity.enemies.Goblin;
+import org.project.entity.enemies.Skeleton;
+import org.project.entity.players.Assassin;
+import org.project.entity.players.Knight;
+import org.project.entity.players.Player;
+import org.project.entity.players.Wizard;
import org.project.location.Location;
+import org.project.object.armors.KnightArmor;
+import org.project.object.armors.Nothing;
+import org.project.object.consumables.Flask;
+import org.project.object.weapons.Punch;
+import org.project.object.weapons.Sword;
import java.util.ArrayList;
import java.util.List;
+import java.util.Scanner;
public class Main {
public static void main(String[] args) {
- // TODO: ADD SOME LOCATIONS TO YOUR GAME
- List locations = new ArrayList<>();
+ List locations = levelConstructor();
+ Scanner scanner = new Scanner(System.in);
- // TODO: IMPLEMENT GAMEPLAY
+ // Character Creation
+ Player player = null;
+ do {
+ System.out.println("\n========================================");
+ System.out.println(" CREATE YOUR HERO ");
+ System.out.println("========================================");
+ System.out.println("1. Wizard - Master of arcane magic");
+ System.out.println("2. Assassin - Deadly and precise");
+ System.out.println("3. Knight - Strong and resilient");
+ System.out.println("========================================");
+ System.out.print("Choose your class (1-3): ");
+ int classNumber = scanner.nextInt();
+
+ System.out.print("Enter your hero's name: ");
+ String name = scanner.next();
+
+ switch (classNumber) {
+ case 1:
+ player = new Wizard(name, new Punch(Wizard.BaseAttack), new Nothing());
+ System.out.println("\n>> " + name + " the Wizard enters the fray!");
+ break;
+ case 2:
+ player = new Assassin(name, new Punch(Assassin.BaseAttack), new Nothing());
+ System.out.println("\n>> " + name + " the Assassin emerges from the shadows!");
+ break;
+ case 3:
+ player = new Knight(name, new Punch(Knight.BaseAttack), new Nothing());
+ System.out.println("\n>> " + name + " the Knight charges into battle!");
+ break;
+ default:
+ System.out.println("Invalid class selection. Please choose agian");
+ }
+ }while(player==null);
+
+
+ //start playing
+ boolean playing = true;
+ while(playing) {
+
+ //choosing a location
+ showLocations(locations);
+ System.out.print("\nChoose your destination (0 to quit): ");
+ int locationIndex = scanner.nextInt() - 2;
+
+ if (locationIndex == -2) {
+ System.out.println("\n>> Farewell, adventurer!");
+ break;
+ }
+
+ enterLocation(locations, locationIndex,player);
+
+ //if we entered the shop go back to location selecting menu
+ if(locationIndex == -1)
+ continue;
+
+
+ //location loop
+ Location currentLocation = locations.get(locationIndex);
+ int round=0;
+ boolean inLocation = true;
+ while(inLocation) {
+
+ //Round Header
+ System.out.println("\n========================================");
+ System.out.printf(" ROUND %-3d - %-15s%n", ++round, currentLocation.getName());
+ System.out.println("========================================");
+ System.out.println(player.getStatus());
+
+ //Player's turn
+ player.reset();
+ displayCombatOptions();
+ int option = scanner.nextInt();
+ switch(option) {
+ case 1://Attack
+ enemyList(locations, locationIndex);
+ System.out.print("\nChoose your target: ");
+ Enemy enemy = currentLocation.getEnemies().get(scanner.nextInt() - 1);
+ player.attack(enemy);
+ System.out.printf("\n>> You strike the %s for %d damage!%n",
+ enemy.getClass().getSimpleName(),
+ player.getWeapon().getDamage());
+
+ if (enemy.isDead()) {
+ int gainedExp = enemy.getLevel() * (enemy.getMaxHP() / 5);
+ int gainedCoins = enemy.getLevel() * (enemy.getMaxHP() / 5);
+ System.out.printf(">> You defeated the %s! Gained %d XP and %d coins.%n",
+ enemy.getClass().getSimpleName(), gainedExp, gainedCoins);
+ player.collectExp(gainedExp);
+ player.setCoin(player.getCoin() + gainedCoins);
+
+ if (!(enemy instanceof Skeleton) || enemy.isResurrected()) {
+ currentLocation.getEnemies().remove(enemy);
+ }
+ }
+ break;
+
+ case 2:// Heal
+ int healAmount = player.getMaxHP() / 8;
+ player.heal(healAmount);
+ System.out.printf("\n>> You healed yourself for %d HP!%n", healAmount);
+ break;
+ case 3:// Defense
+ player.DefendStatusChange();
+ System.out.printf("\n>> You are now %sdefending.%n",
+ player.isDefending() ? "" : "not ");
+ break;
+ case 4:// Special Ability
+ enemyList(locations, locationIndex);
+ System.out.print("\nChoose your target: ");
+ enemy = currentLocation.getEnemies().get(scanner.nextInt() - 1);
+ player.Special(enemy);
+ System.out.printf("\n>> You use your special ability on the %s!%n",
+ enemy.getClass().getSimpleName());
+
+ if (enemy.isDead()) {
+ int gainedExp = enemy.getLevel() * (enemy.getMaxHP() / 5);
+ int gainedCoins = enemy.getLevel() * (enemy.getMaxHP() / 5);
+ System.out.printf(">> You defeated the %s! Gained %d XP and %d coins.%n",
+ enemy, gainedExp, gainedCoins);
+ player.collectExp(gainedExp);
+ player.setCoin(player.getCoin() + gainedCoins);
+
+ if (!(enemy instanceof Skeleton) || enemy.isResurrected()) {
+ currentLocation.getEnemies().remove(enemy);
+ }
+ }
+ case 5:
+ // Fill Mana
+ int manaGain = player.getMaxMp() / 5;
+ player.setMp(player.getMp() + manaGain);
+ System.out.printf("\n>> You focus and restore %d MP!%n", manaGain);
+ break;
+ case 6:// Leave Location
+ System.out.println("\n>> You prepare to retreat at the start of next round...");
+ inLocation = false;
+ break;
+ default:
+ System.out.println("\n>> Invalid option! You hesitate...");
+ }
+
+ // Check if location is cleared
+ if (locationClearedCheck(currentLocation)) {
+ inLocation = false;
+ locations.remove(currentLocation);
+ break;
+ }
+
+ //Enemies' turn
+ for(Enemy enemy : currentLocation.getEnemies()) {
+ //Skeleton Resurrection check
+ if (enemy.isDead() && enemy instanceof Skeleton) {
+ enemy.Special(player);
+ System.out.printf("\n>> The %s's bones rattle as it reforms!%n",
+ enemy.getClass().getSimpleName());
+ continue;
+ }
+
+
+ enemy.reset();
+ int random = (int) (Math.random() * 100) % 20;
+ if (random <= 9) {// Attack
+
+ //Dragon Special
+ if(enemy instanceof Dragon && player.isDefending())
+ {
+ enemy.Special(player);
+ System.out.printf("\n>> The %s Pierced through your guard!%n", enemy);
+
+
+ }else {
+ System.out.printf("\n>> The %s attacks you!%n", enemy);
+ enemy.attack(player);
+ }
+ if (player.isDead()) {
+ System.out.println("\n>> Your vision fades to black...");
+ inLocation = false;
+ playing = false;
+ break;
+ }
+ } else if (random <= 14) { // Defend
+ System.out.printf("\n>> The %s raises its guard!%n", enemy);
+ enemy.DefendStatusChange();
+ } else if (random <= 19 ) { // Heal
+ int healAmount = enemy.getMaxHP() / 10;
+ System.out.printf("\n>> The %s heals itself for %d HP!%n",
+ enemy.getClass().getSimpleName(), healAmount);
+ enemy.heal(healAmount);
+ }
+ }
+ }
+ }
+
+ //Death Message
+ if (!playing) {
+ System.out.println("\n========================================");
+ System.out.println(" GAME OVER ");
+ System.out.println("========================================");
+ System.out.println("Your hero " + player.getName() + " has fallen in battle.");
+ System.out.println("Final stats:");
+ System.out.println(player.getStatus());
+ System.out.println("========================================");
+ }
+ }
+
+
+ private static void displayCombatOptions() {
+ System.out.println("\nCOMBAT OPTIONS:");
+ System.out.println("1. Basic Attack");
+ System.out.println("2. Heal (12.5% of max HP)");
+ System.out.println("3. Toggle Defense");
+ System.out.println("4. Special Ability");
+ System.out.println("5. Focus (Restore 33% MP)");
+ System.out.println("6. Retreat");
+ System.out.print("Choose your action: ");
+ }
+
+ private static ArrayList levelConstructor() {
+
+ //list of all levels and its enemies
+
+ ArrayList locations = new ArrayList<>();
+ ArrayList enemies;
+ Location location;
+ //level 1
+ enemies = addEnemy(1,1,0,0,0,0);
+ location = new Location(enemies,"Jungle 1");
+ locations.add(location);
+ //level 2
+ enemies = addEnemy(1,2,1,1,0,0);
+ location = new Location(enemies,"Jungle 2");
+ locations.add(location);
+ //level 3
+ enemies = addEnemy(3,1,1,1,0,0);
+ location = new Location(enemies,"Jungle 3");
+ locations.add(location);
+ //level 4
+ enemies = addEnemy(0,0,2,2,0,0);
+ location = new Location(enemies,"Jungle 4");
+ locations.add(location);
+ //level 5
+ enemies = addEnemy(2,1,0 ,0, 1,1);
+ location = new Location(enemies,"Jungle 5");
+ locations.add(location);
+ //level 6
+ enemies = addEnemy(3,1,1,2,0,0);
+ location = new Location(enemies,"Desert 1");
+ locations.add(location);
+ //level 7
+ enemies = addEnemy(3,2,2,1,0,0);
+ location = new Location(enemies,"Desert 2");
+ locations.add(location);
+ //level 8
+ enemies = addEnemy(2,3,1,2,0,0);
+ location = new Location(enemies,"Desert 3");
+ locations.add(location);
+ //level 9
+ enemies = addEnemy(0,0,3,2,0,0);
+ location = new Location(enemies,"Desert 4");
+ locations.add(location);
+ //level 10
+ enemies = addEnemy(0,0,2,2,1,2);
+ location = new Location(enemies,"Desert 5");
+ locations.add(location);
+ //level 11
+ enemies = addEnemy(0,0,4,2,0,0);
+ location = new Location(enemies,"Mountain 1");
+ locations.add(location);
+ //level 12
+ enemies = addEnemy(8,2,0,0,0,0);
+ location = new Location(enemies,"Mountain 2");
+ locations.add(location);
+ //level 13
+ enemies = addEnemy(3,3,2,2,0,0);
+ location = new Location(enemies,"Mountain 3");
+ locations.add(location);
+ //level 14
+ enemies = addEnemy(1,5,3,3,0,0);
+ location = new Location(enemies,"Mountain 4");
+ locations.add(location);
+ //level 15
+ enemies = addEnemy(3,3,1,2,1,3);
+ location = new Location(enemies,"Mountain 5");
+ locations.add(location);
+ //level 16
+ enemies = addEnemy(4,4,2,3,0,0);
+ location = new Location(enemies,"Island 1");
+ locations.add(location);
+ //level 17
+ enemies = addEnemy(2,2,3,4,0,0);
+ location = new Location(enemies,"Island 2");
+ locations.add(location);
+ //level 18
+ enemies = addEnemy(3,3,1,6,0,0);
+ location = new Location(enemies,"Island 3");
+ locations.add(location);
+ //level 19
+ enemies = addEnemy(1,10,3,4,0,0);
+ location = new Location(enemies,"Island 4");
+ locations.add(location);
+ //level 20
+ enemies = addEnemy(2,6,2,4,1,5);
+ location = new Location(enemies,"Island 5");
+ locations.add(location);
+
+
+
+
+ return locations;
+ }
+
+ private static ArrayList addEnemy(int numS,int lvlS,int numG,int lvlG,int numD,int lvlD) {
+
+ //creating an enemy list
+ ArrayList enemies = new ArrayList<>();
+ for(int i=1; i<=numS; i++)
+ enemies.add(new Skeleton(lvlS,new Punch(Skeleton.BaseAttack)));
+ for(int i=1; i<=numG; i++)
+ enemies.add(new Goblin(lvlG,new Punch(Goblin.BaseAttack)));
+ for(int i=1; i<=numD; i++)
+ enemies.add(new Dragon(lvlD,new Punch(Dragon.BaseAttack)));
+ return enemies;
+ }
+
+
+ private static boolean locationClearedCheck(Location currentLocation) {
+
+ //it checks whether a location is cleared or not
+ if(currentLocation.getEnemies().isEmpty())
+ {
+ System.out.println("\nYou have cleared this location!");
+ return true;
+ }
+ return false;
+ }
+
+ public static void showLocations(List locations) {
+ //shows the list of locations
+ System.out.println("\n=== Available Locations ===");
+ System.out.println("1. Shop");
+ for (int i = 0; i < locations.size(); i++) {
+ System.out.println((i + 2) + ". " + locations.get(i).getName() +
+ " (" + locations.get(i).getEnemies().size() + " enemies)");
+ }
+ }
+
+ public static void enterLocation(List locations,int locationIndex,Player player) {
+ //enter a location or shop message
+ if (locationIndex == -1) {
+ enterShop(player);
+ } else {
+ System.out.println("\nYou enter " + locations.get(locationIndex).getName());
+ enemyList(locations, locationIndex);
+ }
+ }
+
+ private static void enterShop(Player player) {
+
+ //shop of the game
+ //exchanging coins for goods
+ Scanner input = new Scanner(System.in);
+ System.out.println("\n=== Welcome to the Shop ===");
+ System.out.println(player.getStatus());
+ System.out.println("\nAvailable items:");
+ System.out.println("1. Health Flask (25 coins) - Restores 25% HP");
+ System.out.println("2. Armor Services");
+ System.out.println(" - New Armor: 150 coins");
+ System.out.println(" - Repair: 75 coins");
+ System.out.println("3. Sword Upgrade");
+ System.out.println(" - New Sword: 85 coins");
+ System.out.println(" - Upgrade: 85 coins (+10% damage)");
+ System.out.println("4. Exit Shop");
+ System.out.print("Choose an option: ");
+ int select = input.nextInt();
+ switch(select)
+ {
+ case 1:
+ System.out.println("\nEach flask restores 25% of your max HP.");
+ if (player.getCoin() >= 25) {
+ player.setCoin(player.getCoin() - 25);
+ new Flask().use(player);
+ System.out.println("You drank a health flask!");
+ } else {
+ System.out.println("You don't have enough coins.");
+ }
+ break;
+ case 2:
+ if (player.getArmor() instanceof Nothing) {
+ System.out.println("\nA new armor costs 150 coins.");
+ if (player.getCoin() >= 150) {
+ player.setCoin(player.getCoin() - 150);
+ player.setArmor(new KnightArmor(player.getMaxHP() / 3));
+ System.out.println("You equipped new armor!");
+ } else {
+ System.out.println("You don't have enough coins.");
+ }
+ } else {
+ System.out.println("\nArmor repair costs 75 coins.");
+ if (player.getCoin() >= 75) {
+ player.setCoin(player.getCoin() - 75);
+ player.getArmor().repair();
+ System.out.println("Your armor has been repaired!");
+ } else {
+ System.out.println("You don't have enough coins.");
+ }
+ }
+ break;
+ case 3:
+ if (player.getWeapon() instanceof Punch) {
+ System.out.println("\nA new sword costs 85 coins.");
+ if (player.getCoin() >= 85) {
+ player.setCoin(player.getCoin() - 85);
+ player.setWeapon(new Sword(player.getWeapon().getDamage() * 3));
+ System.out.println("You equipped a new sword!");
+ } else {
+ System.out.println("You don't have enough coins.");
+ }
+ } else {
+ System.out.println("\nSword upgrade costs 85 coins.");
+ if (player.getCoin() >= 85) {
+ player.setCoin(player.getCoin() - 85);
+ player.getWeapon().levelUp();
+ System.out.printf("Your sword has been upgraded to lvl.%d" , player.getLevel());
+ } else {
+ System.out.println("You don't have enough coins.");
+ }
+ }
+ break;
+ case 4:
+ System.out.println("You leave the shop.");
+ break;
+ }
+ }
+
+ public static void enemyList(List locations,int locationIndex) {
+
+ //shows the list of all enemies
+ System.out.println("\nEnemies in this location:");
+ System.out.println("--------------------------");
+ int i = 1;
+ for (Enemy enemy : locations.get(locationIndex).getEnemies()) {
+ System.out.println(i++ + ". " + enemy.getStatus());
+ }
+ System.out.println("--------------------------");
}
}
\ No newline at end of file
diff --git a/Java-Ring/src/main/java/org/project/entity/Entity.java b/Java-Ring/src/main/java/org/project/entity/Entity.java
index 2a060f9..5050113 100644
--- a/Java-Ring/src/main/java/org/project/entity/Entity.java
+++ b/Java-Ring/src/main/java/org/project/entity/Entity.java
@@ -1,21 +1,29 @@
package org.project.entity;
+import org.project.object.weapons.Weapon;
+
public interface Entity {
- void attack(Entity target);
+ void reset();
- void defend();
+ void attack(Entity target);
void heal(int health);
- void fillMana(int mana);
+ void Special(Entity target);
void takeDamage(int damage);
+
+
+ //getters
+ Weapon getWeapon();
+ int getHP();
int getMaxHP();
+ int getLevel();
+ boolean isDefending();
+ boolean isDead();
- int getMaxMP();
+ //setters
+ void DefendStatusChange();
- /*
- TODO: ADD OTHER REQUIRED AND BONUS METHODS
- */
-}
+}
\ No newline at end of file
diff --git a/Java-Ring/src/main/java/org/project/entity/enemies/Enemy.java b/Java-Ring/src/main/java/org/project/entity/enemies/Enemy.java
index 1fcc491..f4b72c3 100644
--- a/Java-Ring/src/main/java/org/project/entity/enemies/Enemy.java
+++ b/Java-Ring/src/main/java/org/project/entity/enemies/Enemy.java
@@ -1,35 +1,97 @@
package org.project.entity.enemies;
+import org.project.entity.Entity;
import org.project.object.weapons.Weapon;
+import java.lang.Math;
-// TODO: UPDATE IMPLEMENTATION
-public abstract class Enemy {
+import static java.lang.Math.min;
+
+public abstract class Enemy implements Entity {
Weapon weapon;
+ private int lvl;
private int hp;
- private int mp;
-
- public Enemy(int hp, int mp, Weapon weapon) {
- this.hp = hp;
- this.mp = mp;
+ private final int MaxHP;
+ private boolean IsDefending=false;
+ protected boolean IsDead=false;
+ //constructor
+ public Enemy(int lvl,double hpMult, Weapon weapon) {
+ this.lvl=lvl;
+ this.hp = (int)(lvl*hpMult)*100;
+ this.MaxHP = this.hp;
this.weapon = weapon;
}
- // TODO: (BONUS) UPDATE THE FORMULA OF TAKING DAMAGE
+ //resets player's status each round
+ @Override
+ public void reset()
+ {
+ this.IsDefending=false;
+ }
+
+ //taking damage
@Override
public void takeDamage(int damage) {
- hp -= damage;
+ if(!IsDefending) {
+ hp -= damage;
+ }
+ else {
+ hp -= damage/(int)(Math.sqrt(lvl)*2);
+ }
+ if(this.hp <= 0) {
+ IsDead=true;
+ this.hp = 0;
+ }
}
- public int getHp() {
- return hp;
+ //attack
+ @Override
+ public void attack(Entity target) {
+ int damage = (int)((getWeapon().getDamage())*(Math.sqrt(getLevel())));
+ target.takeDamage(damage);
}
- public int getMp() {
- return mp;
+ //heal
+ @Override
+ public void heal(int health) {
+ hp = min(hp + health, MaxHP);
}
+
+ //getter methods
+ @Override
+ public boolean isDefending(){
+ return IsDefending;
+ }
+ @Override
+ public int getHP() {
+ return hp;
+ }
+ public int getLevel(){
+ return lvl;
+ }
+ public int getMaxHP() {
+ return MaxHP;
+ }
public Weapon getWeapon() {
return weapon;
}
-}
+ public boolean isDead() {
+ return IsDead;
+ }
+ public boolean isResurrected()
+ {
+ return false;
+ }
+ //getting enemy status
+ abstract public String getStatus();
+
+ //setter methods
+ public void setLevel(int lvl){
+ this.lvl=lvl;
+ }
+ public void DefendStatusChange() {
+ IsDefending = !IsDefending;
+ }
+
+}
\ No newline at end of file
diff --git a/Java-Ring/src/main/java/org/project/entity/enemies/Skeleton.java b/Java-Ring/src/main/java/org/project/entity/enemies/Skeleton.java
index 8c3e638..4ee5178 100644
--- a/Java-Ring/src/main/java/org/project/entity/enemies/Skeleton.java
+++ b/Java-Ring/src/main/java/org/project/entity/enemies/Skeleton.java
@@ -1,6 +1,55 @@
package org.project.entity.enemies;
-// TODO: UPDATE IMPLEMENTATION
-public class Skeleton {
- // TODO: DESIGN ENEMY'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR
-}
+import org.project.entity.Entity;
+import org.project.object.weapons.Weapon;
+
+import static java.lang.Math.min;
+
+public class Skeleton extends Enemy {
+
+ private boolean Resurrected = false;
+ public final static int BaseAttack = 25;
+ //constructor
+ public Skeleton(int lvl, Weapon weapon) {
+ super(lvl,1.25, weapon);
+ }
+ //Special Ability
+ @Override
+ public void Special(Entity target) {
+ if(super.IsDead && !Resurrected)
+ {
+ if(super.getLevel() == 1)
+ Resurrected = true;
+ else {
+ Resurrected = false;
+ super.setLevel(super.getLevel()/2);
+ }
+
+ super.IsDead = false;
+ this.heal(super.getMaxHP()/4);
+ }
+ }
+
+ //get status shows resurrected
+ @Override
+ public String getStatus() {
+ return "Skeleton" + " lvl." + getLevel()+ ": "
+ + "HP (" + getHP() + "/" + getMaxHP() + ") |"
+ + "Defending : " + "(" + isDefending() + ")" + " | Resurrected: " + Resurrected;
+ }
+ @Override
+ public String toString(){
+ return "Skeleton" + " lvl." + getLevel();
+ }
+
+
+
+
+ //getter for resurrected
+ @Override
+ public boolean isResurrected()
+ {
+ return this.Resurrected;
+ }
+
+}
\ No newline at end of file
diff --git a/Java-Ring/src/main/java/org/project/entity/players/Knight.java b/Java-Ring/src/main/java/org/project/entity/players/Knight.java
index 14d8fa2..bc14d62 100644
--- a/Java-Ring/src/main/java/org/project/entity/players/Knight.java
+++ b/Java-Ring/src/main/java/org/project/entity/players/Knight.java
@@ -1,6 +1,33 @@
package org.project.entity.players;
+import org.project.entity.Entity;
+import org.project.object.armors.Armor;
+import org.project.object.weapons.Weapon;
+
// TODO: UPDATE IMPLEMENTATION
-public class Knight {
- // TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR
-}
+public class Knight extends Player {
+ public static int BaseAttack = 90;
+
+ //constructor
+ public Knight(String name, Weapon weapon, Armor armor) {
+ super(name, 1000, 100, weapon, armor);
+ }
+ //uses mana for special ability
+ @Override
+ public void Special(Entity target) {
+ if(super.getMp() >= 50) {
+ super.setMp(super.getMp() - 50);
+ target.takeDamage(5*BaseAttack);
+ System.out.printf("%s uses Holy Strike on %s!%n", getName(), target.getClass().getSimpleName());
+ }
+ else {
+ System.out.println("Not enough mana to perform Holy Strike!");
+ }
+ }
+ //leveling up mechanism
+ @Override
+ public void levelUP(){
+ BaseAttack = BaseAttack + (int)(20*Math.sqrt(super.getLevel()+1));
+ super.levelUP();
+ }
+}
\ No newline at end of file
diff --git a/Java-Ring/src/main/java/org/project/entity/players/Player.java b/Java-Ring/src/main/java/org/project/entity/players/Player.java
index 674905a..f1c2b3b 100644
--- a/Java-Ring/src/main/java/org/project/entity/players/Player.java
+++ b/Java-Ring/src/main/java/org/project/entity/players/Player.java
@@ -2,43 +2,91 @@
import org.project.entity.Entity;
import org.project.object.armors.Armor;
+import org.project.object.armors.Nothing;
import org.project.object.weapons.Weapon;
+import static java.lang.Math.max;
+import static java.lang.Math.min;
// TODO: UPDATE IMPLEMENTATION
-public abstract class Player {
+public abstract class Player implements Entity {
protected String name;
Weapon weapon;
Armor armor;
+ //Health Point & Max Health Point
private int hp;
private int maxHP;
+ //Mana Point & Max Mana Point
private int mp;
- private int maxMP;
-
+ private int maxMp;
+ //Exp & Max Exp & Hero Level
+ private int exp =0;
+ private int maxExp=100;
+ private int level = 1;
+ //coins for buying from Shop
+ private int coin = 0;
+ private boolean IsDefending=false;
+ protected boolean IsDead=false;
+
+ //constructor
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
this.name = name;
this.hp = hp;
this.mp = mp;
-
+ this.maxMp = mp;
+ this.maxHP = hp;
this.weapon = weapon;
this.armor = armor;
}
+ //resets player's status each round
@Override
- public void attack(Entity target) {
- target.takeDamage(weapon.getDamage());
+ public void reset()
+ {
+ IsDefending=false;
}
+ //attack
@Override
- public void defend() {
- // TODO: (BONUS) IMPLEMENT A DEFENSE METHOD FOR SHIELDS
+ public void attack(Entity target) {
+ target.takeDamage(weapon.getDamage());
}
- // TODO: (BONUS) UPDATE THE FORMULA OF TAKING DAMAGE
+ //taking damage
@Override
public void takeDamage(int damage) {
- hp -= damage - armor.getDefense();
+
+ //using armor
+ if(!(getArmor() instanceof Nothing)) {
+ getArmor().use(this);
+ armor.checkBreak();
+ }
+
+
+ int actualDamage;
+
+ if(!IsDefending) {
+ actualDamage = max(damage - armor.getDefense(),0);
+ hp -= actualDamage;
+ }
+ else
+ {
+ actualDamage = max(damage - (armor.getDefense()*2 + damage/3),0);
+ hp -= actualDamage;
+
+ }
+
+ System.out.printf("%s takes %d damage!%n", name, actualDamage);
+
+
+
+ if(hp <= 0) {
+ IsDead = true;
+ hp = 0;
+ }
+
}
+ //healing mechanism
@Override
public void heal(int health) {
hp += health;
@@ -47,43 +95,112 @@ public void heal(int health) {
}
}
- @Override
- public void fillMana(int mana) {
- mp += mana;
- if (mp > maxMP) {
- mp = maxMP;
+ //collecting exp
+ public void collectExp(int exp) {
+ if(this.exp + exp < maxExp) {
+ this.exp += exp;
}
- }
+ else
+ {
+ //leveling up
+ while(this.exp + exp >= maxExp)
+ {
+ int temp = maxExp - this.exp;
+ this.exp = 0;
+ this.levelUP();
+ exp = exp - temp;
+ }
- public String getName() {
- return name;
+ this.exp += exp;
+
+ }
+ System.out.printf("%s reached level %d!%n", name, level);
+ System.out.printf("New stats: HP %d/%d, MP %d/%d%n",
+ hp, maxHP, mp, maxMp);
}
- public int getHp() {
- return hp;
+ //leveling up mechanism
+ public void levelUP(){
+ this.level++;
+ this.maxMp = (int)(maxMp*(1+Math.random()));
+ this.maxHP = (int)(this.maxHP*1.1);
+ this.hp = (int)(this.hp*1.1);
+ this.mp = (int)(this.mp*1.1);
+ this.maxExp = (int)(maxExp*1.1);
+
}
+
+ //getter methods
+ @Override
+ public boolean isDefending() {
+ return IsDefending;
+ }
@Override
+ public int getHP() {
+ return hp;
+ }
+ public String getName() {
+ return name;
+ }
public int getMaxHP() {
return maxHP;
}
-
- public int getMp() {
+ public Weapon getWeapon() {
+ return weapon;
+ }
+ public int getMp()
+ {
return mp;
}
-
+ public int getMaxMp()
+ {
+ return maxMp;
+ }
+ public Armor getArmor() {
+ return armor;
+ }
+ public int getLevel() {
+ return level;
+ }
+ public boolean isDead() {
+ return IsDead;
+ }
+ public int getCoin()
+ {
+ return coin;
+ }
+ //get status method
+ public String getStatus(){
+ return String.format("%s [Lvl.%d] | HP: %d/%d | MP: %d/%d | %s | %s | Coins: %d",
+ name, level, hp, maxHP, mp, maxMp,
+ armor.toString(), weapon.toString(), coin);
+ }
@Override
- public int getMaxMP() {
- return maxMP;
+ public String toString(){
+ return this.name;
}
- public Weapon getWeapon() {
- return weapon;
+ //setters
+ @Override
+ public void DefendStatusChange() {
+ IsDefending=!IsDefending;
}
-
- public Armor getArmor() {
- return armor;
+ public void setMp(int mp) {
+ this.mp = min(mp,this.maxMp);
+ }
+ public void setCoin(int coin)
+ {
+ this.coin = coin;
+ }
+ public void setArmor(Armor armor)
+ {
+ this.armor = armor;
+ }
+ public void setWeapon(Weapon weapon)
+ {
+ this.weapon = weapon;
}
-}
+}
\ No newline at end of file
diff --git a/Java-Ring/src/main/java/org/project/location/Location.java b/Java-Ring/src/main/java/org/project/location/Location.java
index dfa9cb8..8d03c64 100644
--- a/Java-Ring/src/main/java/org/project/location/Location.java
+++ b/Java-Ring/src/main/java/org/project/location/Location.java
@@ -7,26 +7,18 @@
public class Location {
private String name;
- private ArrayList enemies;
+ private ArrayList enemies = new ArrayList();
- public Location(ArrayList locations, ArrayList enemies) {
- this.locations = locations;
- this.enemies = enemies;
+ public Location( ArrayList tempEnemies,String name) {
+ enemies.addAll(tempEnemies);
+ this.name = name;
}
- /*
- TODO: (BONUS) RESET EACH LOCATION AFTER PLAYER LEAVES
- */
-
public String getName() {
return name;
}
- public ArrayList getLocations() {
- return locations;
- }
-
public ArrayList getEnemies() {
return enemies;
}
-}
+}
\ No newline at end of file
diff --git a/Java-Ring/src/main/java/org/project/object/Object.java b/Java-Ring/src/main/java/org/project/object/Object.java
index 922cbd5..1ce8f83 100644
--- a/Java-Ring/src/main/java/org/project/object/Object.java
+++ b/Java-Ring/src/main/java/org/project/object/Object.java
@@ -4,8 +4,4 @@
public interface Object {
void use(Entity target);
-
- /*
- TODO: ADD OTHER REQUIRED AND BONUS METHODS
- */
-}
+}
\ No newline at end of file
diff --git a/Java-Ring/src/main/java/org/project/object/armors/Armor.java b/Java-Ring/src/main/java/org/project/object/armors/Armor.java
index 346c25e..7c84304 100644
--- a/Java-Ring/src/main/java/org/project/object/armors/Armor.java
+++ b/Java-Ring/src/main/java/org/project/object/armors/Armor.java
@@ -1,42 +1,52 @@
package org.project.object.armors;
-// TODO: UPDATE IMPLEMENTATION
-public abstract class Armor {
+import org.project.object.Object;
+
+public abstract class Armor implements Object {
private int defense;
private int maxDefense;
private int durability;
private int maxDurability;
-
private boolean isBroke;
-
+ //constructor
public Armor(int defense, int durability) {
this.defense = defense;
this.durability = durability;
}
+ //checks if armor is broken
public void checkBreak() {
- if (durability <= 0) {
+ if (durability <= 0 && !(this instanceof Nothing)) {
+ System.out.println("your armor is broken");
isBroke = true;
defense = 0;
}
}
- // TODO: (BONUS) UPDATE THE REPAIR METHOD
+ //repair mechanism
public void repair() {
isBroke = false;
defense = maxDefense;
durability = maxDurability;
}
+
+ //getters
public int getDefense() {
return defense;
}
-
public int getDurability() {
return durability;
}
-
+ public int getMaxDefense() {
+ return maxDefense;
+ }
public boolean isBroke() {
return isBroke;
}
-}
+
+ //setter
+ public void setDurability(int durability) {
+ this.durability = durability;
+ }
+}
\ No newline at end of file
diff --git a/Java-Ring/src/main/java/org/project/object/armors/KnightArmor.java b/Java-Ring/src/main/java/org/project/object/armors/KnightArmor.java
index 0dedcc2..9f366c8 100644
--- a/Java-Ring/src/main/java/org/project/object/armors/KnightArmor.java
+++ b/Java-Ring/src/main/java/org/project/object/armors/KnightArmor.java
@@ -1,6 +1,21 @@
package org.project.object.armors;
-// TODO: UPDATE IMPLEMENTATION
-public class KnightArmor {
- // TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
+import org.project.entity.Entity;
+
+
+public class KnightArmor extends Armor {
+ public KnightArmor(int defense) {
+ super(defense, 150);
+ }
+
+ @Override
+ public void use(Entity target) {
+ super.setDurability(super.getDurability()-(super.getMaxDefense()/8));
+ checkBreak();
+ }
+
+ @Override
+ public String toString() {
+ return "Knight Armor";
+ }
}
\ No newline at end of file
diff --git a/Java-Ring/src/main/java/org/project/object/consumables/Consumable.java b/Java-Ring/src/main/java/org/project/object/consumables/Consumable.java
index fd8962c..8eca3cd 100644
--- a/Java-Ring/src/main/java/org/project/object/consumables/Consumable.java
+++ b/Java-Ring/src/main/java/org/project/object/consumables/Consumable.java
@@ -1,8 +1,12 @@
package org.project.object.consumables;
+import org.project.object.Object;
+
// TODO: UPDATE IMPLEMENTATION
-public abstract class Consumable {
- /*
- TODO: ADD OTHER REQUIRED AND BONUS METHODS
- */
-}
+public abstract class Consumable implements Object {
+ private boolean consumed;
+
+ public void Consume() {
+ consumed = true;
+ }
+}
\ No newline at end of file
diff --git a/Java-Ring/src/main/java/org/project/object/consumables/Flask.java b/Java-Ring/src/main/java/org/project/object/consumables/Flask.java
index d7e515d..8eca3cd 100644
--- a/Java-Ring/src/main/java/org/project/object/consumables/Flask.java
+++ b/Java-Ring/src/main/java/org/project/object/consumables/Flask.java
@@ -1,16 +1,12 @@
package org.project.object.consumables;
-import org.project.entity.Entity;
+import org.project.object.Object;
// TODO: UPDATE IMPLEMENTATION
-public class Flask {
- /*
- THIS IS AN EXAMPLE OF A CONSUMABLE DESIGN.
- */
+public abstract class Consumable implements Object {
+ private boolean consumed;
- // TODO: (BONUS) UPDATE USE METHOD
- @Override
- public void use(Entity target) {
- target.heal(target.getMaxHP() / 10);
+ public void Consume() {
+ consumed = true;
}
-}
+}
\ No newline at end of file
diff --git a/Java-Ring/src/main/java/org/project/object/weapons/Sword.java b/Java-Ring/src/main/java/org/project/object/weapons/Sword.java
index a0e3cc3..1ad9376 100644
--- a/Java-Ring/src/main/java/org/project/object/weapons/Sword.java
+++ b/Java-Ring/src/main/java/org/project/object/weapons/Sword.java
@@ -4,23 +4,18 @@
import java.util.ArrayList;
-// TODO: UPDATE IMPLEMENTATION
-public class Sword {
- /*
- THIS IS AN EXAMPLE OF A WEAPON DESIGN.
- */
+public class Sword extends Weapon{
- int abilityCharge;
- public Sword() {
- // TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
+ //constructor
+ public Sword(int damage) {
+ super(damage);
}
- // TODO: (BONUS) UPDATE THE UNIQUE ABILITY
- public void uniqueAbility(ArrayList targets) {
- abilityCharge += 2;
- for (Entity target : targets) {
- target.takeDamage(getDamage());
- }
+
+ @Override
+ public String toString() {
+ return "Sword lvl." + super.getLvl() + " Damage: " + super.getDamage();
}
-}
+
+}
\ No newline at end of file
diff --git a/Java-Ring/src/main/java/org/project/object/weapons/Weapon.java b/Java-Ring/src/main/java/org/project/object/weapons/Weapon.java
index 35e1ecc..f94476f 100644
--- a/Java-Ring/src/main/java/org/project/object/weapons/Weapon.java
+++ b/Java-Ring/src/main/java/org/project/object/weapons/Weapon.java
@@ -1,35 +1,41 @@
package org.project.object.weapons;
import org.project.entity.Entity;
+import org.project.object.Object;
-// TODO: UPDATE IMPLEMENTATION
-public abstract class Weapon {
- private int damage;
- private int manaCost;
- /*
- TODO: ADD OTHER REQUIRED AND BONUS ATTRIBUTES
- */
+public abstract class Weapon implements Object {
+ private int damage;
+ private int lvl = 1;
- public Weapon(int damage, int manaCost) {
+ //constructor
+ public Weapon(int damage) {
this.damage = damage;
- this.manaCost = manaCost;
}
-
+ //using weapon
@Override
public void use(Entity target) {
target.takeDamage(damage);
}
+ //leveling up the weapon
+ public void levelUp(){
+ lvl++;
+ setDamage((int)(getDamage()*1.1));
+ };
+
+
+ //getters
public int getDamage() {
return damage;
}
-
- public int getManaCost() {
- return manaCost;
+ public int getLvl()
+ {
+ return lvl;
}
- /*
- TODO: ADD OTHER REQUIRED AND BONUS METHODS
- */
-}
+ //setter
+ public void setDamage(int damage) {
+ this.damage = damage;
+ }
+}
\ No newline at end of file