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)*"); } }
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); } } }
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()); } }
public void reinitialiserTroll() { String idObjet; try { ResultSet rset = stmt.executeQuery("select idObjet from equipement where idTroll=" + idTroll); while (rset.next()) { idObjet = rset.getString("idObjet"); this.desequiperObjet(idObjet); // int res = stmt.executeUpdate("delete from equipement where idObjet=idObjet"); } } catch (SQLException E) { System.err.println("SQLException: " + E.getMessage()); System.err.println("SQLState: " + E.getSQLState()); } Enumeration enumPopo = tabPopoEnCours.elements(); while (enumPopo.hasMoreElements()) { objet popo = (objet) enumPopo.nextElement(); popo.supprimerTourPopo(); this.verifTourPopo(); } }
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()); } }