Exemple #1
0
 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());
 }
Exemple #2
0
  public static boolean battleStarts(Character player, Monster monster)
      throws InterruptedException {
    String monsterString = monster.trait + " " + monster.color + " " + monster.name;
    if (monster.trait == "") {
      monsterString = monster.color + " " + monster.name;
    }
    System.out.println("* A wild " + monsterString + " appears!");
    while (player.health > 0 && monster.health > 0) {
      int choice = MenuPrints.battleMenu(player, monster);
      won = true;
      random = new Random();
      if (choice == 1) // ATTACK
      {
        System.out.println("* Swoosh.");
        int hitchance;
        int hit;
        if (player.stats[2] - monster.stats[2] < 0) hitchance = 2;
        else hitchance = 2 + player.stats[2] - monster.stats[2];
        int hityesorno = random.nextInt(hitchance);
        try {
          hit =
              ((player.playerEqDamage + player.stats[0])
                      * (2 + (random.nextInt(5) / 2))
                      / hityesorno)
                  * hityesorno;
        } catch (ArithmeticException e) {
          hit = 0;
        } // MISS WANT DIVIDED BY ZERO :D
        monster.health = monster.health - hit;
        if (hit == 0) {
          System.out.println("* You miss the " + monsterString + "! D:");
        } else if (hit == 42) {
          System.out.println("* You give this monster the answer to the question.");
        } // FIRST EASTER EGG
        else {
          System.out.println(
              "* You hit the " + monsterString + " for " + hit + " points of damage! :D");
        }

        if (monster.stats[2] - player.stats[2] < 0) hitchance = 2;
        else hitchance = 2 + monster.stats[2] - player.stats[2];
        hityesorno = random.nextInt(hitchance);
        try {
          hit =
              ((((monster.stats[0] * (1 + random.nextInt(5)))
                          - (player.playerEqDefense * (1 + random.nextInt(3))))
                      / hityesorno)
                  * hityesorno);
        } catch (ArithmeticException e) {
          hit = 0;
        } // MISS WANT DIVIDED BY ZERO :D
        if (hit < 0) hit = 0;
        player.health = player.health - hit;
        if (hit == 0) {
          System.out.println("* The " + monsterString + " has missed you! :D");
        } else {
          System.out.println("* You have been hit for " + hit + " points of damage! D:");
        }
        Thread.sleep(1000);
        for (int i = 0; i < 100; ++i) System.out.println();
      }
      if (choice == 2) // OMNOMNONMONMNONMONNOMNOMNONM
      {
        for (int i = 0; i < 100; ++i) System.out.println();
        MenuPrints.printInventory(player.inventory);
        MenuPrints.inventoryConsumeYN(player);
      }
      if (choice == 3) {
        for (int i = 0; i < 100; ++i) System.out.println();
        Library.writeSpellInventory(player.spellbook, false);
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();
        String input = scanner.nextLine();
        for (int i = 0; i < 100; ++i) System.out.println();
        input = input.trim();
        int inputInt = 0;
        try {
          inputInt = Integer.parseInt(input);
        } catch (NumberFormatException e) {
        }
        if (inputInt > 0 && inputInt <= player.spellbook.size()) {
          Spell castedSpell = player.spellbook.get(inputInt - 1);
          if (player.mana >= castedSpell.manacost) {
            player.mana = player.mana - castedSpell.manacost;
            int randommodfier = 1 + (random.nextInt(10) / 10);
            int hit =
                (castedSpell.power * (monster.weakness[castedSpell.element]) / 100) * randommodfier;
            monster.health = monster.health - hit;
            System.out.println("* " + castedSpell.incantation + "...");
            System.out.println(
                "* You hit the " + monsterString + " for " + hit + " points of damage! :D");
            hit =
                (monster.stats[0] * random.nextInt(5))
                    - (player.playerEqDefense * random.nextInt(3));
            if (hit < 0) {
              hit = 0;
            }
            player.health = player.health - hit;
            if (hit == 0) {
              System.out.println("* The " + monsterString + " has missed you! :D");
            } else {
              System.out.println("* You have been hit for " + hit + " points of damage! D:");
            }
            Thread.sleep(1000);
          } else {
            System.out.println("You need more mana!");
          }
          Thread.sleep(1000);
          for (int i = 0; i < 100; ++i) System.out.println();
        } else {
          for (int i = 0; i < 100; ++i) System.out.println();
          System.out.println("* Nevermind then.");
          Thread.sleep(1000);
          for (int i = 0; i < 100; ++i) System.out.println();
        }
      }
      if (choice == 4) // RUNFORTHEELIFE
      {
        if (player.stats[2] * random.nextInt(3) >= monster.stats[2] * random.nextInt(2)) {
          // LOL XD COWARD
          for (int i = 0; i < 100; ++i) System.out.println();
          System.out.println("* Got away safely!");
          Thread.sleep(1000);
          for (int i = 0; i < 100; ++i) System.out.println();
          return true;
        } else {
          for (int i = 0; i < 100; ++i) System.out.println();
          System.out.println("* The " + monsterString + " is not amused.");
          int hit =
              (monster.stats[0] * random.nextInt(5)) - (player.playerEqDefense * random.nextInt(3));
          if (hit < 0) {
            hit = 0;
          }
          player.health = player.health - hit;
          if (hit == 0) {
            System.out.println("* The " + monsterString + " has missed you! :D");
          } else {
            System.out.println("* You have been hit for " + hit + " points of damage! D:");
          }
          Thread.sleep(2000);
          for (int i = 0; i < 100; ++i) System.out.println();
        }
      }
    }
    if (player.health <= 0) {
      System.out.println("* You have been slain in combat!");
      Thread.sleep(3000);
      for (int i = 0; i < 100; ++i) System.out.println();
      return false;
    }
    if (monster.health <= 0) {
      System.out.println("* You have slain the " + monsterString + " !");
      won = true;
      int phatlewt = 0;
      phatlewt = ((2 + random.nextInt(9)) * (1 + (random.nextInt(player.stats[5] * 10) / 10)));
      System.out.println("* You loot " + phatlewt + " coins from the " + monsterString + ".");
      player.money += phatlewt;
      Item gottenItem = Lootlist.lootGenerate();
      player.inventory.add(gottenItem);
      player.initializeEquipment();
      System.out.println("* You found a " + gottenItem.itemName);
      // REHEAL CHEAT ;D
      player.experience = player.experience + monster.stats[4] * 20;
      System.out.println(
          "* You gain "
              + monster.stats[4] * 20
              + " experience!"); // MAKE A CHECK EXP AND LEVEL UP THING IN THE FUTURE :D
      while (player.experience >= (100 + ((player.level * player.level) * 100))) {
        player.experience = player.experience - (100 + ((player.level * player.level) * 100));
        player.levelUp();
        System.out.println("* You have gained a level!!! :)");
        System.out.println("* Your level now is : " + player.level);
        Thread.sleep(3000);
        for (int i = 0; i < 100; ++i) System.out.println();
      }
    }
    return won;
  }