Пример #1
0
  public void utiliserPopo(objet potion) {
    int val = 0;
    int ancVal = 0;
    String carac = null;
    try {
      stmt.executeUpdate(
          "update equipement SET estEquipe = true where idObjet ='"
              + potion.idObjet()
              + "' and idTroll="
              + idTroll);
      ResultSet rset =
          stmt.executeQuery(
              "select caracteristique from carac where idObjet='" + potion.idObjet() + "'");
      while (rset.next()) {
        carac = rset.getString("caracteristique");
      }

      rset =
          conn.createStatement()
              .executeQuery("select valeur from carac where idObjet='" + potion.idObjet() + "'");
      while (rset.next()) {
        val = rset.getInt("valeur");
      }

      rset = stmt.executeQuery("select " + carac + " from troll where idTroll=" + idTroll);
      while (rset.next()) {
        ancVal = rset.getInt(carac);
      }
      stmt.executeUpdate(
          "update troll SET " + carac + " = " + (ancVal + val) + "where idTroll=" + idTroll);
      rset = stmt.executeQuery("select paRestants from troll where idTroll=" + idTroll);
      while (rset.next()) {
        ancVal = rset.getInt("paRestants");
      }
      stmt.executeUpdate(
          "update troll SET paRestants = " + (ancVal - 1) + " where idTroll=" + idTroll);
      tabPopoEnCours.put(potion.idObjet(), potion);
      paRestants = paRestants - 1;
    } catch (SQLException E) {
      System.err.println("SQLException: " + E.getMessage());
      System.err.println("SQLState:     " + E.getSQLState());
    }
  }
Пример #2
0
 public void afficherPopo() {
   Enumeration enumPopo = tabPopoEnCours.elements();
   if (!enumPopo.hasMoreElements()) {
     System.out.println("      *    - Aucune                        *");
   }
   while (enumPopo.hasMoreElements()) {
     objet popo = (objet) enumPopo.nextElement();
     System.out.println(
         "      *    - " + popo.idObjet() + " : " + popo.duree() + " tour(s) restant(s)*");
   }
 }
Пример #3
0
 public void verifTourPopo() {
   Enumeration enumPopo = tabPopoEnCours.elements();
   while (enumPopo.hasMoreElements()) {
     objet popo = (objet) enumPopo.nextElement();
     popo.decrementerTourPopo();
     System.out.println(popo.duree() + " tour(s) restants pour la potion " + popo.idObjet());
     if (popo.duree() == 0) {
       this.supprimerPopo(popo);
     }
   }
 }
Пример #4
0
  public void supprimerPopo(objet popo) {

    String idPopo = popo.idObjet();
    int val = 0;
    int ancVal = 0;
    String carac = null;
    try {
      ResultSet rset =
          stmt.executeQuery("select caracteristique from carac where idObjet='" + idPopo + "'");
      while (rset.next()) {
        carac = rset.getString("caracteristique");
      }

      rset =
          conn.createStatement()
              .executeQuery("select valeur from carac where idObjet='" + idPopo + "'");
      while (rset.next()) {
        val = rset.getInt("valeur");
      }

      rset = stmt.executeQuery("select " + carac + " from troll where idTroll=" + idTroll);
      while (rset.next()) {
        ancVal = rset.getInt(carac);
      }
      stmt.executeUpdate(
          "update troll SET " + carac + " = " + (ancVal - val) + " where idTroll=" + idTroll);
      stmt.executeUpdate("delete from equipement where idObjet='" + idPopo + "'");
      stmt.executeUpdate("delete from carac where idObjet='" + idPopo + "'");
      stmt.executeUpdate("delete from objet where idObjet='" + idPopo + "'");
      tabPopoEnCours.remove(idPopo);
      // menu.supprimerPopo(idPopo);
    } catch (SQLException E) {
      System.err.println("SQLException: " + E.getMessage());
      System.err.println("SQLState:     " + E.getSQLState());
    }
  }