diff --git a/Java-Knight/src/main/java/org/project/Main.java b/Java-Knight/src/main/java/org/project/Main.java index b55ddbd..86c56a9 100644 --- a/Java-Knight/src/main/java/org/project/Main.java +++ b/Java-Knight/src/main/java/org/project/Main.java @@ -26,6 +26,7 @@ public class Main { public static Entity enemy; public static Scanner input = new Scanner(System.in); public static ArrayList keys = new ArrayList(); + 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| "); diff --git a/Java-Knight/src/main/java/org/project/entity/enemies/Dragon.java b/Java-Knight/src/main/java/org/project/entity/enemies/Dragon.java index 3380543..95bf668 100644 --- a/Java-Knight/src/main/java/org/project/entity/enemies/Dragon.java +++ b/Java-Knight/src/main/java/org/project/entity/enemies/Dragon.java @@ -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"; } } diff --git a/Java-Knight/src/main/java/org/project/entity/enemies/Enemy.java b/Java-Knight/src/main/java/org/project/entity/enemies/Enemy.java index 9ab8e09..7a96b13 100644 --- a/Java-Knight/src/main/java/org/project/entity/enemies/Enemy.java +++ b/Java-Knight/src/main/java/org/project/entity/enemies/Enemy.java @@ -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()); } diff --git a/Java-Knight/src/main/java/org/project/entity/enemies/Skeleton.java b/Java-Knight/src/main/java/org/project/entity/enemies/Skeleton.java index a0fc717..4bf4bee 100644 --- a/Java-Knight/src/main/java/org/project/entity/enemies/Skeleton.java +++ b/Java-Knight/src/main/java/org/project/entity/enemies/Skeleton.java @@ -28,6 +28,10 @@ public class Skeleton extends Enemy { } + public boolean getResurrect(){ + return resurrect; + } + public String toString(){ return "☠\uFE0F Skeleton "; diff --git a/Java-Knight/src/main/java/org/project/entity/players/Player.java b/Java-Knight/src/main/java/org/project/entity/players/Player.java index e60f6e5..c4656f0 100644 --- a/Java-Knight/src/main/java/org/project/entity/players/Player.java +++ b/Java-Knight/src/main/java/org/project/entity/players/Player.java @@ -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; } diff --git a/Java-Knight/src/main/java/org/project/item/armors/Armor.java b/Java-Knight/src/main/java/org/project/item/armors/Armor.java index be19f8f..22c9a11 100644 --- a/Java-Knight/src/main/java/org/project/item/armors/Armor.java +++ b/Java-Knight/src/main/java/org/project/item/armors/Armor.java @@ -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; + } } diff --git a/Java-Knight/src/main/java/org/project/item/weapons/DragonWepon.java b/Java-Knight/src/main/java/org/project/item/weapons/DragonWepon.java index cfa2e68..080ea52 100644 --- a/Java-Knight/src/main/java/org/project/item/weapons/DragonWepon.java +++ b/Java-Knight/src/main/java/org/project/item/weapons/DragonWepon.java @@ -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){ diff --git a/Java-Knight/src/main/java/org/project/item/weapons/knife.java b/Java-Knight/src/main/java/org/project/item/weapons/knife.java index 4b83f59..cf60f97 100644 --- a/Java-Knight/src/main/java/org/project/item/weapons/knife.java +++ b/Java-Knight/src/main/java/org/project/item/weapons/knife.java @@ -2,6 +2,6 @@ package org.project.item.weapons; public class knife extends Weapon{ public knife(){ - super(15 , 8); + super(20 , 8); } } diff --git a/Java-Knight/src/main/java/org/project/item/weapons/wood.java b/Java-Knight/src/main/java/org/project/item/weapons/wood.java index eceb5b8..39acdf7 100644 --- a/Java-Knight/src/main/java/org/project/item/weapons/wood.java +++ b/Java-Knight/src/main/java/org/project/item/weapons/wood.java @@ -3,6 +3,6 @@ package org.project.item.weapons; public class wood extends Weapon{ public wood(){ - super(10, 8); + super(15, 8); } } diff --git a/Java-Knight/target/classes/org/project/Main.class b/Java-Knight/target/classes/org/project/Main.class index bd4f443..503fd24 100644 Binary files a/Java-Knight/target/classes/org/project/Main.class and b/Java-Knight/target/classes/org/project/Main.class differ diff --git a/Java-Knight/target/classes/org/project/entity/enemies/Dragon.class b/Java-Knight/target/classes/org/project/entity/enemies/Dragon.class index f95da93..8624c15 100644 Binary files a/Java-Knight/target/classes/org/project/entity/enemies/Dragon.class and b/Java-Knight/target/classes/org/project/entity/enemies/Dragon.class differ diff --git a/Java-Knight/target/classes/org/project/entity/enemies/Enemy.class b/Java-Knight/target/classes/org/project/entity/enemies/Enemy.class index 2d3d1d0..73539c8 100644 Binary files a/Java-Knight/target/classes/org/project/entity/enemies/Enemy.class and b/Java-Knight/target/classes/org/project/entity/enemies/Enemy.class differ diff --git a/Java-Knight/target/classes/org/project/entity/enemies/Skeleton.class b/Java-Knight/target/classes/org/project/entity/enemies/Skeleton.class index 66fc54f..b9a3f5c 100644 Binary files a/Java-Knight/target/classes/org/project/entity/enemies/Skeleton.class and b/Java-Knight/target/classes/org/project/entity/enemies/Skeleton.class differ diff --git a/Java-Knight/target/classes/org/project/entity/players/Player.class b/Java-Knight/target/classes/org/project/entity/players/Player.class index f4da2eb..1e823a7 100644 Binary files a/Java-Knight/target/classes/org/project/entity/players/Player.class and b/Java-Knight/target/classes/org/project/entity/players/Player.class differ diff --git a/Java-Knight/target/classes/org/project/item/armors/Armor.class b/Java-Knight/target/classes/org/project/item/armors/Armor.class index 6467b83..bef4b72 100644 Binary files a/Java-Knight/target/classes/org/project/item/armors/Armor.class and b/Java-Knight/target/classes/org/project/item/armors/Armor.class differ diff --git a/Java-Knight/target/classes/org/project/item/weapons/DragonWepon.class b/Java-Knight/target/classes/org/project/item/weapons/DragonWepon.class index 46c55d8..6947e93 100644 Binary files a/Java-Knight/target/classes/org/project/item/weapons/DragonWepon.class and b/Java-Knight/target/classes/org/project/item/weapons/DragonWepon.class differ diff --git a/Java-Knight/target/classes/org/project/item/weapons/knife.class b/Java-Knight/target/classes/org/project/item/weapons/knife.class index d5c8755..3ab8b24 100644 Binary files a/Java-Knight/target/classes/org/project/item/weapons/knife.class and b/Java-Knight/target/classes/org/project/item/weapons/knife.class differ diff --git a/Java-Knight/target/classes/org/project/item/weapons/wood.class b/Java-Knight/target/classes/org/project/item/weapons/wood.class index c215821..8faa7e4 100644 Binary files a/Java-Knight/target/classes/org/project/item/weapons/wood.class and b/Java-Knight/target/classes/org/project/item/weapons/wood.class differ