complite main class + add some comment

This commit is contained in:
2026-05-14 11:38:52 +03:30
parent 38fdd06a03
commit 526f07f2c7
18 changed files with 125 additions and 49 deletions
+94 -40
View File
@@ -26,6 +26,7 @@ public class Main {
public static Entity enemy;
public static Scanner input = new Scanner(System.in);
public static ArrayList<Boolean> keys = new ArrayList<Boolean>();
public static boolean running = true;
public static void main(String[] args) {
@@ -33,45 +34,50 @@ public class Main {
startMenu();
while (true){
while (running){ // when exit ruuning will be false
do{
System.out.println("===============================");
Location fightLoc = fightMenu();
enemy = fightLoc.getEnemie();
System.out.println(enemy.toString() + "| HP:" + enemy.getHp());
System.out.println("Do you want fight?");
System.out.println("1.Yes");
System.out.println("2.No(Go to another location)");
int n = input.nextInt();
if(n==1){
gameplay();
if(!player.isalive()){
System.out.println("===============================");
System.out.println( YELLOW + "Goodby!");
return;
try { // if we have null location we handle with this try/catch
System.out.println("===============================");
Location fightLoc = fightMenu(); // make location with random enemy
enemy = fightLoc.getEnemie();
System.out.println(enemy.toString() + "| HP:" + enemy.getHp());
System.out.println("Do you want fight?");
System.out.println("1.Yes");
System.out.println("2.No(Go to another location)");
int n = input.nextInt();
if(n==1){
gameplay(); // if you want play go to gameplay()
if(!player.isalive()){ // result of match
System.out.println("===============================");
System.out.println( YELLOW + "Goodby!");
return;
}
else {
System.out.println(BLUE);
player.repair();
System.out.println(RESET);
}
}
else {
System.out.println(BLUE);
player.repair();
System.out.println(RESET);
else if(n >= 3){
System.out.println("Invalid input");
}
}
else if(n >= 3){
System.out.println("Invalid input");
}catch (NullPointerException exception){
System.out.println( YELLOW + "Goodby!");
return;
}
}while (true);
}while (running);
}
// TODO: IMPLEMENT GAMEPLAY
}
public static void setKeys(){
//make keys array
public static void setKeys(){ // set key array for enemies
boolean goblinkey=false;
boolean skeletonkey = false;
boolean vampirekey = false;
@@ -80,7 +86,9 @@ public class Main {
keys.add(vampirekey);
}
/**
this method choose for player in game
*/
public static void startMenu(){
System.out.println("----------Welcome to Java-Knight----------");
setKeys();
@@ -91,7 +99,7 @@ public class Main {
System.out.println("2. \uD83E\uDDD9\u200D♂\uFE0F Wizard (High HP)");
System.out.println("3. \uD83D\uDDE1\uFE0F Assassin (High Mana)");
boolean validInput = false;
boolean validInput = false; // check for vaild input
while (!validInput){
System.out.print("chose:");
int choose =input.nextInt();
@@ -125,8 +133,13 @@ public class Main {
}
}
/**
* make a location
* @return location with random enemy
*/
public static Location fightMenu(){
boolean dragonOpen = true;
boolean dragonOpen = true; // check drangon is open
for (Boolean b : keys){
if(b == false){
dragonOpen = false;
@@ -140,7 +153,7 @@ public class Main {
System.out.println("2.Sea");
System.out.println("3.Jungle");
for(boolean b : keys){
for(boolean b : keys){ // for every key chek and write lock or tik
if(b){
System.out.print("\uFE0F");
@@ -151,6 +164,8 @@ public class Main {
}
if(dragonOpen) {
System.out.println("4.Dranon");
}
@@ -158,11 +173,12 @@ public class Main {
System.out.println("Dragon");
}
System.out.println("0.EXIT (CLOSE GAME)");
int n = (int) ((Math.random()) *3);
int n = (int) ((Math.random()) *3); // a random number for random enemy
Entity enemy = null;
if(n == 0){
enemy = new Goblin();
@@ -182,6 +198,11 @@ public class Main {
System.out.print("chose:");
int choose =input.nextInt();
switch (choose){
case 0:
{
running = false;
return null;
}
case 1:
{
location = new Location("Desert" , enemy);
@@ -237,8 +258,12 @@ public class Main {
}
/**
* main loop of game
*/
public static void gameplay(){
boolean playerTurn = true;
boolean playerTurn = true; // flag for check for turn
while (player.isalive() && enemy.isalive()){
@@ -252,7 +277,7 @@ public class Main {
System.out.println("\n"+GREEN + "It's your Turn" +RESET);
while (true){
if(playerAttakMenu()){
if(playerAttakMenu()){ // maybe not enough mp and should choose again
break;
}
@@ -260,15 +285,24 @@ public class Main {
playerTurn = !playerTurn;
if(enemy instanceof Skeleton && !enemy.isalive()){
// for skeleton relive
if(enemy instanceof Skeleton && !enemy.isalive() && !((Skeleton) enemy).getResurrect()){
System.out.println("\n"+ RED);
enemy.specialAbility(player);
System.out.println(RESET);
playerTurn = !playerTurn;
}
// for win senario
if(!enemy.isalive()){
System.out.println("you WIN");
int n = (int) (Math.random()*2);
if(enemy instanceof Dragon){
System.out.println(YELLOW + "Congratulation \n + you are the kingdom of Gogorio" + RESET);
((Player) player).setKing(); // king senario;
}
int n = (int) (Math.random()*2); // 50% present enemy have key
if(n== 0){
if(enemy instanceof Goblin){
if(keys.get(0) == true){
@@ -301,22 +335,23 @@ public class Main {
}
if(!enemy.getpossible()){
if(!enemy.getpossible()){ // enemy is possible act?
System.out.println(enemy.toString() + " Can't do any act");
enemy.truepossible();
playerTurn = !playerTurn;
continue;
}
if(enemy.getpossible() && !playerTurn){
System.out.println("\n" + RED +"It's enemy Turn" + RESET);
enemyAttakMenu();
enemyAttakMenu(); // randoum act from enemy;
playerTurn = !playerTurn;
}
if(!player.isalive()){
if(!player.isalive()){ // result
System.out.println("you lose");
return;
}
@@ -331,6 +366,10 @@ public class Main {
}
/**
* selet a random act for each enemy
*/
public static void enemyAttakMenu(){
if(enemy instanceof Goblin || enemy instanceof Vampire){
int n = (int) (Math.random()*3);
@@ -347,7 +386,7 @@ public class Main {
}
else if(enemy instanceof Skeleton){
else if(enemy instanceof Skeleton){ // skeleton use special ability when he dead
if(enemy.getHp() <= 0){
enemy.heavyattack(player);
}
@@ -355,12 +394,27 @@ public class Main {
enemy.lightattack(player);
}
}
else if( enemy instanceof Dragon){
int n = (int)(Math.random()*3);
if(n==0){
enemy.specialAbility(player);
}
else {
enemy.lightattack(player);
}
}
}
/**
* choose a act for player
* @return was the act successful or no
*/
public static boolean playerAttakMenu() {
System.out.print("1.Light attak| ");