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);
}
}
}