develop #1

Open
mahdi_Goudarzi wants to merge 5 commits from develop into main
18 changed files with 125 additions and 49 deletions
Showing only changes of commit 526f07f2c7 - Show all commits
+93 -39
View File
@@ -26,6 +26,7 @@ public class Main {
public static Entity enemy; public static Entity enemy;
public static Scanner input = new Scanner(System.in); public static Scanner input = new Scanner(System.in);
public static ArrayList<Boolean> keys = new ArrayList<Boolean>(); public static ArrayList<Boolean> keys = new ArrayList<Boolean>();
public static boolean running = true;
public static void main(String[] args) { public static void main(String[] args) {
@@ -33,45 +34,50 @@ public class Main {
startMenu(); startMenu();
while (true){ while (running){ // when exit ruuning will be false
do{ do{
System.out.println("===============================");
Location fightLoc = fightMenu(); try { // if we have null location we handle with this try/catch
enemy = fightLoc.getEnemie(); System.out.println("===============================");
System.out.println(enemy.toString() + "| HP:" + enemy.getHp()); Location fightLoc = fightMenu(); // make location with random enemy
System.out.println("Do you want fight?"); enemy = fightLoc.getEnemie();
System.out.println("1.Yes"); System.out.println(enemy.toString() + "| HP:" + enemy.getHp());
System.out.println("2.No(Go to another location)"); System.out.println("Do you want fight?");
int n = input.nextInt(); System.out.println("1.Yes");
if(n==1){ System.out.println("2.No(Go to another location)");
gameplay(); int n = input.nextInt();
if(!player.isalive()){ if(n==1){
System.out.println("==============================="); gameplay(); // if you want play go to gameplay()
System.out.println( YELLOW + "Goodby!"); if(!player.isalive()){ // result of match
return; System.out.println("===============================");
System.out.println( YELLOW + "Goodby!");
return;
}
else {
System.out.println(BLUE);
player.repair();
System.out.println(RESET);
}
} }
else { else if(n >= 3){
System.out.println(BLUE); System.out.println("Invalid input");
player.repair();
System.out.println(RESET);
} }
} }catch (NullPointerException exception){
else if(n >= 3){ System.out.println( YELLOW + "Goodby!");
System.out.println("Invalid input"); return;
} }
}while (true); }while (running);
} }
// TODO: IMPLEMENT GAMEPLAY
} }
//make keys array
public static void setKeys(){ public static void setKeys(){ // set key array for enemies
boolean goblinkey=false; boolean goblinkey=false;
boolean skeletonkey = false; boolean skeletonkey = false;
boolean vampirekey = false; boolean vampirekey = false;
@@ -80,7 +86,9 @@ public class Main {
keys.add(vampirekey); keys.add(vampirekey);
} }
/**
this method choose for player in game
*/
public static void startMenu(){ public static void startMenu(){
System.out.println("----------Welcome to Java-Knight----------"); System.out.println("----------Welcome to Java-Knight----------");
setKeys(); setKeys();
@@ -91,7 +99,7 @@ public class Main {
System.out.println("2. \uD83E\uDDD9\u200D♂\uFE0F Wizard (High HP)"); System.out.println("2. \uD83E\uDDD9\u200D♂\uFE0F Wizard (High HP)");
System.out.println("3. \uD83D\uDDE1\uFE0F Assassin (High Mana)"); System.out.println("3. \uD83D\uDDE1\uFE0F Assassin (High Mana)");
boolean validInput = false; boolean validInput = false; // check for vaild input
while (!validInput){ while (!validInput){
System.out.print("chose:"); System.out.print("chose:");
int choose =input.nextInt(); int choose =input.nextInt();
@@ -125,8 +133,13 @@ public class Main {
} }
} }
/**
* make a location
* @return location with random enemy
*/
public static Location fightMenu(){ public static Location fightMenu(){
boolean dragonOpen = true; boolean dragonOpen = true; // check drangon is open
for (Boolean b : keys){ for (Boolean b : keys){
if(b == false){ if(b == false){
dragonOpen = false; dragonOpen = false;
@@ -140,7 +153,7 @@ public class Main {
System.out.println("2.Sea"); System.out.println("2.Sea");
System.out.println("3.Jungle"); System.out.println("3.Jungle");
for(boolean b : keys){ for(boolean b : keys){ // for every key chek and write lock or tik
if(b){ if(b){
System.out.print("\uFE0F"); System.out.print("\uFE0F");
@@ -151,6 +164,8 @@ public class Main {
} }
if(dragonOpen) { if(dragonOpen) {
System.out.println("4.Dranon"); System.out.println("4.Dranon");
} }
@@ -158,11 +173,12 @@ public class Main {
System.out.println("Dragon"); 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; Entity enemy = null;
if(n == 0){ if(n == 0){
enemy = new Goblin(); enemy = new Goblin();
@@ -182,6 +198,11 @@ public class Main {
System.out.print("chose:"); System.out.print("chose:");
int choose =input.nextInt(); int choose =input.nextInt();
switch (choose){ switch (choose){
case 0:
{
running = false;
return null;
}
case 1: case 1:
{ {
location = new Location("Desert" , enemy); location = new Location("Desert" , enemy);
@@ -237,8 +258,12 @@ public class Main {
} }
/**
* main loop of game
*/
public static void gameplay(){ public static void gameplay(){
boolean playerTurn = true; boolean playerTurn = true; // flag for check for turn
while (player.isalive() && enemy.isalive()){ while (player.isalive() && enemy.isalive()){
@@ -252,7 +277,7 @@ public class Main {
System.out.println("\n"+GREEN + "It's your Turn" +RESET); System.out.println("\n"+GREEN + "It's your Turn" +RESET);
while (true){ while (true){
if(playerAttakMenu()){ if(playerAttakMenu()){ // maybe not enough mp and should choose again
break; break;
} }
@@ -260,15 +285,24 @@ public class Main {
playerTurn = !playerTurn; 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); System.out.println("\n"+ RED);
enemy.specialAbility(player); enemy.specialAbility(player);
System.out.println(RESET); System.out.println(RESET);
playerTurn = !playerTurn; playerTurn = !playerTurn;
} }
// for win senario
if(!enemy.isalive()){ if(!enemy.isalive()){
System.out.println("you WIN"); 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(n== 0){
if(enemy instanceof Goblin){ if(enemy instanceof Goblin){
if(keys.get(0) == true){ 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"); System.out.println(enemy.toString() + " Can't do any act");
enemy.truepossible(); enemy.truepossible();
playerTurn = !playerTurn; playerTurn = !playerTurn;
continue; continue;
} }
if(enemy.getpossible() && !playerTurn){ if(enemy.getpossible() && !playerTurn){
System.out.println("\n" + RED +"It's enemy Turn" + RESET); System.out.println("\n" + RED +"It's enemy Turn" + RESET);
enemyAttakMenu(); enemyAttakMenu(); // randoum act from enemy;
playerTurn = !playerTurn; playerTurn = !playerTurn;
} }
if(!player.isalive()){ if(!player.isalive()){ // result
System.out.println("you lose"); System.out.println("you lose");
return; return;
} }
@@ -331,6 +366,10 @@ public class Main {
} }
/**
* selet a random act for each enemy
*/
public static void enemyAttakMenu(){ public static void enemyAttakMenu(){
if(enemy instanceof Goblin || enemy instanceof Vampire){ if(enemy instanceof Goblin || enemy instanceof Vampire){
int n = (int) (Math.random()*3); 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){ if(enemy.getHp() <= 0){
enemy.heavyattack(player); 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() { public static boolean playerAttakMenu() {
System.out.print("1.Light attak| "); System.out.print("1.Light attak| ");
@@ -14,12 +14,14 @@ public class Dragon extends Enemy{
public void specialAbility(Entity target){ public void specialAbility(Entity target){
heavyattack(target); target.getArmor().brokeArmor();
//sout : fire! System.out.println(toString()+"\uD83D\uDD25 FIRE!! special ability" );
target.takeDamage(2 * weapon.getDamage());
} }
public String toString(){ public String toString(){
String str = "Dragon |" + "Hp:" + getHp(); return "\uD83D\uDC09 Dragon";
return str;
} }
} }
@@ -37,7 +37,7 @@ public abstract class Enemy implements Entity {
public void heavyattack(Entity target){ 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()); target.takeDamage(2 * weapon.getDamage());
} }
@@ -28,6 +28,10 @@ public class Skeleton extends Enemy {
} }
public boolean getResurrect(){
return resurrect;
}
public String toString(){ public String toString(){
return "\uFE0F Skeleton "; return "\uFE0F Skeleton ";
@@ -72,7 +72,7 @@ public abstract class Player implements Entity {
armor.use(this); armor.use(this);
} }
else { else {
System.out.println("you take " + (damage - armor.getDefense())); System.out.println("you take " + (damage - armor.getDefense()) + " Damage");
hp -=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"); 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() { public String getName() {
return name; return name;
} }
@@ -25,6 +25,9 @@ public abstract class Armor implements Item {
public boolean checkBreak() { public boolean checkBreak() {
if(isBroke){
return true;
}
if (durability <= 0) { if (durability <= 0) {
isBroke = true; isBroke = true;
defense = 0; defense = 0;
@@ -64,4 +67,8 @@ public abstract class Armor implements Item {
public boolean isBroke() { public boolean isBroke() {
return isBroke; return isBroke;
} }
public void brokeArmor(){
isBroke =true;
}
} }
@@ -5,7 +5,7 @@ import org.project.entity.Entity;
public class DragonWepon extends Weapon{ public class DragonWepon extends Weapon{
public DragonWepon(){ public DragonWepon(){
super(40 , 10); super(25 , 10);
} }
public void use(Entity target){ public void use(Entity target){
@@ -2,6 +2,6 @@ package org.project.item.weapons;
public class knife extends Weapon{ public class knife extends Weapon{
public knife(){ public knife(){
super(15 , 8); super(20 , 8);
} }
} }
@@ -3,6 +3,6 @@ package org.project.item.weapons;
public class wood extends Weapon{ public class wood extends Weapon{
public wood(){ public wood(){
super(10, 8); super(15, 8);
} }
} }
Binary file not shown.