diff --git a/Java-Knight/src/main/java/org/project/engine/BattleEngine.java b/Java-Knight/src/main/java/org/project/engine/BattleEngine.java index bf17bc0..a45a71c 100644 --- a/Java-Knight/src/main/java/org/project/engine/BattleEngine.java +++ b/Java-Knight/src/main/java/org/project/engine/BattleEngine.java @@ -1,4 +1,15 @@ package org.project.engine; -public class BattleEngine { +import org.project.entity.Entity; + +public abstract class BattleEngine { + public Entity Player1; + public Entity Player2; + + public BattleEngine(Entity player1, Entity player2) { + Player1 = player1; + Player2 = player2; + } + + public abstract void StartBattle(); } diff --git a/Java-Knight/src/main/java/org/project/engine/MainEngine.java b/Java-Knight/src/main/java/org/project/engine/MainEngine.java index ffd3e31..e7be22f 100644 --- a/Java-Knight/src/main/java/org/project/engine/MainEngine.java +++ b/Java-Knight/src/main/java/org/project/engine/MainEngine.java @@ -1,6 +1,11 @@ package org.project.engine; import org.project.constants.appConstants.GameModes; +import org.project.constants.gameConstant.PlayerRoles; +import org.project.constants.gameConstant.PlayerRolesExt; +import org.project.entity.players.Player; + +import java.util.Scanner; public abstract class MainEngine { protected MainEngine() {} @@ -13,4 +18,36 @@ public abstract class MainEngine { case GameModes.MULTI_PLAYER_LOCAL -> new MultiplayerEngine(); }; } + + protected Player RoleMenu(String name, int level) { + Scanner scanner = new Scanner(System.in); + PlayerRoles[] roles = PlayerRoles.values(); + int index = 0; + while (true) { + for (PlayerRoles role : roles) { + System.out.println(index + " > " + role.name().toLowerCase()); + } + int choice = scanner.nextInt(); + + if (choice >= 0 && choice < roles.length) { + return PlayerRolesExt.CreatePlayer(roles[choice], name, level); + } + } + } + + protected Player RoleMenu(String name) { + Scanner scanner = new Scanner(System.in); + PlayerRoles[] roles = PlayerRoles.values(); + int index = 0; + while (true) { + for (PlayerRoles role : roles) { + System.out.println(index + " > " + role.name().toLowerCase()); + } + int choice = scanner.nextInt(); + + if (choice >= 0 && choice < roles.length) { + return PlayerRolesExt.CreatePlayer(roles[choice], name); + } + } + } } diff --git a/Java-Knight/src/main/java/org/project/engine/MultiPlayerBattleEngine.java b/Java-Knight/src/main/java/org/project/engine/MultiPlayerBattleEngine.java index e4f03d7..876e185 100644 --- a/Java-Knight/src/main/java/org/project/engine/MultiPlayerBattleEngine.java +++ b/Java-Knight/src/main/java/org/project/engine/MultiPlayerBattleEngine.java @@ -1,4 +1,15 @@ package org.project.engine; -public class MultiPlayerBattleEngine { +import org.project.entity.enemies.Enemy; +import org.project.entity.players.Player; + +public class MultiPlayerBattleEngine extends BattleEngine { + public MultiPlayerBattleEngine(Player player1, Player player2) { + super(player1, player2); + } + + @Override + public void StartBattle() { + + } } diff --git a/Java-Knight/src/main/java/org/project/engine/MultiplayerEngine.java b/Java-Knight/src/main/java/org/project/engine/MultiplayerEngine.java index a081c5d..4b25148 100644 --- a/Java-Knight/src/main/java/org/project/engine/MultiplayerEngine.java +++ b/Java-Knight/src/main/java/org/project/engine/MultiplayerEngine.java @@ -1,4 +1,39 @@ package org.project.engine; -public class MultiplayerEngine extends MainEngine{ +import org.project.constants.appConstants.TextColor; +import org.project.entity.players.Player; + +import java.util.Scanner; + +public class MultiplayerEngine extends MainEngine { + public MultiplayerEngine() { + super(); + } + + @Override + public void run() { + Scanner scanner = new Scanner(System.in); + + System.out.println("Player 1, Set your name:"); + String player1Name = scanner.nextLine(); + + System.out.println("Player 2, Set your name:"); + String player2Name = scanner.nextLine(); + + System.out.println(player1Name + ", Set the level of your character:"); + int player1Level = scanner.nextInt(); + + System.out.println(player2Name + ", Set the level of your character:"); + int player2Level = scanner.nextInt(); + + System.out.println(player1Name + ", Set the role of your character:"); + Player player1 = RoleMenu(player1Name, player1Level); + + System.out.println(player2Name + ", Set the role of your character:"); + Player player2 = RoleMenu(player2Name, player2Level); + + System.out.println(TextColor.Red + "Now the battle begins" + TextColor.Reset); + BattleEngine engine = new MultiPlayerBattleEngine(player1, player2); + engine.StartBattle(); + } } diff --git a/Java-Knight/src/main/java/org/project/engine/SinglePlayerBattleEngine.java b/Java-Knight/src/main/java/org/project/engine/SinglePlayerBattleEngine.java index bacd832..d17d589 100644 --- a/Java-Knight/src/main/java/org/project/engine/SinglePlayerBattleEngine.java +++ b/Java-Knight/src/main/java/org/project/engine/SinglePlayerBattleEngine.java @@ -1,4 +1,55 @@ package org.project.engine; -public class SinglePlayerBattleEngine { +import org.project.constants.appConstants.TextColor; +import org.project.constants.gameConstant.EntityState; +import org.project.constants.gameConstant.FightMoves; +import org.project.entity.enemies.Enemy; +import org.project.entity.players.Player; + +public class SinglePlayerBattleEngine extends BattleEngine { + private Player player; + private Enemy enemy; + public SinglePlayerBattleEngine(Player player, Enemy enemy) { + super(player, enemy); + player = (Player) Player1; + enemy = (Enemy) Player2; + } + + @Override + public void StartBattle() { + Player playerPast = player; + Enemy enemyPast = enemy; + + while (true) { + if (enemyPast.GetState() == EntityState.FROZEN) { + enemy.SetState(EntityState.ALIVE); + } + if (playerPast.GetState() == EntityState.FROZEN) { + player.SetState(EntityState.ALIVE); + } + + // TODO: get diffs + + // TODO: player round + + // TODO: show players stats + + // TODO: bot move + FightMoves botMove = enemy.PlayRound(player); + switch (botMove) + + 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; + } + + playerPast = player; + enemyPast = enemy; + } + } } diff --git a/Java-Knight/src/main/java/org/project/engine/SinglePlayerEngine.java b/Java-Knight/src/main/java/org/project/engine/SinglePlayerEngine.java index 67adbca..4d3d529 100644 --- a/Java-Knight/src/main/java/org/project/engine/SinglePlayerEngine.java +++ b/Java-Knight/src/main/java/org/project/engine/SinglePlayerEngine.java @@ -2,13 +2,17 @@ package org.project.engine; import org.project.constants.appConstants.ConsoleColor; import org.project.constants.appConstants.TextColor; -import org.project.constants.gameConstant.ItemClass; -import org.project.entity.players.Assassin; -import org.project.entity.players.Knight; +import org.project.constants.gameConstant.*; import org.project.entity.players.Player; -import org.project.entity.players.Wizard; +import org.project.item.Accessory.Accessory; +import org.project.item.Accessory.Shield; +import org.project.item.Item; import org.project.location.*; +import org.project.util.DisplayItem; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Dictionary; import java.util.Scanner; public class SinglePlayerEngine extends MainEngine { @@ -28,55 +32,75 @@ public class SinglePlayerEngine extends MainEngine { System.out.println("How should me call you, hero? "); String name = scanner.nextLine(); - boolean InValidInput = false; - do { - System.out.println("Greetings, " + name + ". May we know your role? \n" + - "0 > Wizard" + - "1 > Assassin" + - "2 > Knight"); + System.out.println("Greetings, " + name + ". May we know your role? \n"); - int choice = scanner.nextInt(); + player = RoleMenu(name); - switch (choice) { - case 0 -> player = new Wizard(name); - case 1 -> player = new Assassin(name); - case 2 -> player = new Knight(name); - default -> InValidInput = true; - } - } while (InValidInput); - - System.out.println("Very well, " + TextColor.Cyan + GetIntro() + ConsoleColor.Reset + " your journey begins!"); + System.out.println("Very well, " + TextColor.Cyan + player.Name + ConsoleColor.Reset + " your journey begins!"); System.out.println(); while (true) { - boolean canFightDragon = false; - if (player.GetInventoryByClass(ItemClass.KEY).size() == 3) { - canFightDragon = true; - } + boolean canFightDragon = player.GetInventoryByClass(ItemClass.KEY).size() == 3; Location location = Location.RandomLocation(); - System.out.println(GetLocationIntro(location)); - while (true) { + boolean continueLoop = false; + do { + System.out.println(GetLocationIntro(location)); System.out.println("What do you do, " + player.Name + "?"); System.out.println( - "0 > FIGHT!\n" + - "1 > Go to the next location\n" + - "2 > Visit the market place in the town" + """ + 0 > FIGHT! + 1 > Go to the next location + 2 > Visit the market place in the town + 3 > Check inventory""" ); if (canFightDragon) { - System.out.println("3 > Go to the castle to face the dragon"); + System.out.println("4 > Go to the castle to face the dragon"); } int choice = scanner.nextInt(); switch (choice) { case 0 -> { - + System.out.println(TextColor.Red + "You choice to FIGHT!" + TextColor.Reset); + BattleEngine engine = new SinglePlayerBattleEngine(player, location.enemy); + engine.StartBattle(); + continueLoop = false; } + case 1 -> { + continueLoop = false; + } + case 2 -> { + MarketPlace(); + continueLoop = false; + } + case 3 -> { + InventoryView(); + continueLoop = true; + } + case 4 -> { + if (canFightDragon) { + location = new Castle(); + continueLoop = false; + } + else { + continueLoop = true; + } + } + default -> continueLoop = true; } + } while (continueLoop); + + if (player.GetState() == EntityState.DEAD) { + System.out.println(TextColor.Red + "Game Over!" + TextColor.Reset); + break; } + if (player.GetInventoryByClass(ItemClass.KEY).size() == 4) { + System.out.println(TextColor.Blue + "You WON! You saved Javanest!" + TextColor.Reset); + break; + } } } @@ -85,20 +109,221 @@ public class SinglePlayerEngine extends MainEngine { } public String GetLocationIntro(Location location) { - if (location instanceof Jungle) { - return player.Name + " enters the woods, after a few steps, they see a green goblin searching for food a few steps away"; + return switch (location) { + case Jungle jungle -> + player.Name + " enters the woods, after a few steps, they see a green goblin searching for food a few steps away"; + case GraveYard graveYard -> + 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 -> + player.Name + " dives into the darkness. As our hero was going deeper, a black smoke appears, a vampire is nearby..."; + case Castle castle -> + player.Name + " Goes through the gates, the dragon looks at " + player.Name + "... It knows that an epic battle awaits both it them"; + case null, default -> ""; + }; + } + + public void MarketPlace() { + Scanner scanner = new Scanner(System.in); + + System.out.println("You've entered the marketplace, what would you like to do?"); + boolean wantsToStay = true; + while (wantsToStay) { + System.out.println("Money = " + player.GetMoney() + "\n"); + System.out.println(""" + 0 > Show Inventory + 1 > Sell Unnecessary goods + 2 > Sell the accessories + 3 > Sell the shields + 4 > Sell the costumes + 5 > Sell the Weapons + 6 > Buy shields + 7 > Buy shields + 8 > Buy shields + 9 > Exit + """); + + int choice = scanner.nextInt(); + + switch (choice) { + case 0 -> DisplayItem.DisplayItems(player.GetInventory()); + case 1 -> { + player.SellByClass(ItemClass.UNNECESSARY); + System.out.println(TextColor.Green + "Unnecessary goods sold" + TextColor.Reset); + } + case 2 -> { + player.SellByClass(ItemClass.ACCESSORY); + System.out.println(TextColor.Green + "accessories sold" + TextColor.Reset); + } + case 3 -> { + player.SellByClass(ItemClass.SHIELD); + System.out.println(TextColor.Green + "shields sold" + TextColor.Reset); + } + case 4 -> { + player.SellByClass(ItemClass.COSTUME); + System.out.println(TextColor.Green + "costumes sold" + TextColor.Reset); + } + case 5 -> { + player.SellByClass(ItemClass.WEAPON); + System.out.println(TextColor.Green + "weapons sold" + TextColor.Reset); + } + case 6 -> { + System.out.println("Money = " + player.GetMoney() + "\n"); + + System.out.println(TextColor.Blue + "Current shield: "); + ArrayList item = new ArrayList<>(); + item.add(player.Shield); + DisplayItem.DisplayItems(item); + System.out.println(TextColor.Reset); + + ArrayList items = new ArrayList<>(Arrays.asList(Shields.getShields())); + Dictionary dictionary = DisplayItem.MenuDisplay(items); + + System.out.println("Please set the number of the accessory you want to buy, set any other number to abort:"); + Integer index = scanner.nextInt(); + Item shield = dictionary.get(index); + Accessory accessory = (Accessory) shield; + + if (accessory != null) { + if (player.GetMoney() >= accessory.GetPrice()) { + accessory.AttachTo(player); + player.ModifyMoney(accessory.GetPrice(), false); + } + else { + System.out.println(TextColor.Red + "You do not have enough money" + TextColor.Reset); + } + } + } + case 7 -> { + System.out.println("Money = " + player.GetMoney() + "\n"); + + System.out.println(TextColor.Blue + "Current weapon: "); + ArrayList item = new ArrayList<>(); + item.add(player.Weapon); + DisplayItem.DisplayItems(item); + System.out.println(TextColor.Reset); + + ArrayList items = new ArrayList<>(Arrays.asList(Weapons.getWeapons())); + Dictionary dictionary = DisplayItem.MenuDisplay(items); + + System.out.println("Please set the number of the accessory you want to buy, set any other number to abort:"); + Integer index = scanner.nextInt(); + Item weapon = dictionary.get(index); + Accessory accessory = (Accessory) weapon; + + if (accessory != null) { + if (player.GetMoney() >= accessory.GetPrice()) { + accessory.AttachTo(player); + player.ModifyMoney(accessory.GetPrice(), false); + } + else { + System.out.println(TextColor.Red + "You do not have enough money" + TextColor.Reset); + } + } + } + case 8 -> { + System.out.println("Money = " + player.GetMoney() + "\n"); + + System.out.println(TextColor.Blue + "Current costume: "); + ArrayList item = new ArrayList<>(); + item.add(player.Costume); + DisplayItem.DisplayItems(item); + System.out.println(TextColor.Reset); + + ArrayList items = new ArrayList<>(Arrays.asList(Costumes.getCostumes())); + Dictionary dictionary = DisplayItem.MenuDisplay(items); + + System.out.println("Please set the number of the accessory you want to buy, set any other number to abort:"); + Integer index = scanner.nextInt(); + Item costume = dictionary.get(index); + Accessory accessory = (Accessory) costume; + + if (accessory != null) { + if (player.GetMoney() >= accessory.GetPrice()) { + accessory.AttachTo(player); + player.ModifyMoney(accessory.GetPrice(), false); + } + else { + System.out.println(TextColor.Red + "You do not have enough money" + TextColor.Reset); + } + } + } + case 9 -> wantsToStay = false; + } } - else if (location instanceof GraveYard) { - return 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!"; - } - else if (location instanceof DarkCaves) { - return player.Name + " dives into the darkness. As our hero was going deeper, a black smoke appears, a vampire is nearby..."; - } - else if (location instanceof Castle) { - return player.Name + " Goes through the gates, the dragon looks at " + player.Name + "... It knows that an epic battle awaits both it them"; - } - else { - return ""; + } + + public void InventoryView() { + Scanner scanner = new Scanner(System.in); + + System.out.println("You open your inventory, what would you like to do?"); + boolean wantsToStay = true; + while (wantsToStay) { + System.out.println("Money = " + player.GetMoney() + "\n"); + System.out.println(""" + 0 > Show Inventory + 1 > Show Shields + 2 > Show Weapons + 3 > Show Costumes + 4 > Exit + """); + + int choice = scanner.nextInt(); + + switch (choice) { + case 0 -> DisplayItem.DisplayItems(player.GetInventory()); + case 1 -> { + System.out.println(TextColor.Blue + "Current shield: "); + ArrayList item = new ArrayList<>(); + item.add(player.Shield); + DisplayItem.DisplayItems(item); + System.out.println(TextColor.Reset); + + Dictionary dictionary = DisplayItem.MenuDisplay(player.GetInventoryByClass(ItemClass.SHIELD)); + + System.out.println("Please set the number of the accessory you want to wear, set any other number to abort:"); + Integer index = scanner.nextInt(); + Item shield = dictionary.get(index); + + if (shield != null) { + ((Accessory) shield).AttachTo(player); + } + } + case 2 -> { + System.out.println(TextColor.Blue + "Current weapon: "); + ArrayList item = new ArrayList<>(); + item.add(player.Weapon); + DisplayItem.DisplayItems(item); + System.out.println(TextColor.Reset); + + Dictionary dictionary = DisplayItem.MenuDisplay(player.GetInventoryByClass(ItemClass.WEAPON)); + + System.out.println("Please set the number of the accessory you want to wear, set any other number to abort:"); + Integer index = scanner.nextInt(); + Item weapon = dictionary.get(index); + + if (weapon != null) { + ((Accessory) weapon).AttachTo(player); + } + } + case 3 -> { + System.out.println(TextColor.Blue + "Current costume: "); + ArrayList item = new ArrayList<>(); + item.add(player.Costume); + DisplayItem.DisplayItems(item); + System.out.println(TextColor.Reset); + + Dictionary dictionary = DisplayItem.MenuDisplay(player.GetInventoryByClass(ItemClass.COSTUME)); + + System.out.println("Please set the number of the accessory you want to wear, set any other number to abort:"); + Integer index = scanner.nextInt(); + Item costume = dictionary.get(index); + + if (costume != null) { + ((Accessory) costume).AttachTo(player); + } + } + case 4 -> wantsToStay = false; + } } } }