Merge pull request 'matin mortazavi' (#1) from develop into main

Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
2026-05-11 20:23:24 +00:00
49 changed files with 1164 additions and 23 deletions
+278
View File
@@ -0,0 +1,278 @@
# ⚔️ Java RPG Game
A text-based role‑playing game built in Java, demonstrating core Object‑Oriented Programming principles such as inheritance, polymorphism, interfaces, abstraction, and encapsulation.
The player chooses a hero (Knight, Wizard, or Assassin), equips weapons and armour, and battles various enemies (Skeleton, Vampire, Goblin) in a simple turn‑based loop. Locations and consumable items are also partially implemented.
---
## 📁 Project Structure
---
## 🎮 Gameplay Overview
1. Character Selection – Enter your name, pick a class (Assassin, Wizard, Knight), choose a weapon and armour.
2. Combat Loop – You face random enemies from a list. Each turn you can:
- Light Attack
- Heavy Attack (normal attack)
- Defend
- Heal
- Use Special Ability
3. Enemy AI – Enemies randomly choose between light and heavy attacks. Some enemies (e.g. Goblin) have special behaviours.
4. Progression – After defeating an enemy, the player's maximum HP and MP increase, and both player and enemy stats are refreshed.
5. Relocation – You can choose to move to another location (currently selecting a random enemy from the list).
---
## 🧱 Class Hierarchy & Interfaces
### Interface Entity
Defines the contract for all living beings in the game.
| Method | Description |
|--------|-------------|
| void attack(Entity target) | Basic attack on a target. |
| void LightAttack(Entity target, int base_damage) | A weaker attack with fixed damage. |
| void defend(Entity me, int damage) | Defensive action (confusing signature, see Player). |
| String getName() | Returns the entity's name. |
| void heal(int health) | Restores health points. |
| void fillMana(int mana) | Restores mana points. |
| void takeDamage(int damage) | Applies damage after armour reduction. |
| int getMaxHP() | Returns maximum health. |
| int getMaxMP() | Returns maximum mana. |
| boolean ISLive() | Checks if the entity is alive (HP > 0). |
### Interface Item
Defines usable items.
| Method | Description |
|--------|-------------|
| void use(Entity target) | Apply the item's effect to the target. |
| String getName() | Returns the item's name. |
---
## 🧙 Abstract Classes
### Player (extends Entity)
Common base for all player characters.
Fields:
- name, weapon, armor, hp, maxHP, mp, maxMP, baseDamage (unused)
Constructors:
- Player(String name, int hp, int mp, Weapon weapon, Armor armor, int baseDamage)
- Player(String name, int hp, int mp, Weapon weapon, Armor armor) – sets maxHP/maxMP equal to initial hp/mp.
Methods:
- void attack(Entity target) – Deals weapon damage.
- void defend(Entity me, int damage) – Heals the entity itself (unusual).
- void takeDamage(int damage) – Reduces damage by armour defence.
- void heal(int health) – Adds health, capped at maxHP.
- void fillMana(int mana) – Adds mana, capped at maxMP.
- abstract void specialAttack(Entity target) – Each subclass defines its own special move.
- boolean IsLive() – Returns true if HP > 0.
- void LightAttack(Entity target, int base_damage) – Deals flat damage.
- void UpGradeMaxHP() / UpGradeMaxMP() – Increases max stats by 20% (used after battle).
- void freshFactors() – Fully restores HP and MP.
### Enemy (extends Entity)
Base for all enemy types.
Fields:
- weapon, hp, mp, maxHp, maxMp
Constructor:
- Enemy(int hp, int mp, Weapon weapon) – Initialises stats and weapon.
Methods:
- int getHp(), int getMp(), Weapon getWeapon(), void setNewHp(int newhp)
- void takeDamage(int damage) – Direct HP reduction.
- abstract void attack(Entity target)
- abstract void check_hp() – Intended for death/recovery checks.
- abstract void defend() – Normal defend.
- abstract String getName()
- void heal(int health), void fillMana(int mana) – Standard recovery.
- boolean IsLive() – HP > 0.
- void LightAttack(Entity target, int base_damage) – Flat damage.
- int getMaxHP(), int getMaxMp()
- void freshFactors() – Resets HP/MP to max.
### Consumable (implements Item)
Base for consumable items.
- Consumable(String name) – Sets the item name.
- String getName()
### Weapon (abstract)
Base for all weapons.
Fields:
- int damage, int manaCost
Constructor: Weapon(int damage, int manaCost)
Methods:
- int getDamage(), int getManaCost()
- (No use method – not implementing Item)
### Armor (abstract)
Base for all armour pieces.
Fields:
- defense, maxDefense, durability, maxDurability, isBroke (private)
Constructors:
- Armor(int defense, int durability) – Main constructor (does not initialise max values correctly).
- Armor(int maxDefense, int maxDurability, boolean isBroke) – Unused overload.
Methods:
- void checkBreak() – If durability ≤ 0, sets isBroke = true and defense = 0.
- void repair() – Restores defence/durability to max values.
- int getDefense(), int getDurability(), boolean isBroke()
- void setMaxDefense(int max)
- void newDurability() – Decrements durability (does not auto‑call checkBreak).
---
## 🧝‍♂️ Concrete Player Classes
### Knight
- Base stats: HP=40, MP=20
- specialAttack(Entity target) – Deals 5 damage.
### Wizard
- Base stats: HP=40, MP=20
- specialAttack(Entity target) – Deals 5 damage and heals self for 10 HP (capped at max).
### Assassin
- Base stats: HP=20, MP=40
- specialAttack(Entity target) – Deals weapon damage.
All three override ISLive() to always return false (bug – should use IsLive() from Player).
---
## 👹 Concrete Enemy Classes
### Skeleton
- HP=10, MP=2
- attack(Entity target) – Weapon damage.
- check_hp() – If HP ≤ 0 and not yet revived, sets HP to Max_hp/2 (5). (Bug: ISLive() returns false, so this may not work as intended.)
- getName() returns "Skeleton".
### Vampire
- HP=12, MP=5
- attack(Entity target) – Weapon damage, heals self by damage/3, capped at Max_hp.
- getName() returns "Vampire".
### Goblin
- HP=6, MP=18
- attack(Entity target) – Weapon damage.
- getName() returns "Gobblin".
### Dragon
- Extends Enemy but currently all methods are empty/return default values – not fully implemented.
---
## ⚔️ Weapons
### Sword
- damage=3, manaCost=4 (constants, but constructor accepts parameters that are ignored)
- Copy constructor: Sword(Weapon other) copies damage and manaCost from another weapon.
- uniqueAbility(ArrayList<Entity> targets) – deals weapon damage to all targets.
### SwordPro
- damage=4, manaCost=3
- Same copy constructor and unique ability.
### SwordProMax
- damage=5, manaCost=2
- Same pattern.
---
## 🛡️ Armors
### KnightArmor
- defense=3, durability=2 (constructor ignores parameters, always uses static constants)
- No copy constructor.
### ArmorNormal
- defense=1, durability=2
### ArmorPro
- defense=2, durability=2
### ArmorProMax
- defense=1, durability=5
All armours use the same pattern: a static final value passed to super().
---
## 🧪 Consumables
### Flask (extends Consumable)
- Flask(String name) – calls super.
- use(Entity target) – Heals target by 10% of its max HP.
Currently unused in gameplay; the Main loop does not reference flasks.
---
## 📍 Location
- Fields: name, enemies (ArrayList<Enemy>), locations (ArrayList<Location>)
- Constructor takes locations and enemies, but does not assign name (remains null).
- Not integrated into the main game loop yet.
---
## 🎯 Main Class (Game Loop)
The main method contains:
1. Setup: Creates weapon instances, enemy list (Skeleton, Vampire, Goblin), scanner, random.
2. Player creation: Asks for name, class (1‑3), weapon (1‑3), armour (1‑4). Uses copy constructors for weapons.
3. Game loop: While player is alive (checks player.ISLive() – currently buggy, always false so loop never enters). Inside:
- Displays current enemy name.
- Offers two options: Fight (1) or Move (2). Moving picks a random enemy from the list.
- When fight is selected, calls playerMove() (player attacks), then if enemy lives, enemyMove() (enemy attacks).
- After enemy dies, player’s max HP/MP increase, both are refreshed.
4. Helper methods:
- playerMove(Player, Enemy) – Displays a menu of actions (Light Attack, Heavy Attack, Defend, Heal, Special) and calls the corresponding method.
- enemyMove(Player, Enemy, int) – Randomly chooses Light Attack or normal Attack for the enemy.
- showDetails(Player, Enemy) – Prints current stats.
- pause(double seconds) – Sleeps the program for a given time.
---
## 🐞 Known Issues / Quirks
- Player.ISLive() always returns false because overridden incorrectly in subclasses; the loop condition is never satisfied.
- Armor constructors do not properly initialise maxDefense/maxDurability.
- Entity interface contains defend(Entity me, int damage) which doesn’t match the usual defend() signature.
- Many ISLive() overrides just return false, while the correct logic is in IsLive() (non‑interface method). The game uses ISLive() (interface method) which clashes with the intended behaviour.
- Location is not used; its name field is never set.
---
## 🚀 How to Run
1. Compile all .java files inside the org/project package.
2. Run org.project.Main.
3. Follow the console prompts to play.
---
## 📚 OOP Concepts Demonstrated
- Inheritance: Player and Enemy extend Entity; weapons extend Weapon; armours extend Armor.
- Polymorphism: Entity references used for both players and enemies in combat.
- Encapsulation: Private fields with getters/setters (though some fields could be better protected).
- Abstraction: Abstract classes Player, Enemy, Weapon, Armor define common behaviour; subclasses fill in specifics.
---
Enjoy the game! Contributions and fixes are welcome.
+245 -2
View File
@@ -1,15 +1,258 @@
package org.project; package org.project;
import java.util.*;
import org.project.entity.Entity;
import org.project.entity.enemies.Enemy;
import org.project.entity.enemies.Goblin;
import org.project.entity.enemies.Skeleton;
import org.project.entity.enemies.Vampire;
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.item.armors.*;
import org.project.item.weapons.Sword;
import org.project.item.weapons.SwordPro;
import org.project.item.weapons.SwordProMax;
import org.project.item.weapons.Weapon;
import org.project.location.Location; import org.project.location.Location;
import java.util.ArrayList;
import java.util.List;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
// TODO: ADD LOCATIONS TO YOUR GAME // TODO: ADD LOCATIONS TO YOUR GAME
int a ;
int b ;
int c ;
String name ;
Scanner input = new Scanner(System.in) ;
Random random = new Random() ;
List<Location> locations = new ArrayList<>(); List<Location> locations = new ArrayList<>();
ArrayList<Enemy> enemies = new ArrayList<>() ;
Weapon sword = new Sword(3 , 4 ) ;
Weapon swordProMax = new SwordProMax(5 , 2 ) ;
Weapon swordPro = new SwordPro(4 , 3) ;
Enemy vampire = new Vampire(12 ,5 , swordProMax) ;
Enemy skeleton = new Skeleton(10 , 2 , sword) ;
Enemy goblin = new Goblin(8 , 12 , swordPro) ;
enemies.add(skeleton) ;
enemies.add(vampire) ;
enemies.add(goblin) ;
Weapon swo ;
Armor arm = null;
Player player ;
Enemy enemy = skeleton ;
String enemy_name = "Skeleton" ;
boolean enemyIsLive = false ;
System.out.println("---- Enter your name : ----") ;
name = input.nextLine() ;
System.out.println("----select your character ----") ;
System.out.println(" Assassin : 1 , Wizard : 2 , Knight : 3 ");
a = input.nextInt() ;
System.out.println("-----select your Weapon ----");
System.out.println(" Sword : 1 , Sword Pro : 2 , Sword Pro Max : 3 ");
b = input.nextInt() ;
System.out.println("-----select your Armor ----");
System.out.println(" Normal Armor : 1 , Armor Pro : 2 , Armor Pro Max : 3 , Knight Armor : 4 ");
c = input.nextInt() ;
if (b == 1) {
swo = new Sword(sword);
}
else if (b == 2 )
{
swo = new SwordPro(swordPro) ;
}
else {
swo = new SwordProMax(swordProMax) ;
}
if (c == 1 )
{
arm = new ArmorNormal(1 ,2) ;
}
else if (c == 2 )
{
arm = new ArmorPro(2 ,2) ;
}
else if (c == 3)
{
arm = new ArmorProMax(5 ,1) ;
}
else if (c == 4)
{
Armor knightarmor = new KnightArmor(3 , 2 ) ;
}
if (a == 1 )
{
player = new Assassin(name , swo , arm ) ;
}
else if ( a == 2 )
{
player = new Wizard(name , swo , arm ) ;
}
else {
player = new Knight(name , swo , arm ) ;
}
System.out.println(player.IsLive());
System.out.println(player.getHp());
while(!player.ISLive())
{
int sel = 0 ;
System.out.println(enemyIsLive);
while (sel != 1 && enemyIsLive == false) {
System.out.println("your Enemy is : " + enemy_name);
System.out.println("# 1) Fight the enemy");
System.out.println("# 2) Move to another location:");
sel = input.nextInt();
if (sel == 2) {
enemy = enemies.get(random.nextInt(enemies.size()));
enemy_name = enemy.getName();
}
else if (sel == 1)
{
enemyIsLive = true ;
break ;
}
}
playerMove(player , enemy );
showDetails(player , enemy);
pause(5);
System.out.println(enemy.IsLive());
if (enemy.IsLive())
{
System.out.println("salam");
int ran = random.nextInt(2) ;
System.out.println(ran);
if (Objects.equals(enemy.getName(), "Goblin"))
{
int ran2 = random.nextInt(3) ;
if (ran == 0)
{
enemy.LightAttack(player , 3 );
showDetails(player , enemy);
pause(5);
}
else
{
enemy.attack(player);
showDetails(player , enemy);
pause(5);
}
}
else {
enemyMove(player, enemy, ran);
showDetails(player, enemy);
pause(5);
}
}
else {
System.out.println("the " + enemy_name + " died !");
enemyIsLive = false;
sel = 0 ;
player.UpGradeMaxHP();
player.UpGradeMaxMP();
player.freshFactors();
enemy.freshFactors();
}
}
// TODO: IMPLEMENT GAMEPLAY // TODO: IMPLEMENT GAMEPLAY
} }
public static void playerMove (Player player , Enemy enemy )
{
System.out.println("# What You Want To Do :");
System.out.println("# 1) Light Attack ");
System.out.println("# 2) Heavy Attack ");
System.out.println("# 3) Defend ") ;
System.out.println("# 4) Heal") ;
System.out.println("# 5) Special Ability");
Scanner sc = new Scanner(System.in) ;
int x = sc.nextInt() ;
switch (x) {
case 1 :
player.LightAttack(enemy , 3);
break;
case 2 :
player.attack(enemy);
break;
case 3 :
player.defend(player , 5);
break;
case 4 :
player.heal(6);
break;
case 5 :
player.specialAttack(enemy);
break;
}
}
public static void enemyMove ( Player player , Enemy enemy , int x )
{
switch (x) {
case 0 :
enemy.LightAttack(player , 3);
break;
case 1 :
enemy.attack(player);
break;
}
}
public static void showDetails (Player player , Enemy enemy )
{
System.out.println("player's Max Hp : " + player.getMaxHP() + " Mp : " + player.getMaxMP()) ;
System.out.println("player's Hp : " + player.getHp() + " Mp : " + player.getMp());
System.out.println("Enemy's Max Hp : " + enemy.getMaxHP()+ " Mp : " + enemy.getMaxMP()) ;
System.out.println("Enemy's Hp : " + enemy.getHp() + " Mp : " + enemy.getMp());
}
public static void pause(double seconds) {
try {
Thread.sleep((long)(seconds * 1000));
} catch (InterruptedException e) {
}
}
} }
@@ -2,8 +2,11 @@ package org.project.entity;
public interface Entity { public interface Entity {
void attack(Entity target); void attack(Entity target);
void LightAttack (Entity target , int base_damage) ;
void defend(); void defend(Entity me , int damage);
String getName() ;
void heal(int health); void heal(int health);
@@ -15,6 +18,8 @@ public interface Entity {
int getMaxMP(); int getMaxMP();
boolean ISLive() ;
/* /*
TODO: ADD OTHER REQUIRED AND BONUS METHODS TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/ */
@@ -0,0 +1,53 @@
package org.project.entity.enemies;
import org.project.item.weapons.Weapon;
import org.project.entity.Entity ;
// TODO: UPDATE IMPLEMENTATION
public class Dragon extends Enemy {
public Dragon(int hp, int mp, Weapon weapon) {
super(hp, mp, weapon);
}
@Override
public void attack(Entity target) {
}
@Override
public void defend(Entity me, int damage) {
}
@Override
public void check_hp() {
}
@Override
public void defend() {
}
@Override
public String getName() {
return "";
}
@Override
public int getMaxHP() {
return 0;
}
@Override
public int getMaxMP() {
return 0;
}
@Override
public boolean ISLive() {
return false;
}
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR
}
@@ -1,16 +1,23 @@
package org.project.entity.enemies; package org.project.entity.enemies;
import org.project.entity.Entity;
import org.project.item.weapons.Weapon; import org.project.item.weapons.Weapon;
import org.project.item.armors.Armor ;
// TODO: UPDATE IMPLEMENTATION // TODO: UPDATE IMPLEMENTATION
public abstract class Enemy {
Weapon weapon; public abstract class Enemy implements Entity {
private Weapon weapon;
private int hp; private int hp;
private int mp; private int mp;
private int maxHp ;
private int maxMp ;
public Enemy(int hp, int mp, Weapon weapon) { public Enemy(int hp, int mp, Weapon weapon) {
this.hp = hp; this.hp = hp;
this.maxHp = hp ;
this.mp = mp; this.mp = mp;
this.maxMp =mp ;
this.weapon = weapon; this.weapon = weapon;
} }
@@ -24,6 +31,10 @@ public abstract class Enemy {
return hp; return hp;
} }
public void setNewHp(int newhp) {
hp = newhp;
}
public int getMp() { public int getMp() {
return mp; return mp;
} }
@@ -31,4 +42,58 @@ public abstract class Enemy {
public Weapon getWeapon() { public Weapon getWeapon() {
return weapon; return weapon;
} }
@Override
public abstract void attack(Entity target) ;
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR
public abstract void check_hp();
public abstract void defend();
public abstract String getName() ;
public void heal(int health)
{
hp = hp + health ;
if (hp > maxHp)
{
hp = maxHp;
}
}
public void fillMana( int mana)
{
mp += mana ;
if (mp > maxMp)
{
mp = maxMp ;
}
}
public boolean IsLive ( )
{
if (getHp() <= 0 )
return false ;
else
{
return true ;
}
}
@Override
public void LightAttack( Entity target , int base_damage)
{
target.takeDamage(base_damage);
}
public int getMaxHP() {
return maxHp;
}
public int getMaxMp(){return maxMp ; }
public void freshFactors()
{
mp = maxMp ;
hp = maxHp ;
}
} }
@@ -0,0 +1,69 @@
package org.project.entity.enemies;
import org.project.entity.Entity;
import org.project.item.weapons.Weapon;
// TODO: UPDATE IMPLEMENTATION
public class Goblin extends Enemy{
private static final int Max_hp = 6 ;
private static final int Max_mp = 18 ;
public Goblin(int hp, int mp, Weapon weapon) {
super(Max_hp, Max_mp, weapon);
}
@Override
public void defend() {
}
@Override
public void heal(int health) {
}
@Override
public void fillMana(int mana) {
}
@Override
public int getMaxHP() {
return 0;
}
@Override
public int getMaxMP() {
return 0;
}
@Override
public boolean ISLive() {
return false;
}
public void attack (Entity target)
{
int damage = getWeapon().getDamage();
System.out.println("Skeleton use ----");
target.takeDamage(damage);
}
@Override
public void check_hp() {
}
@Override
public void defend(Entity me, int damage) {
}
@Override
public String getName()
{
return "Gobblin " ;
}
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR
}
@@ -1,6 +1,76 @@
package org.project.entity.enemies; package org.project.entity.enemies;
import org.project.entity.Entity;
import org.project.item.weapons.Weapon;
// TODO: UPDATE IMPLEMENTATION // TODO: UPDATE IMPLEMENTATION
public class Skeleton { public class Skeleton extends Enemy {
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR private boolean dead;
private static final int Max_hp = 10 ;
private static final int Max_mp = 2 ;
public Skeleton (int hp, int mp, Weapon weapon) {
super(Max_hp , Max_mp , weapon );
this.dead = false ;
}
@Override
public void check_hp ()
{
int x = getHp() ;
if (x <= 0 && dead == false)
{
setNewHp(Max_hp/2) ;
}
}
@Override
public void defend() {
}
@Override
public void heal(int health) {
}
@Override
public void fillMana(int mana) {
}
@Override
public int getMaxHP() {
return super.getMaxHP() ;
}
@Override
public int getMaxMP() {
return super.getMaxMp() ;
}
@Override
public boolean ISLive() {
return false;
}
public void attack (Entity target)
{
int damage = getWeapon().getDamage();
System.out.println("Skeleton use ----");
target.takeDamage(damage);
}
@Override
public void defend(Entity me, int damage) {
}
@Override
public String getName()
{
return "Skeleton " ;
}
} }
@@ -0,0 +1,68 @@
package org.project.entity.enemies;
import org.project.entity.Entity;
import org.project.item.weapons.Weapon;
// TODO: UPDATE IMPLEMENTATION
public class Vampire extends Enemy {
private static final int Max_hp = 12 ;
private static final int Max_mp = 5 ;
public Vampire (int hp, int mp, Weapon weapon) {
super(Max_hp , Max_mp , weapon );
}
@Override
public void attack(Entity target)
{
int damage = getWeapon().getDamage() ;
System.out.println("Vampire use ----");
target.takeDamage(damage);
setNewHp(damage/3) ;
if (getHp() > Max_hp)
{
setNewHp(Max_hp) ;
}
}
@Override
public void check_hp() {
}
@Override
public void defend(Entity me, int damage) {
}
@Override
public int getMaxHP() {
return 0;
}
@Override
public int getMaxMP() {
return 0;
}
@Override
public boolean ISLive() {
return false;
}
@Override
public void defend() {
}
@Override
public String getName()
{
return "Vampire " ;
}
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR
}
@@ -0,0 +1,24 @@
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 static final int assassinHp = 20 ;
private static final int asssassinmp = 40;
public Assassin(String name , Weapon weapon , Armor armor )
{
super(name , assassinHp , asssassinmp ,weapon ,armor);
}
@Override
public void specialAttack(Entity target) {
target.takeDamage(weapon.getDamage());
}
@Override
public boolean ISLive() {
return false;
}
}
@@ -1,6 +1,26 @@
package org.project.entity.players; package org.project.entity.players;
import org.project.entity.Entity;
import org.project.item.armors.Armor;
import org.project.item.weapons.Weapon;
// TODO: UPDATE IMPLEMENTATION // TODO: UPDATE IMPLEMENTATION
public class Knight { public class Knight extends Player {
// TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR private static final int knightHp = 40 ;
private static final int knightmp = 20 ;
public Knight(String name , Weapon weapon , Armor armor )
{
super(name , knightHp , knightmp ,weapon ,armor);
}
@Override
public void specialAttack(Entity target) {
target.takeDamage(5);
}
@Override
public boolean ISLive() {
return false;
}
} }
@@ -5,7 +5,7 @@ import org.project.item.armors.Armor;
import org.project.item.weapons.Weapon; import org.project.item.weapons.Weapon;
// TODO: UPDATE IMPLEMENTATION // TODO: UPDATE IMPLEMENTATION
public abstract class Player { public abstract class Player implements Entity{
protected String name; protected String name;
Weapon weapon; Weapon weapon;
Armor armor; Armor armor;
@@ -13,15 +13,28 @@ public abstract class Player {
private int maxHP; private int maxHP;
private int mp; private int mp;
private int maxMP; private int maxMP;
private int baseDamage ;
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) { public Player(String name, int hp, int mp, Weapon weapon, Armor armor , int baseDamage) {
this.name = name; this.name = name;
this.hp = hp; this.hp = hp;
this.mp = mp; this.mp = mp;
this.weapon = weapon; this.weapon = weapon;
this.armor = armor; this.armor = armor;
this.baseDamage = baseDamage ;
} }
public Player(String name , int hp , int mp , Weapon weapon , Armor armor )
{
this.name = name ;
this.hp = hp ;
this.mp = mp ;
this.maxHP = hp ;
this.maxMP = mp ;
this.weapon = weapon ;
this.armor = armor ;
}
@Override @Override
public void attack(Entity target) { public void attack(Entity target) {
@@ -29,8 +42,11 @@ public abstract class Player {
} }
@Override @Override
public void defend() { public void defend(Entity me , int damage) {
// TODO me.heal(damage);
} }
@@ -63,6 +79,9 @@ public abstract class Player {
public int getHp() { public int getHp() {
return hp; return hp;
} }
public void setHp(int newhp){
hp = newhp ;
}
@Override @Override
public int getMaxHP() { public int getMaxHP() {
@@ -73,6 +92,7 @@ public abstract class Player {
return mp; return mp;
} }
@Override @Override
public int getMaxMP() { public int getMaxMP() {
return maxMP; return maxMP;
@@ -85,5 +105,32 @@ public abstract class Player {
public Armor getArmor() { public Armor getArmor() {
return armor; return armor;
} }
public abstract void specialAttack(Entity target) ;
public boolean IsLive ( )
{
if (getHp() <= 0 )
return false ;
else
{
return true ;
}
}
public void LightAttack( Entity target , int base_damage)
{
target.takeDamage(base_damage);
}
public void UpGradeMaxHP ()
{
maxHP = maxHP + (maxHP*2/10) ;
}
public void UpGradeMaxMP ()
{
maxMP = maxMP + (maxMP*2/10) ;
}
public void freshFactors()
{
mp = maxMP ;
hp = maxHP ;
}
} }
@@ -0,0 +1,33 @@
package org.project.entity.players;
import org.project.entity.Entity;
import org.project.item.armors.Armor;
import org.project.item.weapons.Weapon;
// TODO: UPDATE IMPLEMENTATION
public class Wizard extends Player {
private static final int WizardHp = 40;
private static final int Wizardmp = 20 ;
public Wizard(String name , Weapon weapon , Armor armor )
{
super(name , WizardHp , Wizardmp ,weapon ,armor);
}
@Override
public void specialAttack(Entity target) {
target.takeDamage(5);
setHp(getHp()+10);
if (getHp() > WizardHp) {
setHp(WizardHp);
}
// TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR
}
@Override
public boolean ISLive() {
return false;
}
}
@@ -4,6 +4,8 @@ import org.project.entity.Entity;
public interface Item { public interface Item {
void use(Entity target); void use(Entity target);
String getName () ;
/* /*
TODO: ADD OTHER REQUIRED AND BONUS METHODS TODO: ADD OTHER REQUIRED AND BONUS METHODS
@@ -13,6 +13,12 @@ public abstract class Armor {
this.defense = defense; this.defense = defense;
this.durability = durability; this.durability = durability;
} }
public Armor(int maxDefense , int maxDurability , boolean isBroke)
{
this.maxDefense = maxDefense ;
this.maxDurability = maxDurability ;
this.isBroke = isBroke ;
}
public void checkBreak() { public void checkBreak() {
if (durability <= 0) { if (durability <= 0) {
@@ -31,10 +37,15 @@ public abstract class Armor {
public int getDefense() { public int getDefense() {
return defense; return defense;
} }
public void setMaxDefense( int max){ maxDefense = max ; }
public int getDurability() { public int getDurability() {
return durability; return durability;
} }
public void newDurability()
{
durability -- ;
}
public boolean isBroke() { public boolean isBroke() {
return isBroke; return isBroke;
@@ -0,0 +1,17 @@
package org.project.item.armors;
// TODO: UPDATE IMPLEMENTATION
public class ArmorNormal extends Armor {
private static final int Max_defense = 1 ;
private static final int Max_durability = 2 ;
private static final boolean Isbrok = false ;
public ArmorNormal(int defense, int durability) {
super(Max_defense, Max_durability);
}
// TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
}
@@ -0,0 +1,16 @@
package org.project.item.armors;
// TODO: UPDATE IMPLEMENTATION
public class ArmorPro extends Armor {
private static final int Max_defense = 2 ;
private static final int Max_durability = 2 ;
private static final boolean Isbrok = false ;
public ArmorPro(int defense, int durability) {
super(Max_defense, Max_durability);
}
// TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
}
@@ -0,0 +1,16 @@
package org.project.item.armors;
// TODO: UPDATE IMPLEMENTATION
public class ArmorProMax extends Armor {
private static final int Max_defense = 1 ;
private static final int Max_durability = 5 ;
private static final boolean Isbrok = false ;
public ArmorProMax(int defense, int durability) {
super(Max_defense, Max_durability);
}
// TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
}
@@ -1,6 +1,17 @@
package org.project.item.armors; package org.project.item.armors;
// TODO: UPDATE IMPLEMENTATION // TODO: UPDATE IMPLEMENTATION
public class KnightArmor { public class KnightArmor extends Armor {
private static final int Max_defense = 3 ;
private static final int Max_durability = 2 ;
private static final boolean Isbrok = false ;
public KnightArmor(int defense, int durability) {
super(Max_defense, Max_durability);
}
// TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR // TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
} }
@@ -1,8 +1,17 @@
package org.project.item.consumables; package org.project.item.consumables;
import org.project.item.Item;
// TODO: UPDATE IMPLEMENTATION // TODO: UPDATE IMPLEMENTATION
public abstract class Consumable { public abstract class Consumable implements Item {
private String name ;
public Consumable (String name )
{
this.name = name ;
}
public String getName () { return name ; }
/* /*
TODO: ADD OTHER REQUIRED AND BONUS METHODS TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/ */
} }
@@ -3,7 +3,10 @@ package org.project.item.consumables;
import org.project.entity.Entity; import org.project.entity.Entity;
// TODO: UPDATE IMPLEMENTATION // TODO: UPDATE IMPLEMENTATION
public class Flask { public class Flask extends Consumable {
public Flask(String name) {
super(name);
}
/* /*
THIS IS AN EXAMPLE OF A CONSUMABLE DESIGN. THIS IS AN EXAMPLE OF A CONSUMABLE DESIGN.
*/ */
@@ -5,17 +5,27 @@ import org.project.entity.Entity;
import java.util.ArrayList; import java.util.ArrayList;
// TODO: UPDATE IMPLEMENTATION // TODO: UPDATE IMPLEMENTATION
public class Sword { public class Sword extends Weapon {
/* /*
THIS IS AN EXAMPLE OF A WEAPON DESIGN. THIS IS AN EXAMPLE OF A WEAPON DESIGN.
*/ */
private static final int damage = 3 ;
private static final int manacost = 4;
int abilityCharge; int abilityCharge;
public Sword() { public Sword(int Damage , int Manacost) {
super(damage , manacost);
// TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR // TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
} }
public Sword(Weapon other ) {
super (other.getDamage() , other.getManaCost());
}
// TODO: (BONUS) UPDATE THE UNIQUE ABILITY // TODO: (BONUS) UPDATE THE UNIQUE ABILITY
public void uniqueAbility(ArrayList<Entity> targets) { public void uniqueAbility(ArrayList<Entity> targets) {
abilityCharge += 2; abilityCharge += 2;
@@ -0,0 +1,38 @@
package org.project.item.weapons;
import org.project.entity.Entity;
import java.util.ArrayList;
// TODO: UPDATE IMPLEMENTATION
public class SwordPro extends Weapon {
/*
THIS IS AN EXAMPLE OF A WEAPON DESIGN.
*/
private static final int damage = 4 ;
private static final int manacost = 3;
int abilityCharge;
public SwordPro(int Damage , int Manacost) {
super(damage , manacost);
// TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
}
public SwordPro(Weapon other) {
super (other.getDamage() , other.getManaCost());
}
// TODO: (BONUS) UPDATE THE UNIQUE ABILITY
public void uniqueAbility(ArrayList<Entity> targets) {
abilityCharge += 2;
for (Entity target : targets) {
target.takeDamage(getDamage());
}
}
}
@@ -0,0 +1,35 @@
package org.project.item.weapons;
import org.project.entity.Entity;
import java.util.ArrayList;
// TODO: UPDATE IMPLEMENTATION
public class SwordProMax extends Weapon {
/*
THIS IS AN EXAMPLE OF A WEAPON DESIGN.
*/
private static final int damage = 5 ;
private static final int manacost = 2;
int abilityCharge;
public SwordProMax(int Damage , int Manacost) {
super(damage , manacost);
// TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
}
public SwordProMax(Weapon other) {
super (other.getDamage() , other.getManaCost());
}
// TODO: (BONUS) UPDATE THE UNIQUE ABILITY
public void uniqueAbility(ArrayList<Entity> targets) {
abilityCharge += 2;
for (Entity target : targets) {
target.takeDamage(getDamage());
}
}
}
@@ -16,10 +16,7 @@ public abstract class Weapon {
this.manaCost = manaCost; this.manaCost = manaCost;
} }
@Override
public void use(Entity target) {
target.takeDamage(damage);
}
public int getDamage() { public int getDamage() {
return damage; return damage;
@@ -8,6 +8,7 @@ public class Location {
private String name; private String name;
private ArrayList<Enemy> enemies; private ArrayList<Enemy> enemies;
private ArrayList<Location> locations ;
public Location(ArrayList<Location> locations, ArrayList<Enemy> enemies) { public Location(ArrayList<Location> locations, ArrayList<Enemy> enemies) {
this.locations = locations; this.locations = locations;
Binary file not shown.