コード例 #1
0
 public void attack(Character c) {
   if ((Math.abs(c.getX() - x) < 2) && (Math.abs(c.getY() - y) < 2) && attacking == true) {
     image = attack;
     c.health -= genDamage();
     c.checkHealth();
   }
 }
コード例 #2
0
ファイル: Runtime.java プロジェクト: RikardLegge/Projects
  void inputListener() {
    if (keyboard.keyDown(KeyEvent.VK_W)) player.moveDir[1] = -1;
    else if (keyboard.keyDown(KeyEvent.VK_S)) player.moveDir[1] = 1;
    else player.moveDir[1] = 0;

    if (keyboard.keyDown(KeyEvent.VK_A)) player.moveDir[0] = -1;
    else if (keyboard.keyDown(KeyEvent.VK_D)) player.moveDir[0] = 1;
    else player.moveDir[0] = 0;

    if (keyboard.keyDown(KeyEvent.VK_1)) player.SetWeapon(1);
    if (keyboard.keyDown(KeyEvent.VK_2)) player.SetWeapon(2);
    if (keyboard.keyDown(KeyEvent.VK_3)) player.SetWeapon(3);
    if (keyboard.keyDown(KeyEvent.VK_4)) player.SetWeapon(4);
    if (keyboard.keyDown(KeyEvent.VK_5)) player.SetWeapon(5);
    if (keyboard.keyDown(KeyEvent.VK_6)) player.SetWeapon(6);
    if (keyboard.keyDown(KeyEvent.VK_7)) player.SetWeapon(7);
    if (keyboard.keyDown(KeyEvent.VK_8)) player.SetWeapon(8);
    if (keyboard.keyDown(KeyEvent.VK_9)) player.SetWeapon(9);

    if (keyboard.keyDownOnce(KeyEvent.VK_Z)) {
      if (showDebug) showDebug = false;
      else showDebug = true;
    }
    if (keyboard.keyDownOnce(KeyEvent.VK_F9)) {
      cheated = true;
      player.health = 1000000;
    }
    if (keyboard.keyDownOnce(KeyEvent.VK_F10)) {
      cheated = true;
      player.unlockWeapon(2, true);
      player.unlockWeapon(3, true);
      player.unlockWeapon(4, true);
    }
    if (keyboard.keyDownOnce(KeyEvent.VK_F11)) {
      cheated = true;
      player.upgradeWeapon(1, 1);
      player.upgradeWeapon(2, 1);
      player.upgradeWeapon(3, 1);
      player.upgradeWeapon(4, 1);
    }
    if (keyboard.keyDown(KeyEvent.VK_F12)) {
      cheated = true;
      player.score = (int) (player.score + 1 / delta);
    }

    if (keyboard.keyDownOnce(KeyEvent.VK_MINUS)) if (difficulty < 19) difficulty = difficulty + 1;
    if (keyboard.keyDownOnce(KeyEvent.VK_BACK_SLASH))
      if (difficulty > 1) difficulty = difficulty - 1;
    if (keyboard.keyDownOnce(KeyEvent.VK_ESCAPE)) paused = true;
    if (keyboard.keyDownOnce(KeyEvent.VK_M))
      if (removeMode) removeMode = false;
      else removeMode = true;

    if (mouse.buttonDown(1))
      player.Shoot(mouse.getPosition().getX() - xOffset, mouse.getPosition().getY() - yOffset);
  }
コード例 #3
0
ファイル: Runtime.java プロジェクト: RikardLegge/Projects
 void renderUI(Graphics2D g2d) {
   g2d.setFont(new Font("Courier New", Font.PLAIN, 12));
   g2d.setColor(Color.white);
   if (removeMode) g2d.setColor(Color.black);
   if (player.health < 0) player.health = 0;
   g2d.drawString(String.format("Helath: %s", player.health), 10, 20);
   g2d.drawString(String.format("Kills: %s", player.score), 10, 40);
   int WLevel = (Integer) player.weapon[player.currentWeapon][10];
   if (WLevel == 5)
     g2d.drawString(String.format("Current Weapon: %s:Max", player.currentWeapon), 10, 60);
   else
     g2d.drawString(String.format("Current Weapon: %s:%s", player.currentWeapon, WLevel), 10, 60);
   g2d.setColor(Color.gray);
   g2d.drawString(String.format("Level: %s", difficulty), 10, 80);
   g2d.setColor(Color.black);
   if (showDebug) g2d.drawString(String.format("FPS: %s", fps), 10, 100);
   if (cheated) g2d.drawString("You cheated, no highscore will be saved", 200, height - 15);
 }
