예제 #1
0
파일: Village.java 프로젝트: ttkyle/TWFB
  // Sends the level of hiding place to the GUI
  public static void setHidingPlace() {

    for (int i = 2; i < 20; i++) {
      try {
        String hidingPlaceLabel =
            WebAutomation.driver
                .findElement(By.xpath("//*[@id=\"buildings\"]/tbody/tr[" + i + "]/td[1]"))
                .getText();
        if (substring(hidingPlaceLabel, 0, 6).equals("Hiding")) {
          BuildPanel.setHidingPlaceLabel("Hiding " + substring(hidingPlaceLabel, 7, 22));
          if (substring(hidingPlaceLabel, 13, 22).equals("")) {
            BuildPanel.setHidingPlaceLabel("Hiding place (Level 0)");
            BuildPanel.setHidingPlaceButtonTrueOrFalse(false);
          }
          break;
        } else {
          BuildPanel.setHidingPlaceLabel("Hiding place (Level 0)");
        }
      } catch (NoSuchElementException e) {
        BuildPanel.setUpgradeHidingPlaceLabel("Cannot upgrade");
        BuildPanel.setHidingPlaceButtonTrueOrFalse(false);
        BuildPanel.setHidingPlaceLabel("Hiding place max level");
      }
    }
  }
예제 #2
0
파일: Village.java 프로젝트: ttkyle/TWFB
  // Sends the level of academy to the GUI
  public static void setAcademy() {

    for (int i = 2; i < 20; i++) {
      try {
        String academyLabel =
            WebAutomation.driver
                .findElement(By.xpath("//*[@id=\"buildings\"]/tbody/tr[" + i + "]/td[1]"))
                .getText();
        if (substring(academyLabel, 0, 7).equals("Academy")) {
          BuildPanel.setAcademyLabel("Academy " + substring(academyLabel, 8, 16));
          if (substring(academyLabel, 8, 16).equals("")) {
            BuildPanel.setAcademyLabel("Academy (Level 0)");
            BuildPanel.setAcademyButtonTrueOrFalse(false);
          }
          break;
        } else {
          BuildPanel.setAcademyLabel("Academy (Level 0)");
        }
      } catch (NoSuchElementException e) {
        BuildPanel.setUpgradeAcademyLabel("Cannot upgrade");
        BuildPanel.setAcademyButtonTrueOrFalse(false);
        BuildPanel.setAcademyLabel("Academy max level");
      }
    }
  }
예제 #3
0
파일: Village.java 프로젝트: ttkyle/TWFB
  // Sends the level of warehouse to the GUI
  public static void setWarehouse() {

    for (int i = 2; i < 20; i++) {
      try {
        String wareHouseLabel =
            WebAutomation.driver
                .findElement(By.xpath("//*[@id=\"buildings\"]/tbody/tr[" + i + "]/td[1]"))
                .getText();
        if (substring(wareHouseLabel, 0, 9).equals("Warehouse")) {
          BuildPanel.setWareHouseLabel("Warehouse " + substring(wareHouseLabel, 10, 20));
          if (substring(wareHouseLabel, 10, 20).equals("")) {
            BuildPanel.setWareHouseLabel("Warehouse (Level 0)");
            BuildPanel.setWareHouseButtonTrueOrFalse(false);
          }
          break;
        } else {
          BuildPanel.setWareHouseLabel("Warehouse (Level 0)");
        }
      } catch (NoSuchElementException e) {
        BuildPanel.setUpgradeWareHouseLabel("Cannot upgrade");
        BuildPanel.setWareHouseButtonTrueOrFalse(false);
        BuildPanel.setWareHouseLabel("Warehouse max level");
      }
    }
  }
