add key logic

This commit is contained in:
2026-05-07 14:42:13 +03:30
parent 65a72039bc
commit b7c3086fd0
21 changed files with 84 additions and 8 deletions
@@ -1,15 +1,64 @@
package org.project;
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.KnightArmor;
import org.project.item.weapons.Sword;
import org.project.item.weapons.Weapon;
import org.project.location.Location;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO: ADD LOCATIONS TO YOUR GAME
Weapon wp = new Sword(12, 5);
ArrayList<Enemy> enemies = new ArrayList<>();
enemies.add(new Goblin(100, 100, wp));
enemies.add(new Skeleton(50, 100, wp));
enemies.add(new Vampire(90, 110, wp));
List<Location> locations = new ArrayList<>();
locations.add(new Location("Jungle", enemies));
Player player;
Enemy enemy;
int isTurn = 0;
Scanner sc = new Scanner(System.in);
// TODO: IMPLEMENT GAMEPLAY
while (true) {
System.out.print("1.Assassin\n2.Knight\n3.Wizard\nChoose your Character: ");
int choice = sc.nextInt();
switch (choice) {
case 1:
player = new Assassin("Pia", 100, 100, wp, new KnightArmor(50, 1));
System.out.println("You chose " + player.getName() + "(Assassin)");
break;
case 2:
player = new Knight("Khan", 200, 100, wp, new KnightArmor(80, 1));
System.out.println("You chose " + player.getName() + "(Knight)");
break;
default:
player = new Wizard("Daalou", 90, 100, wp, new KnightArmor(100, 1));
System.out.println("You chose " + player.getName() + "(Wizard)");
System.out.println();
}
break;
}
}
public void displayLocations(List<Location> locations) {
for (Location location : locations) {
System.out.println(location);
}
}
}
@@ -15,6 +15,8 @@ public abstract class Enemy implements Entity {
private boolean defending = false;
private double defendRate;
private double attackMultiplier = 1;
private boolean hasKey = false;
private static boolean keyFound = false;
public Enemy(int hp, int mp, Weapon weapon) {
this.hp = hp;
@@ -22,6 +24,12 @@ public abstract class Enemy implements Entity {
this.mp = mp;
this.maxMP = mp;
this.weapon = weapon;
if (!keyFound) {
hasKey = Math.random() < .2;
}
if (hasKey) {
keyFound = true;
}
}
//implement this in Main
private boolean checkTargetAbility(Player target) {
@@ -140,5 +148,14 @@ public abstract class Enemy implements Entity {
public void setAttackMultiplier(double multiplier) {
attackMultiplier = multiplier;
}
@Override
public String toString() {
return getClass().getSimpleName();
}
public boolean getHasKey() {
return hasKey;
}
}
@@ -17,6 +17,9 @@ public abstract class Player implements Entity, combatOptions {
private double defendRate;
private boolean isUsingSpecialAbility = false;
private double attackMultiplier = 1;
protected boolean hasGoblinKey = false;
protected boolean hasSkeletonKey = false;
protected boolean hasVampireKey = false;
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
this.name = name;
@@ -8,9 +8,9 @@ public class Flask {
THIS IS AN EXAMPLE OF A CONSUMABLE DESIGN.
*/
// TODO: UPDATE USE METHOD
@Override
public void use(Entity target) {
target.heal(target.getMaxHP() / 10);
}
// // TODO: UPDATE USE METHOD
// @Override
// public void use(Entity target) {
// target.heal(target.getMaxHP() / 10);
// }
}
@@ -9,8 +9,9 @@ public class Location {
private ArrayList<Enemy> enemies;
public Location(ArrayList<Enemy> enemies) {
public Location(String name, ArrayList<Enemy> enemies) {
this.enemies = enemies;
this.name = name;
}
public String getName() {
@@ -20,4 +21,10 @@ public class Location {
public ArrayList<Enemy> getEnemies() {
return enemies;
}
@Override
public String toString() {
String string = "Location: " + name + "| Enemies: " + enemies;
return string;
}
}
Binary file not shown.