コード例 #4
0
ファイル: Character.java プロジェクト: dmunner/TextAdventure
  public void battle(Character enemy) {
    System.out.printf("%s appears!\n", enemy.name);

    while (health > 0 && enemy.health > 0) {
      health -= enemy.damage;
      // health equals health minus enemy damage is above
      enemy.health -= damage;
      System.out.printf("%s's health: %d\n", name, health);
      System.out.printf("%s's health: %d\n", enemy.name, enemy.health);
    }

    String message = "%s has died!\n";

    if (health <= 0) {
      System.out.printf(message, name);
    }
    if (enemy.health <= 0) {
      System.out.printf(message, enemy.name);
    }
  }
コード例 #5
0
ファイル: Battle.java プロジェクト: ddcaeste/CoolRPG
  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;
  }
コード例 #6
0
ファイル: Battle.java プロジェクト: ddcaeste/CoolRPG
  public static boolean bossBattle(Character player, Boss boss) throws InterruptedException {
    Texts.printIntro(boss);
    while (player.health > 0 && boss.health > 0) {
      int choice = MenuPrints.bossBattleMenu(player, boss);
      boolean won = true;
      Random random = new Random();
      if (choice == 1) // ATTACK
      {
        System.out.println("* Swoosh.");
        int hitchance;
        int hit = 0;
        if (player.stats[2] - boss.stats[2] < 0) hitchance = 2;
        else hitchance = 2 + player.stats[2] - boss.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
        boss.health = boss.health - hit;
        if (hit == 0) System.out.println(MenuPrints.bossBattleMiss(boss));
        else System.out.println(MenuPrints.bossBattleHit(boss));
        System.out.println("* You hit the " + boss.race + " for " + hit + " points of damage! :D");

        if (boss.stats[2] - player.stats[2] < 0) hitchance = 2;
        else hitchance = 2 + boss.stats[2] - player.stats[2];
        hityesorno = random.nextInt(hitchance);
        try {
          hit =
              ((((boss.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 " + boss.race + " has missed you!");
        else
          System.out.println(
              "* The " + boss.race + " has hit you for " + hit + " points of damage!");
        Thread.sleep(1500);
        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);
        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 * (boss.weakness[castedSpell.element]) / 100) * randommodfier;
            boss.health = boss.health - hit;
            System.out.println("* " + castedSpell.incantation + "...");
            System.out.println(
                "* You hit the " + boss.race + " for " + hit + " points of damage! :D");
            hit =
                (boss.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 " + boss.race + " 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 (player.health <= 0) {
      won = false;
      for (int i = 0; i < 100; ++i) System.out.println();
      System.out.println("You have been defeated!");
      // DEFEAT MESSAGE
    } else if (boss.health <= 0) {
      for (int i = 0; i < 100; ++i) System.out.println();
      System.out.println("* You have slain " + boss.bossFullName + ", the " + boss.race + " !");
      System.out.println(
          "* You are a true hero, worthy to be written down in the books of history!");
      Thread.sleep(5000);
      for (int i = 0; i < 100; ++i) System.out.println();
      won = true;
      // int phatlewt = 200;
      // System.out.println("* You loot " + phatlewt + " coins from the " + monsterString + ".");
      //          GAME ENDS
      // player.money += phatlewt;
      // REHEAL CHEAT ;D
      // player.experience = player.experience + monster.stats[4]*20;
      // System.out.println("* You gain " + monster.stats[4]*20 + " experience!");
      // 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);// VICCTORY MESSAGE + LOOT
      // }
    }
    return won;
  }