コード例 #1
0
  /**
   * All available commands which can be used in the game and it´s function in a private boolean
   * Returns false if text input is no available command Returns true if command was executed
   * successfully
   */
  private boolean openInventory() {
    if (!input.toLowerCase().equals("open inventory")) {
      return false;
    }

    for (int i = 0; i < winner.getInventorySize(); i++) {
      textOut(
          winner.getInventory(i).getType() + " (" + winner.getInventory(i).getStrength() + " ap)");
    }
    input = "";
    if (this.equip()) {}

    return true;
  }
コード例 #2
0
  private boolean equip() {
    if (winner == null) {
      return false;
    }

    for (int i = 0; i < winner.getInventorySize(); i++) {
      if (input.equals("equip " + winner.getInventory(i).getType())) {
        winner.setEquipedWeapon(looser.getEquipedWeapon());
        looser.removeInventory(looser.getEquipedWeapon());
        winner.setTotalStrength();
        textOut(winner.getEquipedWeapon().getType() + " equiped");
        input = "";
      }
    }
    return true;
  }
コード例 #3
0
  /**
   * First choose of random players to fight against each other then give a short message about
   * winner, looser and weapons If the search list is empty a message about the winner of the whole
   * game is sent to the console
   */
  private void mainProgram() {
    if (searchList.size() > 1) {
      textOut.append("\n");
      Player opponent1 = searchList.get(new Random().nextInt(searchList.size()));
      searchList.remove(opponent1);
      Player opponent2 = searchList.get(new Random().nextInt(searchList.size()));
      searchList.remove(opponent2);
      int opponent1Strength = opponent1.getTotalStrength();
      int opponent2Strength = opponent2.getTotalStrength();

      if (opponent1Strength > opponent2Strength) {
        winner = opponent1;
        looser = opponent2;
      } else if (opponent1Strength < opponent2Strength) {
        winner = opponent2;
        looser = opponent1;
      } else {
        if (new Random().nextBoolean() == true) {
          winner = opponent1;
          looser = opponent2;
        } else {
          winner = opponent2;
          looser = opponent1;
        }
      }

      textOut.append(
          winner.getName()
              + " killed "
              + looser.getName()
              + " with "
              + winner.getEquipedWeapon().getType()
              + " ("
              + winner.getEquipedWeapon().getStrength()
              + " ap). "
              + looser.getEquipedWeapon().getType()
              + " ("
              + looser.getEquipedWeapon().getStrength()
              + " ap) is now in "
              + winner.getName()
              + "´s inventory.\n");
      searchList.add(winner);
      winner.addInventory(looser.getEquipedWeapon());
      if (searchList.size() == 1) {
        textOut.append("\n");
        textOut.append(winner.getName() + " won the game!!! Congrantiolations!\n");
      }
      looser.setDead();

      if (this.openInventory()) {

      } else if (this.equip()) {

      } else if (this.exit()) {

      } else if (this.restart()) {

      } else {

      }
    }
  }