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
+75 -21
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,11 +34,13 @@ public class Main {
startMenu();
while (true){
while (running){ // when exit ruuning will be false
do{
try { // if we have null location we handle with this try/catch
System.out.println("===============================");
Location fightLoc = fightMenu();
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?");
@@ -45,8 +48,8 @@ public class Main {
System.out.println("2.No(Go to another location)");
int n = input.nextInt();
if(n==1){
gameplay();
if(!player.isalive()){
gameplay(); // if you want play go to gameplay()
if(!player.isalive()){ // result of match
System.out.println("===============================");
System.out.println( YELLOW + "Goodby!");
return;
@@ -60,18 +63,21 @@ public class Main {
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);
}
@@ -356,11 +395,26 @@ public class Main {
}
}
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| ");
@@ -14,12 +14,14 @@ public class Dragon extends Enemy{
public void specialAbility(Entity target){
heavyattack(target);
//sout : fire!
target.getArmor().brokeArmor();
System.out.println(toString()+"\uD83D\uDD25 FIRE!! special ability" );
target.takeDamage(2 * weapon.getDamage());
}
public String toString(){
String str = "Dragon |" + "Hp:" + getHp();
return str;
return "\uD83D\uDC09 Dragon";
}
}
@@ -37,7 +37,7 @@ public abstract class Enemy implements Entity {
public void heavyattack(Entity target){
System.out.println(toString() + " do a heavy attaked with " + weapon.getDamage() + " damages");
System.out.println(toString() + " do a heavy attaked with " + weapon.getDamage() * 2 + " damages");
target.takeDamage(2 * weapon.getDamage());
}
@@ -28,6 +28,10 @@ public class Skeleton extends Enemy {
}
public boolean getResurrect(){
return resurrect;
}
public String toString(){
return "\uFE0F Skeleton ";
@@ -72,7 +72,7 @@ public abstract class Player implements Entity {
armor.use(this);
}
else {
System.out.println("you take " + (damage - armor.getDefense()));
System.out.println("you take " + (damage - armor.getDefense()) + " Damage");
hp -=damage;
}
@@ -115,6 +115,15 @@ public abstract class Player implements Entity {
System.out.println( "Repair: we full your Hp , repair your armor and give you some Mp");
}
public void setKing(){
this.maxHP =1000;
this.hp=maxHP;
this.maxMP = 1000;
this.mp = maxMP;
armor.repair();
}
public String getName() {
return name;
}
@@ -25,6 +25,9 @@ public abstract class Armor implements Item {
public boolean checkBreak() {
if(isBroke){
return true;
}
if (durability <= 0) {
isBroke = true;
defense = 0;
@@ -64,4 +67,8 @@ public abstract class Armor implements Item {
public boolean isBroke() {
return isBroke;
}
public void brokeArmor(){
isBroke =true;
}
}
@@ -5,7 +5,7 @@ import org.project.entity.Entity;
public class DragonWepon extends Weapon{
public DragonWepon(){
super(40 , 10);
super(25 , 10);
}
public void use(Entity target){
@@ -2,6 +2,6 @@ package org.project.item.weapons;
public class knife extends Weapon{
public knife(){
super(15 , 8);
super(20 , 8);
}
}
@@ -3,6 +3,6 @@ package org.project.item.weapons;
public class wood extends Weapon{
public wood(){
super(10, 8);
super(15, 8);
}
}
Binary file not shown.