add engines

This commit is contained in:
Ramtin Jafari
2026-07-11 11:35:08 +03:30
parent cd1e244201
commit 5f1ffd2520
6 changed files with 136 additions and 0 deletions
@@ -0,0 +1,4 @@
package org.project.engine;
public class BattleEngine {
}
@@ -0,0 +1,16 @@
package org.project.engine;
import org.project.constants.appConstants.GameModes;
public abstract class MainEngine {
protected MainEngine() {}
public abstract void run();
public static MainEngine CreateEngine(GameModes mode) {
return switch (mode) {
case GameModes.SINGLE_PLAYER -> new SinglePlayerEngine();
case GameModes.MULTI_PLAYER_LOCAL -> new MultiplayerEngine();
};
}
}
@@ -0,0 +1,4 @@
package org.project.engine;
public class MultiPlayerBattleEngine {
}
@@ -0,0 +1,4 @@
package org.project.engine;
public class MultiplayerEngine extends MainEngine{
}
@@ -0,0 +1,4 @@
package org.project.engine;
public class SinglePlayerBattleEngine {
}
@@ -0,0 +1,104 @@
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.entity.players.Player;
import org.project.entity.players.Wizard;
import org.project.location.*;
import java.util.Scanner;
public class SinglePlayerEngine extends MainEngine {
private Player player;
public SinglePlayerEngine() {
super();
}
@Override
public void run() {
Scanner scanner = new Scanner(System.in);
System.out.println(TextColor.Cyan + GetIntro() + ConsoleColor.Reset);
System.out.println();
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");
int choice = scanner.nextInt();
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();
while (true) {
boolean canFightDragon = false;
if (player.GetInventoryByClass(ItemClass.KEY).size() == 3) {
canFightDragon = true;
}
Location location = Location.RandomLocation();
System.out.println(GetLocationIntro(location));
while (true) {
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"
);
if (canFightDragon) {
System.out.println("3 > Go to the castle to face the dragon");
}
int choice = scanner.nextInt();
switch (choice) {
case 0 -> {
}
}
}
}
}
public String GetIntro() {
return "For centuries, the land of Javanest lived in peace, until a magical Dragon attacked, plunging the realm into absolute darkness. With a wicked curse, the Dragon transformed the innocent people into horrific monsters: Goblins, Skeletons, and Vampires. Retreating to its impenetrable Castle, the Dragon divided the three keys to its lair and hid them among these cursed creatures. Now, it is your duty to step up and save the land. You must battle these monsters, recover the unique key from each monster type, and finally slay the Dragon to break the curse and restore peace to Javanest!";
}
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";
}
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 "";
}
}
}