예제 #4
0
파일: Village.java 프로젝트: ttkyle/TWFB
  // Sends the level of barracks to the GUI
  public static void setBarracks() {

    for (int i = 2; i < 20; i++) {
      try {
        String barracksLabel =
            WebAutomation.driver
                .findElement(By.xpath("//*[@id=\"buildings\"]/tbody/tr[" + i + "]/td[1]"))
                .getText();
        if (substring(barracksLabel, 0, 8).equals("Barracks")) {
          BuildPanel.setBarracksLabel("Barracks " + substring(barracksLabel, 9, 20));
          if (substring(barracksLabel, 9, 20).equals("")) {
            BuildPanel.setBarracksLabel("Barracks (Level 0)");
            BuildPanel.setBarracksButtonTrueOrFalse(false);
          }
          break;
        } else {
          BuildPanel.setBarracksLabel("Barracks (Level 0)");
        }
      } catch (NoSuchElementException e) {
        BuildPanel.setUpgradeBarracksLabel("Cannot upgrade");
        BuildPanel.setBarracksButtonTrueOrFalse(false);
        BuildPanel.setBarracksLabel("Barracks max level");
      }
    }
  }
예제 #5
0
파일: Village.java 프로젝트: ttkyle/TWFB
  // Sends the level of villageHQ to the GUI
  public static void setVillageHQ() {

    // loop through the building rows
    for (int i = 2; i < 20; i++) {
      try {
        String villageHQLabel =
            WebAutomation.driver
                .findElement(By.xpath("//*[@id=\"buildings\"]/tbody/tr[" + i + "]/td[1]"))
                .getText();

        // if the building was found then set the name and level
        if (substring(villageHQLabel, 0, 7).equals("Village")) {
          BuildPanel.setVillageHQLabel("Village HQ " + substring(villageHQLabel, 21, 31));

          // if the building level is not present then make it level 0
          if (substring(villageHQLabel, 21, 31).equals("")) {
            BuildPanel.setVillageHQLabel("Village HQ (Level 0)");
            BuildPanel.setVillageHQButtonTrueOrFalse(false);
          }
          break;
        }
        // if the building is not found at all make it level 0
        else {
          BuildPanel.setVillageHQLabel("Village HQ (Level 0)");
        }
      }
      // if the element does not exist on the webpage then it's max level
      catch (NoSuchElementException e) {
        BuildPanel.setUpgradeVillageHQLabel("Cannot upgrade");
        BuildPanel.setVillageHQButtonTrueOrFalse(false);
        BuildPanel.setVillageHQLabel("Village max level");
      }
    }
  }
예제 #6
0
파일: Village.java 프로젝트: ttkyle/TWFB
  // Sends the level of clay generation to the GUI
  public static void setClayResource() {

    try {
      String clay;
      clay = WebAutomation.driver.findElement(By.xpath("//*[@id=\"stone\"]")).getText();
      BuildPanel.setVillageClayAmountLabel(clay);
    } catch (NoSuchElementException e) {
    } catch (StaleElementReferenceException e) {
    }
  }
예제 #7
0
파일: Village.java 프로젝트: ttkyle/TWFB
  // Sends the level of wood generation to the GUI
  public static void setWoodResource() {

    try {
      String wood;
      wood = WebAutomation.driver.findElement(By.xpath("//*[@id=\"wood\"]")).getText();
      BuildPanel.setVillageWoodAmountLabel(wood);
    } catch (NoSuchElementException e) {
    } catch (StaleElementReferenceException e) {
    }
  }
예제 #8
0
파일: Village.java 프로젝트: ttkyle/TWFB
  //// Sends the level of iron generation to the GUI
  public static void setIronResource() {

    try {
      String iron;
      iron = WebAutomation.driver.findElement(By.xpath("//*[@id=\"iron\"]")).getText();
      BuildPanel.setVillageIronAmountLabel(iron);
    } catch (NoSuchElementException e) {
    } catch (StaleElementReferenceException e) {
    }
  }
예제 #9
0
파일: Village.java 프로젝트: ttkyle/TWFB
  // Tells the user if they are being attacked
  public static void isAttacked() {

    try {

      String incoming;
      incoming =
          WebAutomation.driver
              .findElement(By.xpath("//*[@id=\"show_incoming_units\"]/h4"))
              .getText();

      if (substring(incoming, 0, 8).equals("Incoming")) {
        BuildPanel.setVillageIncomingLabel(
            WebAutomation.driver
                    .findElement(
                        By.xpath(
                            "//*[@id=\"header_info\"]/tbody/tr/td[7]/table/tbody/tr[1]/td/table/tbody/tr/td[2]"))
                    .getText()
                + " Attacks incoming");
      }
    } catch (NoSuchElementException e) {
    }
  }