update enemies

This commit is contained in:
2026-05-08 13:37:15 +03:30
parent ed41752409
commit 5e023fa6cd
10 changed files with 130 additions and 68 deletions
+28 -44
View File
@@ -20,11 +20,11 @@ import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Weapon wp = new Sword(12, 15);
Weapon wp = new Sword();
ArrayList<Player> players = new ArrayList<>();
players.add(new Assassin("Pia", 100, 100, wp, new KnightArmor(8, 1)));
players.add(new Knight("Khan", 100, 120, wp, new KnightArmor(12, 1)));
players.add(new Wizard("Daalou", 100, 90, wp, new KnightArmor(15, 1)));
players.add(new Assassin(new KnightArmor(8, 1)));
players.add(new Knight());
players.add(new Wizard(new KnightArmor(2,1)));
ArrayList<Enemy> enemies = new ArrayList<>();
enemies.add(new Goblin(80, 100, wp));
enemies.add(new Skeleton(70, 100, wp));
@@ -33,21 +33,20 @@ public class Main {
locations.add(new Location("Jungle", enemies));
locations.add(new Location("China", new ArrayList<>(enemies.subList(0, 2))));
locations.add(new Location("Iran", new ArrayList<>(enemies.subList(1, 3))));
Player player = null;
Enemy enemy = null;
Location location = null;
int isTurn = 0;
Player player;
Enemy enemy;
Location location;
Scanner sc = new Scanner(System.in);
while (true) {
player = choosePlayer(players);
player = choosePlayer(players,sc);
while (true) {
location = chooseLocation(locations);
location = chooseLocation(locations,sc);
enemy = chooseEnemy(location);
System.out.println("wanna fight?\n1.Yes\n2.No");
int choice = sc.nextInt();
if (choice == 1) {
combat(player,enemy);
combat(player,enemy,sc);
System.out.println("player AHP: " + player.getHP());
break;
}
@@ -68,44 +67,30 @@ public class Main {
}
}
public static Player choosePlayer(ArrayList<Player> players) {
public static Player choosePlayer(ArrayList<Player> players, Scanner sc) {
System.out.print("1.Assassin\n2.Knight\n3.Wizard\nChoose your Character: ");
Scanner sc = new Scanner(System.in);
int choice = sc.nextInt();
Player player = null;
Player player;
switch (choice) {
case 1:
player = players.get(0);
break;
case 2:
player = players.get(1);
break;
default:
player = players.get(2);
break;
case 1 -> player = players.get(0);
case 2 -> player = players.get(1);
default -> player = players.get(2);
}
System.out.println("You chose " + player.getName() + "(" + player.getClass().getSimpleName() + ")");
return player;
}
public static Location chooseLocation(ArrayList<Location> locations) {
public static Location chooseLocation(ArrayList<Location> locations, Scanner sc) {
displayLocations(locations);
System.out.print("1.Jungle\n2.Iran\n3.China\nChoose Location: ");
Scanner sc = new Scanner(System.in);
System.out.print("1.Jungle\n2.China\n3.Iran\nChoose Location: ");
int choice = sc.nextInt();
Location location = null;
switch (choice) {
case 1:
location = locations.get(0);
break;
case 2:
location = locations.get(1);
break;
case 3:
location = locations.get(2);
break;
case 1 -> location = locations.get(0);
case 2 -> location = locations.get(1);
case 3 -> location = locations.get(2);
}
System.out.println("You chose " + location.getName() );
return location;
@@ -114,12 +99,11 @@ public class Main {
public static Enemy chooseEnemy(Location location) {
int random = new Random().nextInt(location.getEnemies().size());
Enemy enemy = location.getEnemies().get(random);
System.out.println("The Enemey is: " + enemy.getClass().getSimpleName());
System.out.println("The Enemy is: " + enemy.getClass().getSimpleName());
return enemy;
}
public static void combat(Player player, Enemy enemy) {
Scanner sc = new Scanner(System.in);
public static void combat(Player player, Enemy enemy, Scanner sc) {
int turn = 0;
int choice;
while (player.isAlive() && enemy.isAlive()) {
@@ -173,16 +157,16 @@ public class Main {
switch (choice) {
case 0:
enemy.attack(player);
if (player.isSuccessful()) break;
if (enemy.isSuccessful()) break;
else {turn = 1; continue;}
case 1:
enemy.defend();
if (player.isSuccessful()) break;
else {turn = 0; continue;}
if (enemy.isSuccessful()) break;
else {turn = 1; continue;}
case 2:
enemy.heal(10);
if (player.isSuccessful()) break;
else {turn = 0; continue;}
if (enemy.isSuccessful()) break;
else {turn = 1; continue;}
}
}
System.out.println("[" + player.getClass().getSimpleName() + " - " + player.getHP() + "/" + player.getMaxHP()
@@ -198,7 +182,7 @@ public class Main {
System.out.println("You Won!");
if (enemy.dropKey()) {
System.out.println(enemy.getClass().getSimpleName() + "'s key dropped!");
player.achiveKey(enemy);
player.achieveKey(enemy);
}
}
}
@@ -3,19 +3,27 @@ package org.project.entity.players;
import org.project.entity.Entity;
import org.project.item.armors.Armor;
import org.project.item.weapons.Dagger;
import org.project.item.weapons.Sword;
import org.project.item.weapons.Weapon;
public class Assassin extends Player {
public Assassin(String name, int hp, int mp, Weapon weapon, Armor armor) {
super(name, hp, mp, weapon, armor);
public Assassin(Armor armor) {
super("ASSASSIN",100,100, new Dagger(), armor);
setDefendRate(.7);
}
@Override
public void lightAttack(Entity target) {
super.lightAttack(target);
attack(target);
if (((Dagger) weapon).critical()){
setAttackMultiplier(1.5);
attack(target);
setAttackMultiplier(1);
} else {
attack(target);
}
}
@Override
@@ -3,19 +3,28 @@ package org.project.entity.players;
import org.project.entity.Entity;
import org.project.item.armors.Armor;
import org.project.item.armors.KnightArmor;
import org.project.item.weapons.Dagger;
import org.project.item.weapons.Sword;
import org.project.item.weapons.Weapon;
public class Knight extends Player {
public Knight(String name, int hp, int mp, Weapon weapon, Armor armor) {
super(name, hp, mp, weapon, armor);
public Knight() {
super("Knight",100,90, new Sword(), new KnightArmor(10,1));
setDefendRate(.9);
}
@Override
public void lightAttack(Entity target) {
super.lightAttack(target);
attack(target);
if (((Sword) weapon).charge()){
setAttackMultiplier(1.4);
attack(target);
setAttackMultiplier(1);
} else {
attack(target);
}
}
@Override
@@ -183,7 +183,7 @@ public abstract class Player implements Entity, combatOptions {
public boolean HasSkeletonKey() { return hasSkeletonKey; }
public boolean HasVampireKey() { return hasVampireKey; }
public void achiveKey(Entity target) {
public void achieveKey(Entity target) {
if ( target instanceof Goblin) { hasGoblinKey = true; }
else if (target instanceof Skeleton) { hasSkeletonKey = true; }
else { hasVampireKey = true; }
@@ -2,19 +2,28 @@ package org.project.entity.players;
import org.project.entity.Entity;
import org.project.item.armors.Armor;
import org.project.item.weapons.Bow;
import org.project.item.weapons.Sword;
import org.project.item.weapons.Weapon;
public class Wizard extends Player{
public Wizard(String name, int hp, int mp, Weapon weapon, Armor armor) {
super(name,hp,mp,weapon,armor);
public Wizard(Armor armor) {
super("Wizard",90,90,new Bow(),armor);
setDefendRate(.6);
}
@Override
public void lightAttack(Entity target) {
super.lightAttack(target);
attack(target);
if (((Bow) weapon).charge()){
setAttackMultiplier(1.4);
attack(target);
attack(target);
setAttackMultiplier(1);
} else {
attack(target);
}
}
@Override
@@ -4,4 +4,7 @@ import org.project.entity.Entity;
public interface Item {
String getName();
void use();
}
@@ -0,0 +1,21 @@
package org.project.item.weapons;
public class Bow extends Weapon{
private int abilityCharge;
private static int MAX_CHARGE = 4;
public Bow() {
super("Bow",15,25);
}
public boolean charge() {
abilityCharge++;
if (abilityCharge >= MAX_CHARGE) {
abilityCharge = 0;
System.out.println("Charged Strike!");
return true;
}
return false;
}
}
@@ -0,0 +1,16 @@
package org.project.item.weapons;
public class Dagger extends Weapon{
private static final int CRIT_CHANCE = 30;
private boolean isCrit = (int)(Math.random() * 100) < CRIT_CHANCE;
public Dagger() {
super("Dagger",8,15);
}
public boolean critical() {
if (isCrit) System.out.println("Critical Hit");
return isCrit;
}
}
@@ -4,24 +4,24 @@ import org.project.entity.Entity;
import java.util.ArrayList;
// TODO: UPDATE IMPLEMENTATION
public class Sword extends Weapon{
/*
THIS IS AN EXAMPLE OF A WEAPON DESIGN.
*/
int abilityCharge;
private int abilityCharge;
private static int MAX_CHARGE = 3;
public Sword(int damage, int manacost ) {
// TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
super(damage, manacost);
public Sword() {
super("Sword",12,10);
}
// TODO: (BONUS) UPDATE THE UNIQUE ABILITY
public void uniqueAbility(ArrayList<Entity> targets) {
abilityCharge += 2;
for (Entity target : targets) {
target.takeDamage(1);
public boolean charge() {
abilityCharge++;
if (abilityCharge >= MAX_CHARGE) {
abilityCharge = 0;
System.out.println("Charged Strike!");
return true;
}
return false;
}
}
@@ -5,10 +5,12 @@ import org.project.item.Item;
public abstract class Weapon implements Item {
private String name;
private int damage;
private int manaCost;
public Weapon(int damage, int manaCost) {
public Weapon(String name, int damage, int manaCost) {
this.name = name;
this.damage = damage;
this.manaCost = manaCost;
}
@@ -21,5 +23,15 @@ public abstract class Weapon implements Item {
return manaCost;
}
@Override
public String getName() {
return name;
}
@Override
public void use() {
System.out.println(getName() + " equipped!");
}
}