Develop #1
@@ -0,0 +1,5 @@
|
|||||||
|
package org.project.common.models;
|
||||||
|
|
||||||
|
public record EntityDiff(int health, int stamina, boolean lostShield, boolean lostCostume, int shieldHealth, int costumeHealth) {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -26,6 +26,7 @@ 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();
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,167 @@
|
|||||||
package org.project.engine;
|
package org.project.engine;
|
||||||
|
|
||||||
import org.project.entity.enemies.Enemy;
|
import org.project.common.models.EntityDiff;
|
||||||
|
import org.project.constants.appConstants.TextColor;
|
||||||
|
import org.project.constants.gameConstant.EntityState;
|
||||||
|
import org.project.constants.gameConstant.FightMoves;
|
||||||
|
import org.project.entity.Entity;
|
||||||
import org.project.entity.players.Player;
|
import org.project.entity.players.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Dictionary;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class MultiPlayerBattleEngine extends BattleEngine {
|
public class MultiPlayerBattleEngine extends BattleEngine {
|
||||||
|
private Player player1;
|
||||||
|
private Player player2;
|
||||||
|
private Player player1Past;
|
||||||
|
private Player player2Past;
|
||||||
|
|
||||||
public MultiPlayerBattleEngine(Player player1, Player player2) {
|
public MultiPlayerBattleEngine(Player player1, Player player2) {
|
||||||
super(player1, player2);
|
super(player1, player2);
|
||||||
|
this.player1 = (Player) Player1;
|
||||||
|
this.player2 = (Player) Player2;
|
||||||
|
player1Past = null;
|
||||||
|
player2Past = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void StartBattle() {
|
public void StartBattle() {
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
FightMoves player1Move = PlayerMovesMenu(player1, player2);
|
||||||
|
showMoveExplanation(player1Move, player1, player2);
|
||||||
|
|
||||||
|
if (player1Past.GetState() == EntityState.FROZEN) {
|
||||||
|
player1.SetState(EntityState.ALIVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
player1Past = player1;
|
||||||
|
player2Past = player2;
|
||||||
|
|
||||||
|
EntityDiff playerDiff = getPlayerDiff(player1Past, player1);
|
||||||
|
EntityDiff enemyDiff = getPlayerDiff(player2Past, player2);
|
||||||
|
|
||||||
|
showFighter(playerDiff, player1);
|
||||||
|
showFighter(enemyDiff, player2);
|
||||||
|
|
||||||
|
FightMoves player2Move = PlayerMovesMenu(player2, player1);
|
||||||
|
showMoveExplanation(player2Move, player2, player1);
|
||||||
|
|
||||||
|
if (player2Past.GetState() == EntityState.FROZEN) {
|
||||||
|
player2.SetState(EntityState.ALIVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
player1Past = player1;
|
||||||
|
player2Past = player2;
|
||||||
|
|
||||||
|
playerDiff = getPlayerDiff(player1Past, player1);
|
||||||
|
enemyDiff = getPlayerDiff(player2Past, player2);
|
||||||
|
|
||||||
|
showFighter(playerDiff, player1);
|
||||||
|
showFighter(enemyDiff, player2);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private EntityDiff getPlayerDiff(Entity oldVersion, Entity newVersion) {
|
||||||
|
return new EntityDiff(
|
||||||
|
newVersion.Health - oldVersion.Health,
|
||||||
|
newVersion.GetStamina() - oldVersion.GetStamina(),
|
||||||
|
(newVersion.Shield == null && oldVersion.Shield != null),
|
||||||
|
(newVersion.Weapon == null && oldVersion.Weapon != null),
|
||||||
|
(newVersion.Shield != null ? newVersion.Shield.GetHealth() : 0) - (oldVersion.Shield != null ? oldVersion.Shield.GetHealth() : 0),
|
||||||
|
(newVersion.Costume != null ? newVersion.Costume.GetHealth() : 0) - (oldVersion.Costume != null ? oldVersion.Costume.GetHealth() : 0)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showFighter(EntityDiff diff, Entity entity) {
|
||||||
|
System.out.println(entity.Name + ":");
|
||||||
|
|
||||||
|
String color = diff.health() > 0 ? TextColor.Green : TextColor.Red;
|
||||||
|
System.out.println(" Health: " + entity.Health + " " + color + diff.health() + TextColor.Reset);
|
||||||
|
|
||||||
|
color = diff.stamina() > 0 ? TextColor.Green : TextColor.Red;
|
||||||
|
System.out.println(" Stamina: " + entity.GetStamina() + " " + color + diff.stamina() + TextColor.Reset);
|
||||||
|
|
||||||
|
if (diff.lostShield()) {
|
||||||
|
System.out.println(" Shield: " + entity.Shield.getName() + " " + TextColor.Red + "LOST" + TextColor.Reset);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (diff.lostCostume()) {
|
||||||
|
System.out.println(" Costume: " + entity.Costume.getName() + " " + TextColor.Red + "LOST" + TextColor.Reset);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity.Shield != null) {
|
||||||
|
color = diff.shieldHealth() > 0 ? TextColor.Green : TextColor.Red;
|
||||||
|
System.out.println(" Shield: " + entity.Shield.getName() + " " + color + diff.shieldHealth() + TextColor.Reset);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity.Costume != null) {
|
||||||
|
color = diff.costumeHealth() > 0 ? TextColor.Green : TextColor.Red;
|
||||||
|
System.out.println(" Costume: " + entity.Costume.getName() + " " + color + diff.shieldHealth() + TextColor.Reset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private FightMoves PlayerMovesMenu(Player performer, Player receiver) {
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
|
System.out.println(performer.Name + " it's your turn");
|
||||||
|
ArrayList<FightMoves> moves = performer.GetAvailableMoves();
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
|
Dictionary<Integer, FightMoves> dictionary = new Hashtable<>();
|
||||||
|
|
||||||
|
for (FightMoves move : moves) {
|
||||||
|
String result = index + " > " + move.toString();
|
||||||
|
|
||||||
|
if (move == FightMoves.SPECIAL) {
|
||||||
|
result += " (" + performer.GetSpecialAbilityDescription(receiver) + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
dictionary.put(index, move);
|
||||||
|
index++;
|
||||||
|
|
||||||
|
System.out.println(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean continueLoop;
|
||||||
|
while (true){
|
||||||
|
continueLoop = false;
|
||||||
|
int choice = scanner.nextInt();
|
||||||
|
FightMoves move = moves.get(choice);
|
||||||
|
|
||||||
|
switch (move) {
|
||||||
|
case FightMoves.LIGHT_ATTACK -> performer.LightAttack(receiver);
|
||||||
|
case FightMoves.HEAVY_ATTACK -> performer.HeavyAttack(receiver);
|
||||||
|
case FightMoves.SPECIAL -> performer.SpecialAbility(receiver);
|
||||||
|
case FightMoves.HEAL -> performer.HealMove();
|
||||||
|
case FightMoves.DEFEND -> performer.defend();
|
||||||
|
default -> continueLoop = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!continueLoop) {
|
||||||
|
return move;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showMoveExplanation(FightMoves move, Entity performer, Entity receiver) {
|
||||||
|
switch (move) {
|
||||||
|
case FightMoves.LIGHT_ATTACK -> System.out.println(performer.Name + " performs a light attack");
|
||||||
|
case FightMoves.HEAVY_ATTACK -> System.out.println(performer.Name + " performs a heavy attack");
|
||||||
|
case FightMoves.SPECIAL -> System.out.println(performer.GetSpecialAbilityResultDescription(receiver));
|
||||||
|
case FightMoves.HEAL -> System.out.println(performer.Name + " heals");
|
||||||
|
case FightMoves.DEFEND -> System.out.println(performer.Name + " get their guard up!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,42 +1,66 @@
|
|||||||
package org.project.engine;
|
package org.project.engine;
|
||||||
|
|
||||||
|
import org.project.common.models.EntityDiff;
|
||||||
import org.project.constants.appConstants.TextColor;
|
import org.project.constants.appConstants.TextColor;
|
||||||
import org.project.constants.gameConstant.EntityState;
|
import org.project.constants.gameConstant.EntityState;
|
||||||
import org.project.constants.gameConstant.FightMoves;
|
import org.project.constants.gameConstant.FightMoves;
|
||||||
|
import org.project.entity.Entity;
|
||||||
import org.project.entity.enemies.Enemy;
|
import org.project.entity.enemies.Enemy;
|
||||||
import org.project.entity.players.Player;
|
import org.project.entity.players.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Dictionary;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class SinglePlayerBattleEngine extends BattleEngine {
|
public class SinglePlayerBattleEngine extends BattleEngine {
|
||||||
private Player player;
|
private Player player;
|
||||||
private Enemy enemy;
|
private Enemy enemy;
|
||||||
|
private Player playerPast;
|
||||||
|
private Enemy enemyPast;
|
||||||
public SinglePlayerBattleEngine(Player player, Enemy enemy) {
|
public SinglePlayerBattleEngine(Player player, Enemy enemy) {
|
||||||
super(player, enemy);
|
super(player, enemy);
|
||||||
player = (Player) Player1;
|
this.player = (Player) Player1;
|
||||||
enemy = (Enemy) Player2;
|
this.enemy = (Enemy) Player2;
|
||||||
|
playerPast = null;
|
||||||
|
enemyPast = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void StartBattle() {
|
public void StartBattle() {
|
||||||
Player playerPast = player;
|
|
||||||
Enemy enemyPast = enemy;
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (enemyPast.GetState() == EntityState.FROZEN) {
|
FightMoves playerMove = PlayerMovesMenu();
|
||||||
enemy.SetState(EntityState.ALIVE);
|
showMoveExplanation(playerMove, player, enemy);
|
||||||
}
|
|
||||||
if (playerPast.GetState() == EntityState.FROZEN) {
|
if (playerPast.GetState() == EntityState.FROZEN) {
|
||||||
player.SetState(EntityState.ALIVE);
|
player.SetState(EntityState.ALIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: get diffs
|
playerPast = player;
|
||||||
|
enemyPast = enemy;
|
||||||
|
|
||||||
// TODO: player round
|
EntityDiff playerDiff = getPlayerDiff(playerPast, player);
|
||||||
|
EntityDiff enemyDiff = getPlayerDiff(enemyPast, enemy);
|
||||||
|
|
||||||
// TODO: show players stats
|
showFighter(playerDiff, player);
|
||||||
|
showFighter(enemyDiff, enemy);
|
||||||
|
|
||||||
// TODO: bot move
|
|
||||||
FightMoves botMove = enemy.PlayRound(player);
|
FightMoves botMove = enemy.PlayRound(player);
|
||||||
switch (botMove)
|
showMoveExplanation(botMove, enemy, player);
|
||||||
|
|
||||||
|
if (enemyPast.GetState() == EntityState.FROZEN) {
|
||||||
|
enemy.SetState(EntityState.ALIVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
playerPast = player;
|
||||||
|
enemyPast = enemy;
|
||||||
|
|
||||||
|
playerDiff = getPlayerDiff(playerPast, player);
|
||||||
|
enemyDiff = getPlayerDiff(enemyPast, enemy);
|
||||||
|
|
||||||
|
showFighter(playerDiff, player);
|
||||||
|
showFighter(enemyDiff, enemy);
|
||||||
|
|
||||||
if (enemy.GetState() == EntityState.DEAD) {
|
if (enemy.GetState() == EntityState.DEAD) {
|
||||||
enemy.DropLoot(player);
|
enemy.DropLoot(player);
|
||||||
@@ -47,9 +71,98 @@ public class SinglePlayerBattleEngine extends BattleEngine {
|
|||||||
else if (player.GetState() == EntityState.DEAD) {
|
else if (player.GetState() == EntityState.DEAD) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
playerPast = player;
|
private EntityDiff getPlayerDiff(Entity oldVersion, Entity newVersion) {
|
||||||
enemyPast = enemy;
|
return new EntityDiff(
|
||||||
|
newVersion.Health - oldVersion.Health,
|
||||||
|
newVersion.GetStamina() - oldVersion.GetStamina(),
|
||||||
|
(newVersion.Shield == null && oldVersion.Shield != null),
|
||||||
|
(newVersion.Weapon == null && oldVersion.Weapon != null),
|
||||||
|
(newVersion.Shield != null ? newVersion.Shield.GetHealth() : 0) - (oldVersion.Shield != null ? oldVersion.Shield.GetHealth() : 0),
|
||||||
|
(newVersion.Costume != null ? newVersion.Costume.GetHealth() : 0) - (oldVersion.Costume != null ? oldVersion.Costume.GetHealth() : 0)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showFighter(EntityDiff diff, Entity entity) {
|
||||||
|
System.out.println(entity.Name + ":");
|
||||||
|
|
||||||
|
String color = diff.health() > 0 ? TextColor.Green : TextColor.Red;
|
||||||
|
System.out.println(" Health: " + entity.Health + " " + color + diff.health() + TextColor.Reset);
|
||||||
|
|
||||||
|
color = diff.stamina() > 0 ? TextColor.Green : TextColor.Red;
|
||||||
|
System.out.println(" Stamina: " + entity.GetStamina() + " " + color + diff.stamina() + TextColor.Reset);
|
||||||
|
|
||||||
|
if (diff.lostShield()) {
|
||||||
|
System.out.println(" Shield: " + entity.Shield.getName() + " " + TextColor.Red + "LOST" + TextColor.Reset);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (diff.lostCostume()) {
|
||||||
|
System.out.println(" Costume: " + entity.Costume.getName() + " " + TextColor.Red + "LOST" + TextColor.Reset);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity.Shield != null) {
|
||||||
|
color = diff.shieldHealth() > 0 ? TextColor.Green : TextColor.Red;
|
||||||
|
System.out.println(" Shield: " + entity.Shield.getName() + " " + color + diff.shieldHealth() + TextColor.Reset);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity.Costume != null) {
|
||||||
|
color = diff.costumeHealth() > 0 ? TextColor.Green : TextColor.Red;
|
||||||
|
System.out.println(" Costume: " + entity.Costume.getName() + " " + color + diff.shieldHealth() + TextColor.Reset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private FightMoves PlayerMovesMenu() {
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
|
System.out.println(player.Name + " it's your turn");
|
||||||
|
ArrayList<FightMoves> moves = player.GetAvailableMoves();
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
|
Dictionary<Integer, FightMoves> dictionary = new Hashtable<>();
|
||||||
|
|
||||||
|
for (FightMoves move : moves) {
|
||||||
|
String result = index + " > " + move.toString();
|
||||||
|
|
||||||
|
if (move == FightMoves.SPECIAL) {
|
||||||
|
result += " (" + player.GetSpecialAbilityDescription(enemy) + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
dictionary.put(index, move);
|
||||||
|
index++;
|
||||||
|
|
||||||
|
System.out.println(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean continueLoop;
|
||||||
|
while (true){
|
||||||
|
continueLoop = false;
|
||||||
|
int choice = scanner.nextInt();
|
||||||
|
FightMoves move = moves.get(choice);
|
||||||
|
|
||||||
|
switch (move) {
|
||||||
|
case FightMoves.LIGHT_ATTACK -> player.LightAttack(enemy);
|
||||||
|
case FightMoves.HEAVY_ATTACK -> player.HeavyAttack(enemy);
|
||||||
|
case FightMoves.SPECIAL -> player.SpecialAbility(enemy);
|
||||||
|
case FightMoves.HEAL -> player.HealMove();
|
||||||
|
case FightMoves.DEFEND -> player.defend();
|
||||||
|
default -> continueLoop = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!continueLoop) {
|
||||||
|
return move;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showMoveExplanation(FightMoves move, Entity performer, Entity receiver) {
|
||||||
|
switch (move) {
|
||||||
|
case FightMoves.LIGHT_ATTACK -> System.out.println(performer.Name + " performs a light attack");
|
||||||
|
case FightMoves.HEAVY_ATTACK -> System.out.println(performer.Name + " performs a heavy attack");
|
||||||
|
case FightMoves.SPECIAL -> System.out.println(performer.GetSpecialAbilityResultDescription(receiver));
|
||||||
|
case FightMoves.HEAL -> System.out.println(performer.Name + " heals");
|
||||||
|
case FightMoves.DEFEND -> System.out.println(performer.Name + " get their guard up!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public abstract class Player extends Entity {
|
|||||||
|
|
||||||
public void LevelUpTo(int level) {
|
public void LevelUpTo(int level) {
|
||||||
while (Level < level) {
|
while (Level < level) {
|
||||||
LevelUp();
|
UnconditionalLevelUp();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,13 +43,11 @@ public abstract class Player extends Entity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LevelUp() {
|
public void UnconditionalLevelUp() {
|
||||||
while (LevelProgress >= 100) {
|
|
||||||
Level++;
|
Level++;
|
||||||
double upgradeRatio = (1.1 + ((double) Level * 0.02));
|
double upgradeRatio = (1.1 + ((double) Level * 0.02));
|
||||||
int gift = Level * 10;
|
int gift = Level * 10;
|
||||||
|
|
||||||
LevelProgress -= 100;
|
|
||||||
MaxStamina = (int) (MaxStamina * upgradeRatio);
|
MaxStamina = (int) (MaxStamina * upgradeRatio);
|
||||||
MaxHealth = (int) (MaxHealth * upgradeRatio);
|
MaxHealth = (int) (MaxHealth * upgradeRatio);
|
||||||
BaseDamage = (int) (BaseDamage * upgradeRatio);
|
BaseDamage = (int) (BaseDamage * upgradeRatio);
|
||||||
@@ -57,6 +55,12 @@ public abstract class Player extends Entity {
|
|||||||
HealAmount = (int) (HealAmount * upgradeRatio);
|
HealAmount = (int) (HealAmount * upgradeRatio);
|
||||||
ModifyMoney(gift, true);
|
ModifyMoney(gift, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void LevelUp() {
|
||||||
|
while (LevelProgress >= 100) {
|
||||||
|
UnconditionalLevelUp();
|
||||||
|
LevelProgress -= 100;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user