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