complete code
This commit is contained in:
@@ -1,157 +1,274 @@
|
|||||||
package org.project.game;
|
package org.project;
|
||||||
|
|
||||||
|
import org.project.entity.players.Player;
|
||||||
|
import org.project.entity.players.Knight;
|
||||||
|
import org.project.entity.players.Wizard;
|
||||||
|
import org.project.entity.players.Assassin;
|
||||||
|
|
||||||
import org.project.entity.enemies.Enemy;
|
import org.project.entity.enemies.Enemy;
|
||||||
import org.project.entity.enemies.Goblin;
|
import org.project.entity.enemies.Goblin;
|
||||||
import org.project.entity.players.Knight;
|
import org.project.entity.enemies.Skeleton;
|
||||||
import org.project.entity.players.Player;
|
import org.project.entity.enemies.Vampire;
|
||||||
import org.project.entity.players.Warrior;
|
import org.project.entity.enemies.Dragon;
|
||||||
|
|
||||||
|
import org.project.item.Item;
|
||||||
|
|
||||||
import org.project.location.Location;
|
import org.project.location.Location;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.*;
|
||||||
|
|
||||||
public class setupGame {
|
public class GameEngine {
|
||||||
|
|
||||||
private Player player;
|
private Player player;
|
||||||
|
|
||||||
private Location currentLocation;
|
private Location currentLocation;
|
||||||
|
private Location castle;
|
||||||
|
|
||||||
private Scanner scanner;
|
private Scanner scanner;
|
||||||
|
|
||||||
public setupGame() {
|
private Map<Location, Enemy[]> possibleEnemiesMap = new HashMap<>();
|
||||||
|
|
||||||
|
private Enemy currentEnemy;
|
||||||
|
|
||||||
|
public GameEngine() {
|
||||||
scanner = new Scanner(System.in);
|
scanner = new Scanner(System.in);
|
||||||
|
|
||||||
setupGame();
|
setupGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupGame() {
|
private void setupGame() {
|
||||||
|
|
||||||
|
System.out.println("Choose your class:");
|
||||||
|
System.out.println("1. Knight");
|
||||||
|
System.out.println("2. Mage");
|
||||||
|
System.out.println("3. Assassin");
|
||||||
|
|
||||||
player = new Knight("Hero");
|
int choice = scanner.nextInt();
|
||||||
|
scanner.nextLine();
|
||||||
|
|
||||||
|
switch (choice) {
|
||||||
|
case 1:
|
||||||
|
player = new Knight("Hero");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
player = new Wizard("Hero");
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
player = new Assassin("Hero");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.out.println("Invalid choice, defaulting to Knight.");
|
||||||
|
player = new Knight("Hero");
|
||||||
|
}
|
||||||
|
|
||||||
// Create Locations
|
|
||||||
Location village = new Location("Village");
|
Location village = new Location("Village");
|
||||||
Location forest = new Location("Forest");
|
Location forest = new Location("Forest");
|
||||||
Location dungeon = new Location("Dungeon");
|
Location dungeon = new Location("Dungeon");
|
||||||
|
Location graveyard = new Location("Graveyard");
|
||||||
|
|
||||||
|
castle = new Location("Castle");
|
||||||
|
|
||||||
// Connect Locations
|
|
||||||
village.connectLocation(forest);
|
village.connectLocation(forest);
|
||||||
forest.connectLocation(village);
|
forest.connectLocation(village);
|
||||||
|
|
||||||
forest.connectLocation(dungeon);
|
forest.connectLocation(dungeon);
|
||||||
dungeon.connectLocation(forest);
|
dungeon.connectLocation(forest);
|
||||||
|
|
||||||
// Add Enemies
|
forest.connectLocation(graveyard);
|
||||||
forest.addEnemy(new Goblin());
|
graveyard.connectLocation(forest);
|
||||||
|
|
||||||
|
village.connectLocation(castle);
|
||||||
|
castle.connectLocation(village);
|
||||||
|
|
||||||
// Starting Location
|
|
||||||
currentLocation = village;
|
currentLocation = village;
|
||||||
|
|
||||||
|
possibleEnemiesMap.put(forest, new Enemy[] { new Goblin() });
|
||||||
|
possibleEnemiesMap.put(dungeon, new Enemy[] { new Skeleton(), new Vampire() });
|
||||||
|
possibleEnemiesMap.put(graveyard, new Enemy[] { new Skeleton(), new Vampire() });
|
||||||
|
possibleEnemiesMap.put(castle, new Enemy[] { new Dragon() });
|
||||||
|
|
||||||
|
spawnEnemyForLocation(currentLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void spawnEnemyForLocation(Location loc) {
|
||||||
|
Enemy[] possibilities = possibleEnemiesMap.get(loc);
|
||||||
|
if (possibilities == null || possibilities.length == 0) {
|
||||||
|
currentEnemy = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Random rand = new Random();
|
||||||
|
Enemy template = possibilities[rand.nextInt(possibilities.length)];
|
||||||
|
currentEnemy = createEnemyInstance(template);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Enemy createEnemyInstance(Enemy e) {
|
||||||
|
if (e instanceof Goblin) return new Goblin();
|
||||||
|
if (e instanceof Skeleton) return new Skeleton();
|
||||||
|
if (e instanceof Vampire) return new Vampire();
|
||||||
|
if (e instanceof Dragon) return new Dragon();
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startGame() {
|
public void startGame() {
|
||||||
|
|
||||||
boolean running = true;
|
|
||||||
|
|
||||||
System.out.println("=== RPG Game Started ===");
|
System.out.println("=== RPG Game Started ===");
|
||||||
|
|
||||||
|
boolean running = true;
|
||||||
|
|
||||||
while (running) {
|
while (running) {
|
||||||
|
|
||||||
System.out.println("\nCurrent Location: " + currentLocation.getName());
|
System.out.println("\n===== MENU =====");
|
||||||
|
|
||||||
System.out.println("1. Move");
|
System.out.println("Location: " + currentLocation.getName());
|
||||||
|
System.out.println("HP: " + player.getHp());
|
||||||
|
System.out.println("Mana: " + player.getMana());
|
||||||
|
System.out.println("Level: " + player.getLevel());
|
||||||
|
System.out.println("XP: " + player.getXp());
|
||||||
|
System.out.println("Keys: " + player.getKeyCount());
|
||||||
|
|
||||||
|
System.out.println("\n1. Move");
|
||||||
System.out.println("2. Fight");
|
System.out.println("2. Fight");
|
||||||
System.out.println("3. Show Inventory");
|
System.out.println("3. Show Inventory");
|
||||||
System.out.println("4. Exit");
|
System.out.println("4. Exit");
|
||||||
|
|
||||||
int choice = scanner.nextInt();
|
int choice = scanner.nextInt();
|
||||||
|
scanner.nextLine();
|
||||||
|
|
||||||
switch (choice) {
|
switch (choice) {
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
move();
|
move();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
fight();
|
fight();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
player.getInventory().showInventory();
|
player.getInventory().showInventory();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
running = false;
|
running = false;
|
||||||
System.out.println("Game Over.");
|
System.out.println("Game Over.");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
System.out.println("Invalid choice.");
|
System.out.println("Invalid choice.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!player.isAlive()) {
|
||||||
|
System.out.println("\nYou died. Game Over.");
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void move() {
|
private void move() {
|
||||||
|
|
||||||
if (currentLocation.getConnectedLocations().isEmpty()) {
|
if (currentLocation.getConnectedLocations().isEmpty()) {
|
||||||
System.out.println("No connected locations.");
|
System.out.println("No connected locations.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Where do you want to go?");
|
System.out.println("\nWhere do you want to go?");
|
||||||
|
|
||||||
for (int i = 0; i < currentLocation.getConnectedLocations().size(); i++) {
|
for (int i = 0; i < currentLocation.getConnectedLocations().size(); i++) {
|
||||||
|
System.out.println((i + 1) + ". " + currentLocation.getConnectedLocations().get(i).getName());
|
||||||
System.out.println(
|
|
||||||
(i + 1) + ". " +
|
|
||||||
currentLocation.getConnectedLocations().get(i).getName()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int choice = scanner.nextInt();
|
int choice = scanner.nextInt();
|
||||||
|
|
||||||
if (choice < 1 || choice > currentLocation.getConnectedLocations().size()) {
|
if (choice < 1 || choice > currentLocation.getConnectedLocations().size()) {
|
||||||
|
System.out.println("Invalid choice.");
|
||||||
System.out.println("Invalid location.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentLocation =
|
Location nextLocation = currentLocation.getConnectedLocations().get(choice - 1);
|
||||||
currentLocation.getConnectedLocations().get(choice - 1);
|
|
||||||
|
|
||||||
System.out.println("You moved to " + currentLocation.getName());
|
if (nextLocation == castle && player.getKeyCount() < 3) {
|
||||||
|
System.out.println("\nThe castle gate is locked!");
|
||||||
|
System.out.println("You need 3 keys.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentLocation = nextLocation;
|
||||||
|
|
||||||
|
spawnEnemyForLocation(currentLocation);
|
||||||
|
|
||||||
|
System.out.println("\nYou moved to " + currentLocation.getName());
|
||||||
|
|
||||||
|
if (currentLocation == castle) {
|
||||||
|
System.out.println("\nThe final battle awaits...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fight() {
|
private void fight() {
|
||||||
|
if (currentEnemy == null || !currentEnemy.isAlive()) {
|
||||||
if (currentLocation.getEnemies().isEmpty()) {
|
|
||||||
|
|
||||||
System.out.println("No enemies here.");
|
System.out.println("No enemies here.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Enemy enemy = currentLocation.getEnemies().get(0);
|
Enemy enemy = currentEnemy;
|
||||||
|
|
||||||
System.out.println("A wild " + enemy.getName() + " appeared!");
|
System.out.println("\nA wild " + enemy.getName() + " appeared!");
|
||||||
|
|
||||||
while (player.isAlive() && enemy.isAlive()) {
|
while (player.isAlive() && enemy.isAlive()) {
|
||||||
|
|
||||||
player.lightAttack(enemy);
|
System.out.println("\n===== COMBAT =====");
|
||||||
|
System.out.println(player.getName() + " HP: " + player.getHp());
|
||||||
|
System.out.println(enemy.getName() + " HP: " + enemy.getHp());
|
||||||
|
|
||||||
|
System.out.println("\nChoose action:");
|
||||||
|
System.out.println("1. Light Attack");
|
||||||
|
System.out.println("2. Heavy Attack");
|
||||||
|
System.out.println("3. Defend");
|
||||||
|
System.out.println("4. Heal");
|
||||||
|
System.out.println("5. Special Ability");
|
||||||
|
|
||||||
|
int choice = scanner.nextInt();
|
||||||
|
scanner.nextLine();
|
||||||
|
|
||||||
|
switch (choice) {
|
||||||
|
case 1:
|
||||||
|
player.lightAttack(enemy);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
player.heavyAttack(enemy);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
player.defend();
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
player.heal();
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
player.specialAbility(enemy);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.out.println("Invalid choice.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (enemy.isAlive()) {
|
if (enemy.isAlive()) {
|
||||||
|
System.out.println("\n" + enemy.getName() + "'s turn!");
|
||||||
enemy.attack(player);
|
enemy.attack(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!enemy.isAlive()) {
|
if (!enemy.isAlive()) {
|
||||||
|
System.out.println("\n" + enemy.getName() + " was defeated!");
|
||||||
|
|
||||||
System.out.println(enemy.getName() + " defeated!");
|
player.gainXP(enemy.getXpReward());
|
||||||
|
|
||||||
currentLocation.removeEnemy(enemy);
|
Item loot = enemy.dropLoot();
|
||||||
}
|
|
||||||
|
|
||||||
if (!player.isAlive()) {
|
if (loot != null) {
|
||||||
|
player.getInventory().addItem(loot);
|
||||||
|
System.out.println(enemy.getName() + " dropped: " + loot.getName());
|
||||||
|
}
|
||||||
|
|
||||||
System.out.println("You died.");
|
currentEnemy = null;
|
||||||
|
|
||||||
|
if (enemy instanceof Dragon) {
|
||||||
|
System.out.println("\n====================");
|
||||||
|
System.out.println("YOU DEFEATED THE DRAGON!");
|
||||||
|
System.out.println("====== YOU WIN ======");
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,46 @@
|
|||||||
package org.project;
|
package org.project.inventory;
|
||||||
|
|
||||||
|
import org.project.item.Item;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class Inventory {
|
public class Inventory {
|
||||||
|
|
||||||
|
private ArrayList<Item> items;
|
||||||
|
|
||||||
|
public Inventory() {
|
||||||
|
items = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addItem(Item item) {
|
||||||
|
|
||||||
|
items.add(item);
|
||||||
|
|
||||||
|
System.out.println(item.getName() + " added to inventory.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeItem(Item item) {
|
||||||
|
items.remove(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Item> getItems() {
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showInventory() {
|
||||||
|
|
||||||
|
if(items.isEmpty()) {
|
||||||
|
System.out.println("Inventory is empty.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("=== Inventory ===");
|
||||||
|
|
||||||
|
for(int i = 0; i < items.size(); i++) {
|
||||||
|
|
||||||
|
System.out.println(
|
||||||
|
(i + 1) + ". " + items.get(i).getName()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,10 @@
|
|||||||
package org.project;
|
package org.project;
|
||||||
|
|
||||||
import org.project.location.Location;
|
import org.project.GameEngine;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
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
|
GameEngine game = new GameEngine();
|
||||||
List<Location> locations = new ArrayList<>();
|
game.startGame();
|
||||||
|
|
||||||
// TODO: IMPLEMENT GAMEPLAY
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,16 @@
|
|||||||
package org.project.entity.players;
|
package org.project.entity.players;
|
||||||
|
|
||||||
public class CombatActions {
|
import org.project.entity.Entity;
|
||||||
|
|
||||||
|
public interface CombatActions {
|
||||||
|
|
||||||
|
void lightAttack(Entity target);
|
||||||
|
|
||||||
|
void heavyAttack(Entity target);
|
||||||
|
|
||||||
|
void defend();
|
||||||
|
|
||||||
|
void heal();
|
||||||
|
|
||||||
|
void specialAbility(Entity target);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,8 @@ package org.project.item;
|
|||||||
import org.project.entity.Entity;
|
import org.project.entity.Entity;
|
||||||
|
|
||||||
public interface Item {
|
public interface Item {
|
||||||
void use(Entity target);
|
|
||||||
|
|
||||||
/*
|
String getName();
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
|
||||||
*/
|
void use(Entity target);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,24 @@
|
|||||||
package org.project.item;
|
package org.project.item;
|
||||||
|
|
||||||
public class Key {
|
import org.project.entity.Entity;
|
||||||
|
import org.project.item.Item;
|
||||||
|
|
||||||
|
public class Key implements Item {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public Key(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void use(Entity target) {
|
||||||
|
|
||||||
|
System.out.println("This key is used automatically to unlock the castle.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package org.project.item.armors;
|
package org.project.item.armors;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
|
||||||
public abstract class Armor {
|
public abstract class Armor {
|
||||||
|
|
||||||
private int defense;
|
private int defense;
|
||||||
private int maxDefense;
|
private int maxDefense;
|
||||||
private int durability;
|
private int durability;
|
||||||
@@ -14,16 +14,23 @@ public abstract class Armor {
|
|||||||
this.durability = durability;
|
this.durability = durability;
|
||||||
this.maxDefense = defense;
|
this.maxDefense = defense;
|
||||||
this.maxDurability = durability;
|
this.maxDurability = durability;
|
||||||
|
this.isBroke = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkBreak() {
|
public void checkBreak() {
|
||||||
if (durability <= 0) {
|
if (durability <= 0) {
|
||||||
|
durability = 0;
|
||||||
isBroke = true;
|
isBroke = true;
|
||||||
defense = 0;
|
defense = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: (BONUS) UPDATE THE REPAIR METHOD
|
public void takeDamage(int amount) {
|
||||||
|
durability -= amount;
|
||||||
|
checkBreak();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void repair() {
|
public void repair() {
|
||||||
isBroke = false;
|
isBroke = false;
|
||||||
defense = maxDefense;
|
defense = maxDefense;
|
||||||
@@ -31,6 +38,9 @@ public abstract class Armor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getDefense() {
|
public int getDefense() {
|
||||||
|
if (isBroke) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return defense;
|
return defense;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
package org.project.item.armors;
|
package org.project.item.armors;
|
||||||
|
|
||||||
public class AssassinArmor {
|
public class AssassinArmor extends Armor {
|
||||||
|
public AssassinArmor(){
|
||||||
|
super(5,25);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package org.project.item.armors;
|
package org.project.item.armors;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
public class KnightArmor extends Armor {
|
||||||
public class KnightArmor {
|
|
||||||
// TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
|
public KnightArmor() {
|
||||||
|
super(8, 40);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
package org.project.item.armors;
|
package org.project.item.armors;
|
||||||
|
|
||||||
public class MageArmor {
|
public class MageArmor extends Armor{
|
||||||
|
public MageArmor(){
|
||||||
|
super(2,15);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,17 @@
|
|||||||
package org.project.item.consumables;
|
package org.project.item.consumables;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
import org.project.item.Item;
|
||||||
public abstract class Consumable {
|
|
||||||
/*
|
public abstract class Consumable implements Item {
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
|
||||||
*/
|
private String name;
|
||||||
|
|
||||||
|
public Consumable(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,33 @@ 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 {
|
|
||||||
/*
|
private int healAmount;
|
||||||
THIS IS AN EXAMPLE OF A CONSUMABLE DESIGN.
|
|
||||||
*/
|
public Flask() {
|
||||||
|
super("Flask");
|
||||||
|
this.healAmount = 30;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: UPDATE USE METHOD
|
|
||||||
@Override
|
@Override
|
||||||
public void use(Entity target) {
|
public void use(Entity target) {
|
||||||
target.heal(target.getMaxHP() / 10);
|
|
||||||
|
target.heal(healAmount);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(
|
||||||
|
target.getName() +
|
||||||
|
" drinks a flask and restores " +
|
||||||
|
healAmount + " HP."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHealAmount() {
|
||||||
|
return healAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHealAmount(int healAmount) {
|
||||||
|
this.healAmount = healAmount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,28 @@
|
|||||||
package org.project.item.weapons;
|
package org.project.item.weapons;
|
||||||
|
|
||||||
public class Dragger {
|
import org.project.entity.Entity;
|
||||||
|
|
||||||
|
public class Dagger extends Weapon {
|
||||||
|
|
||||||
|
public Dagger() {
|
||||||
|
super(10, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Dagger";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void use(Entity target) {
|
||||||
|
int damage = getDamage();
|
||||||
|
|
||||||
|
if (target.isDefending()) {
|
||||||
|
damage /= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
target.setHp(target.getHp() - damage);
|
||||||
|
|
||||||
|
System.out.println("Dagger deals " + damage + " damage to " + target.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,28 @@
|
|||||||
package org.project.item.weapons;
|
package org.project.item.weapons;
|
||||||
|
|
||||||
public class Staff {
|
import org.project.entity.Entity;
|
||||||
|
|
||||||
|
public class Staff extends Weapon {
|
||||||
|
|
||||||
|
public Staff() {
|
||||||
|
super(12, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return " Staff";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void use(Entity target) {
|
||||||
|
int damage = getDamage();
|
||||||
|
|
||||||
|
if (target.isDefending()) {
|
||||||
|
damage /= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
target.setHp(target.getHp() - damage);
|
||||||
|
|
||||||
|
System.out.println("Staff deals " + damage + " damage to " + target.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,25 +2,27 @@ package org.project.item.weapons;
|
|||||||
|
|
||||||
import org.project.entity.Entity;
|
import org.project.entity.Entity;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
public class Sword extends Weapon {
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
|
||||||
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(15, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: (BONUS) UPDATE THE UNIQUE ABILITY
|
@Override
|
||||||
public void uniqueAbility(ArrayList<Entity> targets) {
|
public String getName() {
|
||||||
abilityCharge += 2;
|
return "Sword";
|
||||||
for (Entity target : targets) {
|
}
|
||||||
target.takeDamage(getDamage());
|
|
||||||
|
@Override
|
||||||
|
public void use(Entity target) {
|
||||||
|
int damage = getDamage();
|
||||||
|
|
||||||
|
if (target.isDefending()) {
|
||||||
|
damage /= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
target.setHp(target.getHp() - damage);
|
||||||
|
|
||||||
|
System.out.println("Sword deals " + damage + " damage to " + target.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,18 @@
|
|||||||
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;
|
||||||
|
|
||||||
public abstract class Weapon {
|
public abstract class Weapon implements Item {
|
||||||
protected int damage;
|
|
||||||
protected int manaCost;
|
|
||||||
|
|
||||||
|
private int damage;
|
||||||
|
private int manaCost;
|
||||||
|
|
||||||
public Weapon(int damage, int manaCost) {
|
public Weapon(int damage, int manaCost) {
|
||||||
this.damage = damage;
|
this.damage = damage;
|
||||||
this.manaCost = manaCost;
|
this.manaCost = manaCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void use(Entity target);
|
|
||||||
|
|
||||||
public int getDamage() {
|
public int getDamage() {
|
||||||
return damage;
|
return damage;
|
||||||
}
|
}
|
||||||
@@ -22,5 +21,14 @@ public abstract class Weapon {
|
|||||||
return manaCost;
|
return manaCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDamage(int damage) {
|
||||||
|
this.damage = damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setManaCost(int manaCost) {
|
||||||
|
this.manaCost = manaCost;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public abstract void use(Entity target);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,24 +5,40 @@ import org.project.entity.enemies.Enemy;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class Location {
|
public class Location {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
private ArrayList<Location> connectedLocations;
|
||||||
|
|
||||||
private ArrayList<Enemy> enemies;
|
private ArrayList<Enemy> enemies;
|
||||||
|
|
||||||
public Location(ArrayList<Location> locations, ArrayList<Enemy> enemies) {
|
public Location(String name) {
|
||||||
this.locations = locations;
|
this.name = name;
|
||||||
this.enemies = enemies;
|
this.connectedLocations = new ArrayList<>();
|
||||||
|
this.enemies = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Location> getLocations() {
|
public ArrayList<Location> getConnectedLocations() {
|
||||||
return locations;
|
return connectedLocations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Enemy> getEnemies() {
|
public ArrayList<Enemy> getEnemies() {
|
||||||
return enemies;
|
return enemies;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void connectLocation(Location location) {
|
||||||
|
connectedLocations.add(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addEnemy(Enemy enemy) {
|
||||||
|
enemies.add(enemy);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeEnemy(Enemy enemy) {
|
||||||
|
enemies.remove(enemy);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user