1 Commits
Author SHA1 Message Date
Ramtin d66dab9fce fix engines bugs 2026-07-15 17:24:38 +03:30
12 changed files with 111 additions and 210 deletions
@@ -3,6 +3,6 @@ package org.project.Interface;
import org.project.entity.Entity; import org.project.entity.Entity;
public interface IAttachable { public interface IAttachable {
public void AttachTo(Entity entity, boolean fromInventory); public void AttachTo(Entity entity);
public void DeattachFrom(Entity entity, boolean toInventory); public void DeattachFrom(Entity entity);
} }
@@ -1,49 +1,15 @@
package org.project; package org.project;
import org.project.constants.appConstants.GameModes; import org.project.location.Location;
import org.project.constants.appConstants.TextColor;
import org.project.engine.MainEngine;
import java.util.Scanner; import java.util.ArrayList;
import java.util.List;
public class Main { public class Main {
static void main(String[] args) { public static void main(String[] args) {
Scanner scanner = new Scanner(System.in); // TODO: ADD LOCATIONS TO YOUR GAME
boolean endGame = false; List<Location> locations = new ArrayList<>();
while (true) { // TODO: IMPLEMENT GAMEPLAY
System.out.println(TextColor.Cyan + "JAVA KNIGHT" + TextColor.Reset);
System.out.println(
"""
0 > Single Player
1 > Local Multiplayer
2 > Exit
"""
);
GameModes gameMode = null;
while (true){
int choice = scanner.nextInt();
if (choice == 0) {
gameMode = GameModes.SINGLE_PLAYER;
break;
} else if (choice == 1) {
gameMode = GameModes.MULTI_PLAYER_LOCAL;
break;
} else if (choice == 2) {
endGame = true;
break;
}
}
if (endGame) {
break;
}
MainEngine engine = MainEngine.CreateEngine(gameMode);
engine.run();
}
} }
} }
@@ -43,7 +43,6 @@ public abstract class MainEngine {
while (true) { while (true) {
for (PlayerRoles role : roles) { for (PlayerRoles role : roles) {
System.out.println(index + " > " + role.name().toLowerCase()); System.out.println(index + " > " + role.name().toLowerCase());
index++;
} }
int choice = scanner.nextInt(); int choice = scanner.nextInt();
@@ -13,8 +13,8 @@ import java.util.Hashtable;
import java.util.Scanner; import java.util.Scanner;
public class MultiPlayerBattleEngine extends BattleEngine { public class MultiPlayerBattleEngine extends BattleEngine {
private final Player player1; private Player player1;
private final Player player2; private Player player2;
private Player player1Past; private Player player1Past;
private Player player2Past; private Player player2Past;
@@ -28,61 +28,52 @@ public class MultiPlayerBattleEngine extends BattleEngine {
@Override @Override
public void StartBattle() { public void StartBattle() {
EntityDiff playerDiff;
EntityDiff enemyDiff;
while (true) { while (true) {
if (player1.GetState() != EntityState.FROZEN) { FightMoves player1Move = PlayerMovesMenu(player1, player2);
FightMoves player1Move = PlayerMovesMenu(player1, player2); showMoveExplanation(player1Move, player1, player2);
showMoveExplanation(player1Move, player1, player2Past);
playerDiff = getPlayerDiff(player1Past, player1);
enemyDiff = getPlayerDiff(player2Past, player2);
System.out.println();
showFighter(playerDiff, player1);
showFighter(enemyDiff, player2);
System.out.println();
}
if (player1.GetState() == EntityState.DEAD) {
System.out.println(TextColor.Green + player2.Name + " WON!" + TextColor.Reset);
return;
}
if (player1Past.GetState() == EntityState.FROZEN) { if (player1Past.GetState() == EntityState.FROZEN) {
player1.SetState(EntityState.ALIVE); player1.SetState(EntityState.ALIVE);
} }
EntityDiff playerDiff = getPlayerDiff(player1Past, player1);
EntityDiff enemyDiff = getPlayerDiff(player2Past, player2);
System.out.println();
showFighter(playerDiff, player1);
showFighter(enemyDiff, player2);
System.out.println();
player1Past = player1.copy(); player1Past = player1.copy();
player2Past = player2.copy(); player2Past = player2.copy();
FightMoves player2Move = PlayerMovesMenu(player2, player1);
if (player2.GetState() != EntityState.FROZEN) showMoveExplanation(player2Move, player2, player1);
{
FightMoves player2Move = PlayerMovesMenu(player2, player1);
showMoveExplanation(player2Move, player2, player1Past);
playerDiff = getPlayerDiff(player1Past, player1);
enemyDiff = getPlayerDiff(player2Past, player2);
System.out.println();
showFighter(playerDiff, player1);
showFighter(enemyDiff, player2);
System.out.println();
}
if (player2.GetState() == EntityState.DEAD) {
System.out.println(TextColor.Green + player1.Name + " WON!" + TextColor.Reset);
return;
}
if (player2Past.GetState() == EntityState.FROZEN) { if (player2Past.GetState() == EntityState.FROZEN) {
player2.SetState(EntityState.ALIVE); player2.SetState(EntityState.ALIVE);
} }
playerDiff = getPlayerDiff(player1Past, player1);
enemyDiff = getPlayerDiff(player2Past, player2);
System.out.println();
showFighter(playerDiff, player1);
showFighter(enemyDiff, player2);
System.out.println();
player1Past = player1.copy(); player1Past = player1.copy();
player2Past = player2.copy(); player2Past = player2.copy();
if (player2.GetState() == EntityState.DEAD) {
System.out.println(TextColor.Green + player1.Name + " WON!" + TextColor.Reset);
return;
}
else if (player1.GetState() == EntityState.DEAD) {
System.out.println(TextColor.Green + player2.Name + " WON!" + TextColor.Reset);
return;
}
} }
} }
@@ -14,8 +14,8 @@ import java.util.Hashtable;
import java.util.Scanner; import java.util.Scanner;
public class SinglePlayerBattleEngine extends BattleEngine { public class SinglePlayerBattleEngine extends BattleEngine {
private final Player player; private Player player;
private final Enemy enemy; private Enemy enemy;
private Player playerPast; private Player playerPast;
private Enemy enemyPast; private Enemy enemyPast;
public SinglePlayerBattleEngine(Player player, Enemy enemy) { public SinglePlayerBattleEngine(Player player, Enemy enemy) {
@@ -28,53 +28,28 @@ public class SinglePlayerBattleEngine extends BattleEngine {
@Override @Override
public void StartBattle() { public void StartBattle() {
EntityDiff playerDiff;
EntityDiff enemyDiff;
while (true) { while (true) {
if (player.GetState() != EntityState.FROZEN) { FightMoves playerMove = PlayerMovesMenu();
FightMoves playerMove = PlayerMovesMenu(); showMoveExplanation(playerMove, player, enemy);
showMoveExplanation(playerMove, player, enemyPast);
playerDiff = getPlayerDiff(playerPast, player);
enemyDiff = getPlayerDiff(enemyPast, enemy);
System.out.println();
showFighter(playerDiff, player);
showFighter(enemyDiff, enemy);
System.out.println();
}
if (playerPast.GetState() == EntityState.FROZEN) { if (playerPast.GetState() == EntityState.FROZEN) {
player.SetState(EntityState.ALIVE); player.SetState(EntityState.ALIVE);
} }
if (player.GetState() == EntityState.DEAD) {
return;
}
playerPast = player.copy(); playerPast = player.copy();
enemyPast = enemy.copy(); enemyPast = enemy.copy();
if (enemy.GetState() != EntityState.FROZEN) { EntityDiff playerDiff = getPlayerDiff(playerPast, player);
FightMoves botMove = enemy.PlayRound(player); EntityDiff enemyDiff = getPlayerDiff(enemyPast, enemy);
showMoveExplanation(botMove, enemy, playerPast);
playerDiff = getPlayerDiff(playerPast, player); System.out.println();
enemyDiff = getPlayerDiff(enemyPast, enemy); showFighter(playerDiff, player);
showFighter(enemyDiff, enemy);
System.out.println();
System.out.println(); FightMoves botMove = enemy.PlayRound(player);
showFighter(playerDiff, player); showMoveExplanation(botMove, enemy, player);
showFighter(enemyDiff, enemy);
System.out.println();
}
if (enemy.GetState() == EntityState.DEAD) {
enemy.DropLoot(player);
player.AddLevelProgress(enemy.LevelProgressAmount);
System.out.println(TextColor.Green + player.Name + " WON!" + TextColor.Reset);
return;
}
if (enemyPast.GetState() == EntityState.FROZEN) { if (enemyPast.GetState() == EntityState.FROZEN) {
enemy.SetState(EntityState.ALIVE); enemy.SetState(EntityState.ALIVE);
@@ -82,6 +57,24 @@ public class SinglePlayerBattleEngine extends BattleEngine {
playerPast = player.copy(); playerPast = player.copy();
enemyPast = enemy.copy(); enemyPast = enemy.copy();
playerDiff = getPlayerDiff(playerPast, player);
enemyDiff = getPlayerDiff(enemyPast, enemy);
System.out.println();
showFighter(playerDiff, player);
showFighter(enemyDiff, enemy);
System.out.println();
if (enemy.GetState() == EntityState.DEAD) {
enemy.DropLoot(player);
player.AddLevelProgress(enemy.LevelProgressAmount);
System.out.println(TextColor.Green + player.Name + " WON!" + TextColor.Reset);
return;
}
else if (player.GetState() == EntityState.DEAD) {
return;
}
} }
} }
@@ -29,10 +29,10 @@ public class SinglePlayerEngine extends MainEngine {
System.out.println(TextColor.Cyan + GetIntro() + ConsoleColor.Reset); System.out.println(TextColor.Cyan + GetIntro() + ConsoleColor.Reset);
System.out.println(); System.out.println();
System.out.println("How should we call you, hero? "); System.out.println("How should me call you, hero? ");
String name = scanner.nextLine(); String name = scanner.nextLine();
System.out.println("Greetings, " + TextColor.Cyan + name + TextColor.Reset +". May we know your role? \n"); System.out.println("Greetings, " + name + ". May we know your role? \n");
player = RoleMenu(name); player = RoleMenu(name);
@@ -46,7 +46,7 @@ public class SinglePlayerEngine extends MainEngine {
boolean continueLoop = false; boolean continueLoop = false;
do { do {
System.out.println(TextColor.Cyan + GetLocationIntro(location) + TextColor.Reset); System.out.println(GetLocationIntro(location));
System.out.println("What do you do, " + player.Name + "?"); System.out.println("What do you do, " + player.Name + "?");
System.out.println( System.out.println(
""" """
@@ -113,7 +113,7 @@ public class SinglePlayerEngine extends MainEngine {
case Jungle jungle -> case Jungle jungle ->
player.Name + " enters the woods, after a few steps, they see a green goblin searching for food a few steps away"; player.Name + " enters the woods, after a few steps, they see a green goblin searching for food a few steps away";
case GraveYard graveYard -> case GraveYard graveYard ->
player.Name + " goes inside the grave ward, they cannot see further than 10 steps ahead because of the fog in the air. After lurking through out the graves, the shadow appears... It's a skeleton!"; player.Name + " goes inside the grave ward, they cannot see a more than 10 steps ahead because of the fog in the air. After lurking through out the graves, the shadow appears... It's a skeleton!";
case DarkCaves darkCaves -> case DarkCaves darkCaves ->
player.Name + " dives into the darkness. As our hero was going deeper, a black smoke appears, a vampire is nearby..."; player.Name + " dives into the darkness. As our hero was going deeper, a black smoke appears, a vampire is nearby...";
case Castle castle -> case Castle castle ->
@@ -125,7 +125,7 @@ public class SinglePlayerEngine extends MainEngine {
public void MarketPlace() { public void MarketPlace() {
Scanner scanner = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
System.out.println(TextColor.Cyan + "You've entered the marketplace, what would you like to do?" + TextColor.Reset); System.out.println("You've entered the marketplace, what would you like to do?");
boolean wantsToStay = true; boolean wantsToStay = true;
while (wantsToStay) { while (wantsToStay) {
System.out.println("Money = " + player.GetMoney() + "\n"); System.out.println("Money = " + player.GetMoney() + "\n");
@@ -137,21 +137,15 @@ public class SinglePlayerEngine extends MainEngine {
4 > Sell the costumes 4 > Sell the costumes
5 > Sell the Weapons 5 > Sell the Weapons
6 > Buy shields 6 > Buy shields
7 > Buy weapon 7 > Buy shields
8 > Buy costume 8 > Buy shields
9 > Exit 9 > Exit
"""); """);
int choice = scanner.nextInt(); int choice = scanner.nextInt();
switch (choice) { switch (choice) {
case 0 -> { case 0 -> DisplayItem.DisplayItems(player.GetInventory());
if (player.GetInventory().isEmpty()) {
System.out.println(TextColor.Red + "You do not have anything at the moment" + TextColor.Reset);
break;
}
DisplayItem.DisplayItems(player.GetInventory());
}
case 1 -> { case 1 -> {
player.SellByClass(ItemClass.UNNECESSARY); player.SellByClass(ItemClass.UNNECESSARY);
System.out.println(TextColor.Green + "Unnecessary goods sold" + TextColor.Reset); System.out.println(TextColor.Green + "Unnecessary goods sold" + TextColor.Reset);
@@ -177,13 +171,8 @@ public class SinglePlayerEngine extends MainEngine {
System.out.println(TextColor.Blue + "Current shield: "); System.out.println(TextColor.Blue + "Current shield: ");
ArrayList<Item> item = new ArrayList<>(); ArrayList<Item> item = new ArrayList<>();
if (player.Shield == null) { item.add(player.Shield);
System.out.println(TextColor.Red + "You do not have a Shield" + TextColor.Reset); DisplayItem.DisplayItems(item);
}
else {
item.add(player.Shield);
DisplayItem.DisplayItems(item);
}
System.out.println(TextColor.Reset); System.out.println(TextColor.Reset);
ArrayList<Item> items = new ArrayList<>(Arrays.asList(Shields.getShields())); ArrayList<Item> items = new ArrayList<>(Arrays.asList(Shields.getShields()));
@@ -196,8 +185,7 @@ public class SinglePlayerEngine extends MainEngine {
if (accessory != null) { if (accessory != null) {
if (player.GetMoney() >= accessory.GetPrice()) { if (player.GetMoney() >= accessory.GetPrice()) {
if (player.Shield != null) player.Shield.DeattachFrom(player, true); accessory.AttachTo(player);
accessory.AttachTo(player, false);
player.ModifyMoney(accessory.GetPrice(), false); player.ModifyMoney(accessory.GetPrice(), false);
} }
else { else {
@@ -210,13 +198,8 @@ public class SinglePlayerEngine extends MainEngine {
System.out.println(TextColor.Blue + "Current weapon: "); System.out.println(TextColor.Blue + "Current weapon: ");
ArrayList<Item> item = new ArrayList<>(); ArrayList<Item> item = new ArrayList<>();
if (player.Weapon == null) { item.add(player.Weapon);
System.out.println(TextColor.Red + "You do not have a Weapon" + TextColor.Reset); DisplayItem.DisplayItems(item);
}
else {
item.add(player.Weapon);
DisplayItem.DisplayItems(item);
}
System.out.println(TextColor.Reset); System.out.println(TextColor.Reset);
ArrayList<Item> items = new ArrayList<>(Arrays.asList(Weapons.getWeapons())); ArrayList<Item> items = new ArrayList<>(Arrays.asList(Weapons.getWeapons()));
@@ -229,8 +212,7 @@ public class SinglePlayerEngine extends MainEngine {
if (accessory != null) { if (accessory != null) {
if (player.GetMoney() >= accessory.GetPrice()) { if (player.GetMoney() >= accessory.GetPrice()) {
if (player.Weapon != null) player.Weapon.DeattachFrom(player, true); accessory.AttachTo(player);
accessory.AttachTo(player, false);
player.ModifyMoney(accessory.GetPrice(), false); player.ModifyMoney(accessory.GetPrice(), false);
} }
else { else {
@@ -243,13 +225,8 @@ public class SinglePlayerEngine extends MainEngine {
System.out.println(TextColor.Blue + "Current costume: "); System.out.println(TextColor.Blue + "Current costume: ");
ArrayList<Item> item = new ArrayList<>(); ArrayList<Item> item = new ArrayList<>();
if (player.Costume == null) { item.add(player.Costume);
System.out.println(TextColor.Red + "You do not have a Costume" + TextColor.Reset); DisplayItem.DisplayItems(item);
}
else {
item.add(player.Costume);
DisplayItem.DisplayItems(item);
}
System.out.println(TextColor.Reset); System.out.println(TextColor.Reset);
ArrayList<Item> items = new ArrayList<>(Arrays.asList(Costumes.getCostumes())); ArrayList<Item> items = new ArrayList<>(Arrays.asList(Costumes.getCostumes()));
@@ -262,8 +239,7 @@ public class SinglePlayerEngine extends MainEngine {
if (accessory != null) { if (accessory != null) {
if (player.GetMoney() >= accessory.GetPrice()) { if (player.GetMoney() >= accessory.GetPrice()) {
if (player.Costume != null) player.Costume.DeattachFrom(player, true); accessory.AttachTo(player);
accessory.AttachTo(player, false);
player.ModifyMoney(accessory.GetPrice(), false); player.ModifyMoney(accessory.GetPrice(), false);
} }
else { else {
@@ -279,8 +255,7 @@ public class SinglePlayerEngine extends MainEngine {
public void InventoryView() { public void InventoryView() {
Scanner scanner = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
System.out.println(TextColor.Cyan + "You open your inventory, what would you like to do?\n" + TextColor.Reset); System.out.println("You open your inventory, what would you like to do?");
boolean wantsToStay = true; boolean wantsToStay = true;
while (wantsToStay) { while (wantsToStay) {
System.out.println("Money = " + player.GetMoney() + "\n"); System.out.println("Money = " + player.GetMoney() + "\n");
@@ -295,20 +270,10 @@ public class SinglePlayerEngine extends MainEngine {
int choice = scanner.nextInt(); int choice = scanner.nextInt();
switch (choice) { switch (choice) {
case 0 -> { case 0 -> DisplayItem.DisplayItems(player.GetInventory());
if (player.GetInventory().isEmpty()) {
System.out.println(TextColor.Red + "You do not have anything at the moment" + TextColor.Reset);
break;
}
DisplayItem.DisplayItems(player.GetInventory());
}
case 1 -> { case 1 -> {
System.out.println(TextColor.Blue + "Current shield: "); System.out.println(TextColor.Blue + "Current shield: ");
ArrayList<Item> item = new ArrayList<>(); ArrayList<Item> item = new ArrayList<>();
if (player.Shield == null) {
System.out.println(TextColor.Red + "You do not have a Shield" + TextColor.Reset);
break;
}
item.add(player.Shield); item.add(player.Shield);
DisplayItem.DisplayItems(item); DisplayItem.DisplayItems(item);
System.out.println(TextColor.Reset); System.out.println(TextColor.Reset);
@@ -320,17 +285,12 @@ public class SinglePlayerEngine extends MainEngine {
Item shield = dictionary.get(index); Item shield = dictionary.get(index);
if (shield != null) { if (shield != null) {
if (player.Shield != null) player.Shield.DeattachFrom(player, true); ((Accessory) shield).AttachTo(player);
((Accessory) shield).AttachTo(player, true);
} }
} }
case 2 -> { case 2 -> {
System.out.println(TextColor.Blue + "Current weapon: "); System.out.println(TextColor.Blue + "Current weapon: ");
ArrayList<Item> item = new ArrayList<>(); ArrayList<Item> item = new ArrayList<>();
if (player.Weapon == null) {
System.out.println(TextColor.Red + "You do not have a Weapon" + TextColor.Reset);
break;
}
item.add(player.Weapon); item.add(player.Weapon);
DisplayItem.DisplayItems(item); DisplayItem.DisplayItems(item);
System.out.println(TextColor.Reset); System.out.println(TextColor.Reset);
@@ -342,17 +302,12 @@ public class SinglePlayerEngine extends MainEngine {
Item weapon = dictionary.get(index); Item weapon = dictionary.get(index);
if (weapon != null) { if (weapon != null) {
if (player.Weapon != null) player.Weapon.DeattachFrom(player, true); ((Accessory) weapon).AttachTo(player);
((Accessory) weapon).AttachTo(player, true);
} }
} }
case 3 -> { case 3 -> {
System.out.println(TextColor.Blue + "Current costume: "); System.out.println(TextColor.Blue + "Current costume: ");
ArrayList<Item> item = new ArrayList<>(); ArrayList<Item> item = new ArrayList<>();
if (player.Costume == null) {
System.out.println(TextColor.Red + "You do not have a Costume" + TextColor.Reset);
break;
}
item.add(player.Costume); item.add(player.Costume);
DisplayItem.DisplayItems(item); DisplayItem.DisplayItems(item);
System.out.println(TextColor.Reset); System.out.println(TextColor.Reset);
@@ -364,8 +319,7 @@ public class SinglePlayerEngine extends MainEngine {
Item costume = dictionary.get(index); Item costume = dictionary.get(index);
if (costume != null) { if (costume != null) {
if (player.Costume != null) player.Costume.DeattachFrom(player, true); ((Accessory) costume).AttachTo(player);
((Accessory) costume).AttachTo(player, true);
} }
} }
case 4 -> wantsToStay = false; case 4 -> wantsToStay = false;
@@ -39,7 +39,9 @@ public class Assassin extends Player {
@Override @Override
public void SpecialAbility(Entity entity) { public void SpecialAbility(Entity entity) {
ModifyStamina(SpecialAbilityStamina, false); ModifyStamina(SpecialAbilityStamina, false);
entity.SetState(EntityState.FROZEN);
Damage(entity, GetDamage() * 3, new AttackPowerUp[]{AttackPowerUp.NO_DEFENSE}); Damage(entity, GetDamage() * 3, new AttackPowerUp[]{AttackPowerUp.NO_DEFENSE});
Heal(MaxHealth/4);
} }
@@ -45,13 +45,13 @@ public abstract class Accessory extends SellableItem implements IDamageable, IAt
@Override @Override
public void HandleZeroHealth() { public void HandleZeroHealth() {
this.DeattachFrom(this.Owner, false); this.DeattachFrom(this.Owner);
this.Owner.Inventory.remove(this); this.Owner.Inventory.remove(this);
} }
@Override @Override
public abstract void AttachTo(Entity entity, boolean fromInventory); public abstract void AttachTo(Entity entity);
@Override @Override
public abstract void DeattachFrom(Entity entity, boolean toInventory); public abstract void DeattachFrom(Entity entity);
} }
@@ -35,14 +35,14 @@ public class Costume extends Accessory implements IDefender {
} }
@Override @Override
public void AttachTo(Entity entity, boolean fromInventory) { public void AttachTo(Entity entity) {
if (fromInventory) entity.RemoveFromInventory(this); entity.RemoveFromInventory(this);
entity.Costume = this; entity.Costume = this;
} }
@Override @Override
public void DeattachFrom(Entity entity, boolean toInventory) { public void DeattachFrom(Entity entity) {
entity.Costume = null; entity.Costume = null;
if (toInventory) entity.AddToInventory(this); entity.AddToInventory(this);
} }
} }
@@ -35,14 +35,14 @@ public class Shield extends Accessory implements IDefender {
} }
@Override @Override
public void AttachTo(Entity entity, boolean fromInventory) { public void AttachTo(Entity entity) {
if (fromInventory) entity.RemoveFromInventory(this); entity.RemoveFromInventory(this);
entity.Shield = this; entity.Shield = this;
} }
@Override @Override
public void DeattachFrom(Entity entity, boolean toInventory) { public void DeattachFrom(Entity entity) {
entity.Shield = null; entity.Shield = null;
if (toInventory) entity.AddToInventory(this); entity.AddToInventory(this);
} }
} }
@@ -17,14 +17,14 @@ public class Weapon extends Accessory implements IDamageUtil {
} }
@Override @Override
public void AttachTo(Entity entity, boolean fromInventory) { public void AttachTo(Entity entity) {
if (fromInventory) entity.RemoveFromInventory(this); entity.RemoveFromInventory(this);
entity.Weapon = this; entity.Weapon = this;
} }
@Override @Override
public void DeattachFrom(Entity entity, boolean toInventory) { public void DeattachFrom(Entity entity) {
entity.Weapon = null; entity.Weapon = null;
if (toInventory) entity.AddToInventory(this); entity.AddToInventory(this);
} }
} }
@@ -15,8 +15,6 @@ import java.util.Hashtable;
public class DisplayItem { public class DisplayItem {
public static void DisplayItems(ArrayList<Item> items) { public static void DisplayItems(ArrayList<Item> items) {
for (Item item : items) { for (Item item : items) {
if (item == null) continue;
String result = item.getName(); String result = item.getName();
if (item instanceof SellableItem) { if (item instanceof SellableItem) {
@@ -32,7 +30,7 @@ public class DisplayItem {
} }
if (item instanceof IDefender) { if (item instanceof IDefender) {
result += "\n Defence = " + ((IDefender) item).GetDefense(); result += "\n Damage = " + ((IDefender) item).GetDefense();
} }
System.out.println(result); System.out.println(result);
@@ -44,8 +42,6 @@ public class DisplayItem {
Dictionary<Integer, Item> dictionary = new Hashtable<>(); Dictionary<Integer, Item> dictionary = new Hashtable<>();
for (Item item : items) { for (Item item : items) {
if (item == null) continue;
String result = index + " > " + item.getName(); String result = index + " > " + item.getName();
if (item instanceof KeyItem) { if (item instanceof KeyItem) {
@@ -65,7 +61,7 @@ public class DisplayItem {
} }
if (item instanceof IDefender) { if (item instanceof IDefender) {
result += "\n Defence = " + ((IDefender) item).GetDefense(); result += "\n Damage = " + ((IDefender) item).GetDefense();
} }
dictionary.put(index, item); dictionary.put(index, item);