complte classes

This commit is contained in:
2026-05-10 16:07:52 +03:30
parent 78d4bedb08
commit a7ff45292f
26 changed files with 459 additions and 104 deletions
@@ -7,9 +7,43 @@ 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
List<Location> locations = new ArrayList<>();
ArrayList<String> names = new ArrayList<>();
names.add("Nou Camp");
names.add("Bernabeu");
names.add("Azadi");
System.out.println("----------Welcome to Java-Knight");
while (true){
}
// TODO: IMPLEMENT GAMEPLAY // TODO: IMPLEMENT GAMEPLAY
} }
private void
} }
@@ -1,21 +1,24 @@
package org.project.entity; package org.project.entity;
import org.project.item.armors.Armor;
public interface Entity { public interface Entity {
void attack(Entity target);
void lightattack(Entity target);
void heavyattack(Entity target);
void defend(); void defend();
void healHp(int health);
void heal(int health); void healMp(int mp);
void fillMana(int mana); void fillMana(int mana);
void takeDamage(int damage); void takeDamage(int damage);
int getMaxHP(); int getMaxHP();
int getMaxMP(); int getMaxMP();
Armor getArmor();
void falsepossible();
void truepossible();
boolean isalive();
void specialAbility(Entity target);
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
} }
@@ -0,0 +1,20 @@
package org.project.entity.enemies;
import org.project.entity.Entity;
import org.project.item.armors.EnemyArmor;
import org.project.item.weapons.DragonWepon;
import org.project.item.weapons.Weapon;
public class Dragon extends Enemy{
public Dragon(){
super(200 , 50 , new DragonWepon() , new EnemyArmor());
}
public void specialAbility(Entity target){
heavyattack(target);
//sout : fire!
}
}
@@ -1,23 +1,58 @@
package org.project.entity.enemies; package org.project.entity.enemies;
import org.project.entity.Entity;
import org.project.item.armors.Armor;
import org.project.item.weapons.Weapon; import org.project.item.weapons.Weapon;
// TODO: UPDATE IMPLEMENTATION
public abstract class Enemy {
Weapon weapon;
private int hp;
private int mp;
public Enemy(int hp, int mp, Weapon weapon) {
public abstract class Enemy implements Entity {
protected Weapon weapon;
protected Armor armor;
protected int hp;
protected int mp;
protected int maxHp;
protected int maxMp;
protected boolean ispossible;
protected boolean haveKey;
protected boolean isalive;
public Enemy(int hp, int mp, Weapon weapon , Armor armor) {
this.hp = hp; this.hp = hp;
this.maxHp=hp;
this.mp = mp; this.mp = mp;
this.maxMp=mp;
this.weapon = weapon; this.weapon = weapon;
this.armor = armor;
this.ispossible = true;
this.isalive=true;
int n = (int) (Math.random())*2;
if(n==0){
haveKey=true;
}
else {
haveKey=false;
}
} }
@Override
public void lightattack(Entity target){
target.takeDamage(weapon.getDamage());
}
public void takeDamage(int damage) { public void takeDamage(int damage) {
hp -= damage; if(!armor.checkBreak()){
hp -= damage - armor.getDefense();
armor.use(this);
}
else {
hp -=damage;
};
} }
public int getHp() { public int getHp() {
@@ -28,7 +63,45 @@ public abstract class Enemy {
return mp; return mp;
} }
public int getMaxHP(){
return maxHp;
}
public int getMaxMP(){
return maxMp;
}
public Weapon getWeapon() { public Weapon getWeapon() {
return weapon; return weapon;
} }
public Armor getArmor(){return armor;}
public void falsepossible(){
ispossible = false;
}
public void truepossible(){
ispossible=true;}
public boolean getpossible(){
return ispossible;
}
public abstract void specialAbility(Entity target);
@Override
public boolean isalive(){
return isalive;
}
@Override
public void heavyattack(Entity target){
target.takeDamage(weapon.getDamage());
}
public void defend() {}
public void healHp(int health){}
public void healMp(int mp){}
public void fillMana(int mana){}
} }
@@ -0,0 +1,19 @@
package org.project.entity.enemies;
import org.project.entity.Entity;
import org.project.item.armors.EnemyArmor;
import org.project.item.weapons.knife;
public class Goblin extends Enemy {
public Goblin(){
super(35 , 25 , new knife() , new EnemyArmor());
}
public void specialAbility(Entity target){
heavyattack(target);
//sout : crirtal
}
}
@@ -1,6 +1,26 @@
package org.project.entity.enemies; package org.project.entity.enemies;
// TODO: UPDATE IMPLEMENTATION
public class Skeleton { import org.project.entity.Entity;
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR import org.project.item.armors.EnemyArmor;
import org.project.item.weapons.wood;
public class Skeleton extends Enemy {
private boolean resurrect;
public Skeleton(){
super(50 , 30 , new wood() , new EnemyArmor());
this.resurrect =false;
}
public void specialAbility(Entity target){
if(this.isalive == false && this.resurrect == false){
this.isalive = true;
this.hp=25;
this.mp=15;
}
}
} }
@@ -0,0 +1,20 @@
package org.project.entity.enemies;
import org.project.entity.Entity;
import org.project.item.armors.EnemyArmor;
import org.project.item.weapons.wood;
public class Vampire extends Enemy{
public Vampire(){
super(60 , 25, new wood() , new EnemyArmor());
}
@Override
public void specialAbility(Entity target){
target.takeDamage(this.weapon.getDamage());
this.hp += this.weapon.getDamage() /2;
}
}
@@ -0,0 +1,21 @@
package org.project.entity.players;
import org.project.entity.Entity;
import org.project.item.armors.woodenArmor;
import org.project.item.weapons.knife;
public class Assassin extends Player{
public Assassin(String name){
super(name , 60 , 80 ,new knife(), new woodenArmor() , 8);
}
public void specialAbility(Entity target){
target.falsepossible();
// sout : na marei ;
heavyattack(target);
}
}
@@ -1,6 +1,21 @@
package org.project.entity.players; package org.project.entity.players;
// TODO: UPDATE IMPLEMENTATION
public class Knight { import org.project.entity.Entity;
// TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR import org.project.item.armors.KnightArmor;
import org.project.item.weapons.Sword;
public class Knight extends Player {
public Knight(String name){
super(name , 50 , 50 , new Sword() , new KnightArmor() ,10);
}
@Override
public void specialAbility(Entity target){
target.takeDamage(weapon.getDamage() + fistDamage);
target.falsepossible();
}
} }
@@ -4,49 +4,83 @@ import org.project.entity.Entity;
import org.project.item.armors.Armor; import org.project.item.armors.Armor;
import org.project.item.weapons.Weapon; import org.project.item.weapons.Weapon;
// TODO: UPDATE IMPLEMENTATION
public abstract class Player {
protected String name;
Weapon weapon;
Armor armor;
private int hp;
private int maxHP;
private int mp;
private int maxMP;
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) { public abstract class Player implements Entity {
protected String name;
protected Weapon weapon;
protected Armor armor;
protected int hp;
protected int maxHP;
protected int mp;
protected int maxMP;
protected int fistDamage;
protected boolean isDefending;
protected boolean isalive;
public Player(String name, int hp, int mp, Weapon weapon, Armor armor , int fistDamage) {
this.name = name; this.name = name;
this.hp = hp; this.hp = hp;
this.maxHP=hp;
this.mp = mp; this.mp = mp;
this.maxMP = mp;
this.weapon = weapon; this.weapon = weapon;
this.armor = armor; this.armor = armor;
this.isDefending=false;
this.fistDamage = fistDamage;
this.isalive=true;
}
@Override
public void lightattack(Entity target){
target.takeDamage(fistDamage);
} }
@Override @Override
public void attack(Entity target) { public void heavyattack(Entity target){
target.takeDamage(weapon.getDamage()); target.takeDamage(weapon.getDamage());
} }
@Override @Override
public void defend() { public void defend() {
// TODO isDefending =true;
} }
@Override @Override
public void takeDamage(int damage) { public void takeDamage(int damage) {
if(isDefending){
damage /= 2;
isDefending = false;
}
if(!armor.checkBreak()){
hp -= damage - armor.getDefense(); hp -= damage - armor.getDefense();
armor.use(this);
}
else {
hp -=damage;
}
} }
@Override @Override
public void heal(int health) { public void healHp(int health) {
hp += health; hp += health;
if (hp > maxHP) { if (hp > maxHP) {
hp = maxHP; hp = maxHP;
} }
} }
@Override
public void healMp(int mp) {
this.mp+= mp;
if (this.mp > maxMP) {
this.mp = maxMP;
}
}
@Override @Override
public void fillMana(int mana) { public void fillMana(int mana) {
mp += mana; mp += mana;
@@ -55,6 +89,8 @@ public abstract class Player {
} }
} }
public abstract void specialAbility(Entity target);
public String getName() { public String getName() {
return name; return name;
@@ -82,8 +118,17 @@ public abstract class Player {
return weapon; return weapon;
} }
public Armor getArmor() { public Armor getArmor() {
return armor; return armor;
} }
@Override
public boolean isalive(){
return isalive;
}
public void falsepossible(){}
public void truepossible(){}
} }
@@ -0,0 +1,18 @@
package org.project.entity.players;
import org.project.entity.Entity;
import org.project.item.armors.leatherArmor;
import org.project.item.weapons.wood;
public class Wizard extends Player{
public Wizard(String name){
super(name , 90 , 60 , new wood() , new leatherArmor() , 7 );
}
public void specialAbility(Entity target){
target.takeDamage(weapon.getDamage() + fistDamage);
this.healHp(30);
}
}
@@ -4,8 +4,4 @@ import org.project.entity.Entity;
public interface Item { public interface Item {
void use(Entity target); void use(Entity target);
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
} }
@@ -1,7 +1,10 @@
package org.project.item.armors; package org.project.item.armors;
import org.project.entity.Entity;
import org.project.item.Item;
// TODO: UPDATE IMPLEMENTATION // TODO: UPDATE IMPLEMENTATION
public abstract class Armor { public abstract class Armor implements Item {
private int defense; private int defense;
private int maxDefense; private int maxDefense;
private int durability; private int durability;
@@ -12,16 +15,31 @@ public abstract class Armor {
public Armor(int defense, int durability) { public Armor(int defense, int durability) {
this.defense = defense; this.defense = defense;
this.durability = durability; this.durability = durability;
this.maxDurability = durability;
this.maxDefense = defense;
} }
public void checkBreak() { public void use(Entity target){
durability -= defense;
}
public boolean checkBreak() {
if (durability <= 0) { if (durability <= 0) {
isBroke = true; isBroke = true;
defense = 0; defense = 0;
return true;
} }
else {
isBroke= false;
return false;
}
} }
// TODO: (BONUS) UPDATE THE REPAIR METHOD
public void repair() { public void repair() {
isBroke = false; isBroke = false;
defense = maxDefense; defense = maxDefense;
@@ -36,6 +54,14 @@ public abstract class Armor {
return durability; return durability;
} }
public void setMaxDefense(int maxDefense) {
this.maxDefense = maxDefense;
}
public void setMaxDurability(int maxDurability) {
this.maxDurability = maxDurability;
}
public boolean isBroke() { public boolean isBroke() {
return isBroke; return isBroke;
} }
@@ -0,0 +1,7 @@
package org.project.item.armors;
public class EnemyArmor extends Armor{
public EnemyArmor(){
super(2 , 10);
}
}
@@ -1,6 +1,9 @@
package org.project.item.armors; package org.project.item.armors;
// TODO: UPDATE IMPLEMENTATION // TODO: UPDATE IMPLEMENTATION
public class KnightArmor { public class KnightArmor extends Armor{
// TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
public KnightArmor(){
super(5 , 20);
}
} }
@@ -0,0 +1,7 @@
package org.project.item.armors;
public class leatherArmor extends Armor {
public leatherArmor(){
super(4 , 20);
}
}
@@ -0,0 +1,7 @@
package org.project.item.armors;
public class woodenArmor extends Armor{
public woodenArmor(){
super(4 , 16);
}
}
@@ -1,8 +1,11 @@
package org.project.item.consumables; package org.project.item.consumables;
// TODO: UPDATE IMPLEMENTATION import org.project.entity.Entity;
public abstract class Consumable { import org.project.item.Item;
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/ public abstract class Consumable implements Item {
public abstract void use(Entity target);
} }
@@ -2,15 +2,11 @@ package org.project.item.consumables;
import org.project.entity.Entity; import org.project.entity.Entity;
// TODO: UPDATE IMPLEMENTATION public class Flask extends Consumable {
public class Flask {
/*
THIS IS AN EXAMPLE OF A CONSUMABLE DESIGN.
*/
// TODO: UPDATE USE METHOD
@Override @Override
public void use(Entity target) { public void use(Entity target) {
target.heal(target.getMaxHP() / 10); target.healHp(target.getMaxHP() / 10);
} }
} }
@@ -0,0 +1,11 @@
package org.project.item.consumables;
import org.project.entity.Entity;
public class Teriak {
public void use(Entity target) {
target.healMp(target.getMaxMP() / 10);
}
}
@@ -0,0 +1,16 @@
package org.project.item.weapons;
import org.project.entity.Entity;
public class DragonWepon extends Weapon{
public DragonWepon(){
super(40 , 10);
}
public void use(Entity target){
target.takeDamage(this.getDamage()+ target.getArmor().getDefense());
}
}
@@ -4,23 +4,8 @@ import org.project.entity.Entity;
import java.util.ArrayList; import java.util.ArrayList;
// TODO: UPDATE IMPLEMENTATION public class Sword extends Weapon {
public class Sword {
/*
THIS IS AN EXAMPLE OF A WEAPON DESIGN.
*/
int abilityCharge;
public Sword() { public Sword() {
// TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR super( 20 , 8);
}
// TODO: (BONUS) UPDATE THE UNIQUE ABILITY
public void uniqueAbility(ArrayList<Entity> targets) {
abilityCharge += 2;
for (Entity target : targets) {
target.takeDamage(getDamage());
}
} }
} }
@@ -1,15 +1,12 @@
package org.project.item.weapons; package org.project.item.weapons;
import org.project.entity.Entity; import org.project.entity.Entity;
import org.project.item.Item;
// TODO: UPDATE IMPLEMENTATION public class Weapon implements Item {
public abstract class Weapon {
private int damage; private int damage;
private int manaCost; private int manaCost;
/*
TODO: ADD OTHER REQUIRED AND BONUS ATTRIBUTES
*/
public Weapon(int damage, int manaCost) { public Weapon(int damage, int manaCost) {
this.damage = damage; this.damage = damage;
@@ -29,7 +26,4 @@ public abstract class Weapon {
return manaCost; return manaCost;
} }
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
} }
@@ -0,0 +1,7 @@
package org.project.item.weapons;
public class knife extends Weapon{
public knife(){
super(15 , 8);
}
}
@@ -0,0 +1,8 @@
package org.project.item.weapons;
public class wood extends Weapon{
public wood(){
super(10, 8);
}
}
@@ -1,28 +1,29 @@
package org.project.location; package org.project.location;
import org.project.entity.enemies.Enemy; 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 java.util.ArrayList; import java.util.ArrayList;
public class Location { public class Location {
private String name; private String name;
private Enemy enemy;
private ArrayList<Enemy> enemies; public Location(String name) {
this.name=name;
public Location(ArrayList<Location> locations, ArrayList<Enemy> enemies) { int n = (int) (Math.random()) * 3 ;
this.locations = locations; if(n==0){
this.enemies = enemies; this.enemy = new Goblin();
}
if(n==1){
this.enemy = new Vampire();
}
if(n==2){
this.enemy = new Skeleton();
}
} }
public String getName() {
return name;
}
public ArrayList<Location> getLocations() {
return locations;
}
public ArrayList<Enemy> getEnemies() {
return enemies;
}
} }