Exemple #1
0
 private boolean doAttack(JSONObject action) {
   Champion c1 = board.getChampionById((String) action.get("actor1"));
   Champion c2 = board.getChampionById((String) action.get("actor2"));
   if (c1 != null) {
     if (c1.doAttack((String) action.get("attack"))) {
       Attack a = c1.getAttackById((String) action.get("attack"));
       if (a == null) {
         errorString = "Attack Doesn't exist!";
         return false;
       }
       int damage = a.getDamage();
       if (c2 != null && c2.takeDamage(damage)) {
         return true;
       } else {
         errorString = "Champion 2 Not Found!";
         return false;
       }
     } else {
       errorString = "Not a valid move";
       return false;
     }
   } else {
     errorString = "Champion Not Found!";
     return false;
   }
 }
Exemple #2
0
 // ------------------------- ACTIONS -------------------------
 private boolean doMove(JSONObject action) {
   Champion c = board.getChampionById((String) action.get("actor1"));
   if (c != null) {
     if (c.move(Integer.parseInt((String) action.get("position")))) {
       return true;
     } else {
       errorString = "Not a valid move";
       return false;
     }
   } else {
     errorString = "Champion Not Found!";
     return false;
   }
 }
  @PostConstruct
  public void init() {
    itemSetData = new ArrayList<ItemSetDisplay>();
    curr = null;

    try {
      champId =
          FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id");
      if (FacesContext.getCurrentInstance()
              .getExternalContext()
              .getRequestParameterMap()
              .get("mode")
          != null) {
        gameMode =
            FacesContext.getCurrentInstance()
                .getExternalContext()
                .getRequestParameterMap()
                .get("mode");
      } else {
        gameMode = "custom";
      }

      // create our mysql database connection
      Class.forName(GlobalConfig.DB_DRIVER);
      Connection conn =
          DriverManager.getConnection(
              GlobalConfig.DB_URL, GlobalConfig.DB_USERNAME, GlobalConfig.DB_PASSWORD);

      String query = "SELECT * FROM champions WHERE ID=?";
      PreparedStatement st = conn.prepareStatement(query);
      st.setString(1, champId);
      ResultSet rs = st.executeQuery();

      // iterate through the java resultset

      while (rs.next()) {
        curr = new Champion();
        curr.setId(rs.getInt("ID"));
        curr.setName(rs.getString("NAME"));
        curr.setTitle(rs.getString("TITLE"));
        String image =
            "http://ddragon.leagueoflegends.com/cdn/5.16.1/img/champion/"
                + rs.getString("KEYID")
                + ".png";
        curr.setImage(image);
        String splash =
            "http://ddragon.leagueoflegends.com/cdn/img/champion/splash/"
                + rs.getString("KEYID")
                + "_0.jpg";
        curr.setSplash(splash);
        String loading =
            "http://ddragon.leagueoflegends.com/cdn/img/champion/loading/"
                + rs.getString("KEYID")
                + "_0.jpg";
        curr.setLoading(loading);
      }

      rs.close();
      st.close();
      conn.close();

    } catch (Exception e) {
      System.err.println("Got an exception! ");
      System.err.println(e.getMessage());
    }
  }