public static void main(String[] args) throws IOException { Character debug = new Character("Debug", 0, 0); Character debug2 = new Character("Debug2", 0, 1); ShortSword testsword = new ShortSword("TairaSlayer"); Armor testarmor = new Armor("TestArmor"); System.out.print("Level: "); System.out.println(debug.getLevel()); System.out.print("Health, pre levelup: "); System.out.println(debug.getHealth()); debug.levelUp(); System.out.print("Level: "); System.out.println(debug.getLevel()); System.out.print("Health, post levelup: "); System.out.println(debug.getHealth()); System.out.println("Name of Testsword: " + testsword.name); System.out.println("Testswords damage: " + testsword.damage); System.out.println("Equipped damage: " + debug.equippedDamage()); System.out.println("Start Equip"); debug.equipWeapon(testsword); // debug.equipWeapon(testsword); debug2.equipArmor(testarmor); System.out.println("Equipped Damage: " + debug.equippedDamage()); System.out.println("Equip Finished"); System.out.println("Debugs health prefight: " + debug.getHealth()); System.out.println("Debug2s health prefight: " + debug2.getHealth()); Action.Fight(debug, debug2); debug.checkDead(); debug2.checkDead(); System.out.println("Debugs health postfight: " + debug.getHealth()); System.out.println("Debug2s health postfight: " + debug2.getHealth()); System.out.println("Is debug dead? " + debug.getDead()); System.out.println("Is debug2 dead? " + debug2.getDead()); Tile testTile = new Tile(Tile.Type.DIRT); Map map = new Map(testTile); System.out.println("printing testtile.."); // System.out.println(testTile.getType()); System.out.println("printing map.."); System.out.println(map); Map map1 = map.readMap( "maps/map1.txt", "maps/map1h.txt"); // Just change ArrayList stuff to Map when readmap has been updated. // System.out.println(map.getTile(0,0,1).getType()); }
public boolean Battle() throws IOException { player.update(); boolean alive = true; int health; flee = false; P_HEALTH = player.getHealth(); PC_HEALTH = player.getCHealth(); plevel = player.getLevel(); elevel = elgen.nextInt(2) + (plevel - 1); if (elevel != -1) { health = 70 + (elevel) * 30; } else { health = 70; elevel = 0; } E_HEALTH = health; EC_HEALTH = health; H.pln("You have encountered a level " + elevel + " enemy"); while (EC_HEALTH > 0 && PC_HEALTH > 0 && !flee) { engine = new Random(); H.pln("Your Health: " + PC_HEALTH + "/" + P_HEALTH); H.pln("Enemy's Health : " + EC_HEALTH + "/" + E_HEALTH); H.pln("What do you want to do?"); H.pln("(1)Attack, (2)Defend, (3)Flee"); choice = H.inputInt(); switch (choice) { case 1: if (engine.nextInt(99) + 1 <= 95) { damage = (int) ((engine.nextInt(P_MAX_DAMAGE[plevel])) * wD[player.getWeapon()]); if (damage <= EC_HEALTH) { H.pln("Enemy lost " + damage + " health!"); EC_HEALTH -= damage; } else { helper = EC_HEALTH; H.pln("Enemy lost " + helper + " health!"); EC_HEALTH -= damage; } } else { if (plevel <= 8) { damage = (int) (engine.nextInt(P_MAX_DAMAGE[plevel + 2]) * wD[player.getWeapon()]); H.pln("Critical Hit!"); if (damage <= EC_HEALTH) { H.pln("Enemy lost " + damage + " health!"); EC_HEALTH -= damage; } else { helper = EC_HEALTH; H.pln("Enemy lost " + helper + " health!"); EC_HEALTH = 0; } } else { if (plevel == 9) { damage = (int) (engine.nextInt(P_MAX_DAMAGE[plevel + 1]) * wD[player.getWeapon()]); H.pln("Critical Hit!"); if (damage <= EC_HEALTH) { H.pln("Enemy lost " + damage + " health!"); EC_HEALTH -= damage; } else { helper = EC_HEALTH; H.pln("Enemy lost " + helper + " health!"); EC_HEALTH -= damage; } } if (plevel == 10) { damage = EC_HEALTH; H.pln("You destroyed the Enemy with one blow!!!"); } } } damage = engine.nextInt(E_MAX_DAMAGE[elevel]) + 1; H.pln("You lost " + damage + " health"); PC_HEALTH -= damage; player.setCHealth(PC_HEALTH); if (player.getCHealth() <= 0) return false; break; case 2: H.pln("You have blocked the enemy attack!"); break; case 3: H.pln("You have fled"); flee = true; break; } } if (EC_HEALTH <= 0 && PC_HEALTH > 0) { player.addXP(EC_HEALTH * (-1)); H.pln("You gained " + String.valueOf(EC_HEALTH * (-1)) + " XP!"); } if (flee) { player.addXP((EC_HEALTH) * (-1)); H.pln("You lost " + EC_HEALTH + " XP!"); } player.saveAll(); return true; }
public int attack(Character other) { int answer = 0; String linebr = "--------------------------------"; if (pc == true) { say(linebr); System.out.println("Choose your attack:"); System.out.println("Press 1 to unleash FIREBALL"); System.out.println("Press 2 to unleash ICE STORM"); System.out.println("Press 3 to unleash EARTHSHAKER"); System.out.println("Press 4 to whack your opponent with your STAFF"); Scanner sc = new Scanner(System.in); answer = sc.nextInt(); System.out.println(linebr); } else if (pc == false) { Random r = new Random(); answer = r.nextInt(4) + 1; } delay(2000); System.out.println("Roll:" + roll() + " | Dexterity: " + this.dexterity); if (roll() >= this.dexterity) { if (answer == 1) { if (mana >= 8) { other.takedamage(11); mana = mana - 8; say(this.name + " has unleashed a FIREBALL upon " + other.name); say(this.name + " has " + this.mana + " mana left."); say( other + " has lost 11 health points and has " + other.getHealth() + " health points left"); // return super.attack(other); } else { System.out.println("You don't have enough mana!"); } } else if (answer == 2) { if (mana >= 3) { other.takedamage(6); mana = mana - 3; say(this.name + " has unleashed an ICESTORM upon " + other.name); say(this.name + " has " + this.mana + " mana left."); say( other + " has lost 6 health points and has " + other.getHealth() + " health points left"); } else { System.out.println("You don't have enough mana!"); } } else if (answer == 3) { if (mana >= 5) { other.takedamage(8); mana = mana - 5; say(this.name + " has unleashed an EARTHSHAKER upon " + other.name); say(this.name + " has " + this.mana + " mana left."); say( other + " has lost 8 health points and has " + other.getHealth() + " health points left."); } else { System.out.println("You don't have enough mana!"); } } else if (answer == 4) { other.takedamage(3); say(this.name + " whacked " + other.name + " with a staff!"); say( other + " has lost 3 health points and has " + other.getHealth() + " health points left."); } else { say("I'm sorry. It does not seem you have this spell in your arsenal."); } say(linebr); } else { say(this.name + "'s attack missed!"); if (answer == 1) mana = mana - 8; else if (answer == 2) mana = mana - 3; else if (answer == 3) mana = mana - 5; say(this.name + " has " + this.mana + " mana left."); say(linebr); } /*if (this.health <= 5){ if (this.flee(other)){ return 0; } } if (other.health <= 5){ if (other.flee(this)){ return 1; } } if (this.health <= 0){ this.die(); return 2; } else{ other.die(); return 3; }*/ return 0; }