Example #1
0
 public void ramasserObjet() {
   boolean vide = true;
   try {
     ResultSet rset =
         stmt.executeQuery(
             "select idObjet from objet where positionX="
                 + positionX
                 + " and positionY="
                 + positionY);
     Hashtable<String, String> tabObj = new Hashtable<String, String>();
     while (rset.next()) {
       vide = false;
       String idObj = rset.getString("idObjet");
       System.out.println(idObj);
       tabObj.put(idObj, idObj);
     }
     rset.close();
     if (!vide) {
       System.out.println("Quel objet voulez vous ramasser ? : ");
       String obj = IO.lireChaine();
       if (tabObj.containsKey(obj)) {
         proc = conn.prepareCall("{call rammasser(?,?)}");
         proc.setInt(1, idTroll);
         proc.setString(2, obj);
         proc.executeUpdate();
         proc.close();
         rset = stmt.executeQuery("select typeObjet from objet where idObjet='" + obj + "'");
         rset.first();
         String type = rset.getString("typeObjet");
         if (type.equals("potion")) {
           menu.supprimerPopo(obj);
         } else {
           menu.supprimerObjet(obj);
         }
         rset = stmt.executeQuery("select paRestants from troll where idTroll=" + idTroll);
         int ancVal = 0;
         while (rset.next()) {
           ancVal = rset.getInt("paRestants");
         }
         stmt.executeUpdate(
             "update troll SET paRestants = " + (ancVal - 1) + " where idTroll=" + idTroll);
         paRestants = paRestants - 1;
       } else {
         System.out.println("Cet objet ne se trouve pas sur votre case !");
       }
     } else {
       System.out.println("Il n'y a aucun objet sur votre case");
     }
   } catch (SQLException E) {
     System.err.println("SQLException: " + E.getMessage());
     System.err.println("SQLState:     " + E.getSQLState());
   }
 }
  public SingleNameReport(WritableWorkbook workbook, Statement new_statement, String[] arguments) {

    String main_tsn = "";
    String main_rank = "";
    String main_kingdom = "";
    row = 0;
    try {
      statement = new_statement;
      func = new AdditionalFunctions(statement);
      copy = workbook;
      kingdom = arguments[0];
      hrank = arguments[1];
      lrank = arguments[2];
      scientificName = arguments[3];
      date_from = arguments[4];
      date_to = arguments[5];
      user = arguments[6];

      String temp = "";
      temp =
          "SELECT tsn,rank_id,kingdom_id from Tree where scientificName='" + scientificName + "'";
      System.out.println(temp);
      result = statement.executeQuery(temp);
      metadata = result.getMetaData();
      int numberOfRows = 0;
      int hrankVal = Integer.parseInt(hrank);
      int main_rankVal = 0;
      if (result.last()) numberOfRows = result.getRow();
      result.first();
      if (numberOfRows > 0 && metadata.getColumnCount() > 0) {
        main_tsn = result.getString(1);
        main_rank = result.getString(2);
        main_rankVal = Integer.parseInt(main_rank);
        main_kingdom = result.getString(3);
      }
      if (HasChildren(main_tsn) == true) FindChildInformation(main_tsn, arguments, func);

      FileInFrontPage frontPage = new FileInFrontPage(copy, statement, arguments);
      copy.write();
      copy.close();
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
  } // end of constructor
  // public method that checks for existance of children
  public boolean HasChildren(String tsn) {

    String temp = "SELECT tsn from Tree where parent_tsn='" + tsn + "'";
    if (lrank.compareTo("0") != 0 && lrank.compareTo("7") != 0)
      temp = temp + " AND rank_id<=" + lrank;
    System.out.println(temp);
    int numberOfRows = 0;
    boolean flag = false;
    try {
      result = statement.executeQuery(temp);
      metadata = result.getMetaData();
      if (result.last()) numberOfRows = result.getRow();
      result.first();
      if (numberOfRows > 0 && metadata.getColumnCount() > 0) flag = true;
    } catch (SQLException sql) {
      sql.printStackTrace();
      System.exit(1);
    }
    return flag;
  } // end of method HasChildren
  // public method to extract and write the Publication information
  public static void WritePublication(String publicationId, int rowNum) {

    WritableSheet sheet2 = copy.getSheet(1);

    try {
      String query =
          "SELECT address,author,publicationTitle,chapter,edition,editor,month,day,note,number,publisher,"
              + "series,title,volume,year,isbn,issn,pages FROM Publication WHERE id="
              + publicationId;
      System.out.println(query);

      ResultSet result_query = statement.executeQuery(query);
      ResultSetMetaData metadata_query = result_query.getMetaData();
      int numberOfRows = 0;
      if (result_query.last()) numberOfRows = result_query.getRow();
      result_query.first();
      if (numberOfRows > 0 && metadata_query.getColumnCount() > 0) {
        String aut_edi = result_query.getString(2);
        System.out.println("autor is " + aut_edi);
        if (result_query.getString(6).compareTo("") != 0)
          aut_edi = aut_edi + " / " + result_query.getString(6) + ",eds.";
        Label label = new Label(7, rowNum, aut_edi);
        sheet2.addCell(label);
        label = new Label(8, rowNum, result_query.getString(13));
        sheet2.addCell(label);
        String publication_name = result_query.getString(3);
        if (result_query.getString(12).compareTo("") != 0)
          publication_name = publication_name + ", ser. " + result_query.getString(12);
        if (result_query.getString(14).compareTo("0") != 0)
          publication_name = publication_name + ", vol. " + result_query.getString(14);
        if (result_query.getString(10).compareTo("0") != 0)
          publication_name = publication_name + ",no. " + result_query.getString(10);
        label = new Label(9, rowNum, publication_name);
        sheet2.addCell(label);
        label = new Label(12, rowNum, result_query.getString(11));
        sheet2.addCell(label);
        label = new Label(13, rowNum, result_query.getString(1));
        sheet2.addCell(label);
        label = new Label(15, rowNum, result_query.getString(9));
        sheet2.addCell(label);
        label = new Label(16, rowNum, result_query.getString(16));
        sheet2.addCell(label);
        label = new Label(17, rowNum, result_query.getString(17));
        sheet2.addCell(label);
        label = new Label(14, rowNum, result_query.getString(18));
        sheet2.addCell(label);

        String date = result_query.getString(15);
        String month = "Jan";
        System.out.println("month is " + result_query.getString(7));
        if (result_query.getString(7).compareTo("") != 0) month = result_query.getString(7);
        month = func.ConvertMonth(month);
        date = month + "/" + date;
        String day = "01";
        if (result_query.getString(8).compareTo("0") != 0) day = result_query.getString(8);
        if (day.length() == 1) day = "0" + day;
        date = day + "/" + date;
        label = new Label(10, rowNum, date);
        sheet2.addCell(label);
        label = new Label(11, rowNum, date);
        sheet2.addCell(label);
      }
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
  } // end of WritePublication
  // public method to find child information
  public void FindChildInformation(String tsn, String[] arguments, AdditionalFunctions func) {

    WritableSheet sheet2 = copy.getSheet(1);
    Label label = null;
    String children[] = null;
    String temp = "", current_tsn = "", dateCreated = "";
    int dateCheck = 1;
    temp = "SELECT distinct tsn from Tree where parent_tsn='" + tsn + "'";
    try {
      result = statement.executeQuery(temp);
      metadata = result.getMetaData();
      int numberOfRows = 0;
      if (result.last()) numberOfRows = result.getRow();
      if (numberOfRows > 0 && metadata.getColumnCount() > 0) {
        result.first();
        children = new String[numberOfRows];
        for (int j = 0; j < numberOfRows; j++) {
          children[j] = result.getString(1);
          result.next();
        }
      }
      for (int j = 0; j < numberOfRows; j++) {
        int current_tsnId = Integer.parseInt(children[j]);
        if (current_tsnId >= 999000000) {
          temp =
              "SELECT distinct Tree.tsn,unit_name1,unit_name2,unit_name3,unit_name4,scientificName,`usage`,"
                  + "taxon_author,parent_tsn,rank_name, pages, publicationId, userId, dateCreated, nameType FROM Tree,"
                  + " BaseObject, TaxonConcepts, TaxonAuthors,TaxonUnitTypes"
                  + " WHERE Tree.tsn=TaxonConcepts.tsn AND Tree.tsn='"
                  + current_tsnId
                  + "' AND "
                  + "BaseObject.id=TaxonConcepts.id AND TaxonAuthors.taxon_author_id=Tree.taxon_author_id AND "
                  + "Tree.rank_id=TaxonUnitTypes.rank_id";
          System.out.println(temp);

          result = statement.executeQuery(temp);
          metadata = result.getMetaData();
          int RowNumber = 0;
          if (result.last()) RowNumber = result.getRow();
          if (RowNumber > 0 && metadata.getColumnCount() > 0) {
            current_tsn = result.getString(1);
            dateCreated = result.getString(14);
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            Date d1 = df.parse(dateCreated);
            Date d2 = null;
            if (date_from.compareTo("all") != 0) {
              d2 = df.parse(date_from);
              if (d2.before(d1) || d2.equals(d1)) dateCheck = 1;
              else dateCheck = 0;
            }
            if (date_to.compareTo("today") != 0) {
              d2 = df.parse(date_to);
              if (d1.before(d2) || d1.equals(d2)) dateCheck = 1;
              else dateCheck = 0;
            }
            if (result.getString(7).compareTo("public") == 0
                && result.getString(15).compareTo("Regular scientific name") == 0
                && result.getString(12).compareTo("") != 0
                && dateCheck == 1) {

              String scientificName = result.getString(6);
              String taxon_author = result.getString(8);
              String publicationId = result.getString(12);
              for (int k = 0; k < 4; k++) {
                if (result.getString(k + 2).compareTo("null") != 0) {
                  label = new Label(k, row + 1, result.getString(k + 2));
                  sheet2.addCell(label);
                }
              }
              label = new Label(4, row + 1, taxon_author);
              sheet2.addCell(label);
              label = new Label(5, row + 1, result.getString(10));
              sheet2.addCell(label);

              String parent_tsn = result.getString(9);
              String userId = result.getString(13);
              WritePublication(publicationId, row + 1);
              label = new Label(18, row + 1, func.GetSubmitter(userId));
              sheet2.addCell(label);
              label = new Label(6, row + 1, func.GetParent(parent_tsn));
              sheet2.addCell(label);

              row = row + 1;
            }
          }
        }
        continue;
      }
      for (int j = 0; j < numberOfRows; j++) {
        if (HasChildren(children[j]) == true) FindChildInformation(children[j], arguments, func);
        else continue;
      }
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
  } // end of FindChildInformation
Example #6
0
  public boolean attaquer() {
    boolean reussite;
    boolean mort = false;
    int idTrollAdverse;
    int positionAdverseX = 0;
    int positionAdverseY = 0;
    if (idTroll == 1) {
      idTrollAdverse = 2;
    } else {
      idTrollAdverse = 1;
    }
    try {
      ResultSet rset =
          stmt.executeQuery(
              "select positionX, positionY from troll where idTroll=" + idTrollAdverse);
      rset.first();
      positionAdverseX = rset.getInt("positionX");
      positionAdverseY = rset.getInt("positionY");
    } catch (SQLException E) {
      System.err.println("SQLException: " + E.getMessage());
      System.err.println("SQLState:     " + E.getSQLState());
    }
    if (positionAdverseX == this.positionX && positionAdverseY == this.positionY) {
      reussite = loi_reussite();
      if (reussite) {
        int scoreAttaque = score_Des(att);
        System.out.println("Jet d'attaque : " + scoreAttaque);
        try {

          proc = conn.prepareCall("{? = call nb_des_esq(?)}");
          proc.registerOutParameter(1, Types.INTEGER);
          proc.setInt(2, idTrollAdverse);
          proc.executeUpdate();
          int esqAdverse = proc.getInt(1);
          proc.close();
          int scoreEsquiveAdversaire = score_Des(esqAdverse);
          System.out.println("Jet d'esquive de l'adversaire : " + scoreEsquiveAdversaire);
          if (scoreEsquiveAdversaire < scoreAttaque) {
            System.out.println("Esquive de l'adversaire ratée... PAF !!");
            int scoreDegats = score_Des(deg);
            System.out.print(
                "L'adversaire perd " + scoreDegats + " pts de vie, il lui en reste donc ");

            proc = conn.prepareCall("{? = call decrementer_vie(?,?)}");
            proc.registerOutParameter(1, Types.BOOLEAN);
            proc.setInt(2, idTrollAdverse);
            proc.setInt(3, scoreDegats);
            proc.executeUpdate();
            mort = proc.getBoolean(1);
            proc.close();

            ResultSet rset =
                stmt.executeQuery("select vie from troll where idTroll =" + idTrollAdverse);
            rset.first();
            System.out.println(rset.getInt("vie"));

            proc = conn.prepareCall("{call init_pa(?,?)}");
            proc.setInt(1, idTroll);
            proc.setInt(2, paRestants - 4);
            proc.executeUpdate();
            proc.close();

            paRestants = paRestants - 4;

          } else if (scoreEsquiveAdversaire == scoreAttaque) {
            System.out.println("Esquive de l'adversaire un peu tardive... PAF !!");
            int scoreDegats = score_Des(deg);
            System.out.println(
                "L'adversaire perd " + (scoreDegats / 2) + " pts de vie, il lui en reste donc ");
            proc = conn.prepareCall("{? = call decrementer_vie(?,?)}");
            proc.registerOutParameter(1, Types.BOOLEAN);
            proc.setInt(2, idTrollAdverse);
            proc.setInt(3, scoreDegats);
            proc.executeUpdate();
            mort = proc.getBoolean(1);
            proc.close();

            ResultSet rset =
                stmt.executeQuery("select vie from troll where idTroll =" + idTrollAdverse);
            rset.first();
            System.out.println(rset.getInt("vie"));

            proc = conn.prepareCall("{call init_pa(?,?)}");
            proc.setInt(1, idTroll);
            proc.setInt(2, paRestants - 4);
            proc.executeUpdate();
            proc.close();

            paRestants = paRestants - 4;
          } else {
            System.out.println(
                "Magnifique esquive de l'adversaire qui ne subira donc aucun dommage");
          }
        } catch (SQLException E) {
          System.err.println("SQLException: " + E.getMessage());
          System.err.println("SQLState:     " + E.getSQLState());
        }
      }
    } else {
      System.out.println("Le troll adverse n'est pas sur votre case !!");
    }
    return (mort);
  }
Example #7
0
  public void deplacer(int tailleEchiquier) {

    boolean coordOk = false;
    System.out.println("Position actuelle : X=" + positionX + " | Y=" + positionY);
    System.out.println("Nouvelle position :");
    while (coordOk == false) {
      if (positionX - 1 < 1) {
        System.out.print("X [1 - " + (positionX + 1) + " ] = ");
      } else if (positionX + 1 > tailleEchiquier) {
        System.out.print("X [" + (positionX - 1) + " - " + (tailleEchiquier) + " ] = ");
      } else {
        System.out.print("X [" + (positionX - 1) + " - " + (positionX + 1) + " ] = ");
      }
      int nouvPositionX = IO.lireEntier();
      if (nouvPositionX < 1) {
        System.out.println("Impossible : coordonnee X < 1 !");
      } else if (nouvPositionX > tailleEchiquier) {
        System.out.println("Impossible : coordonnee X > " + tailleEchiquier + " !");
      } else if (nouvPositionX == positionX + 1
          || nouvPositionX == positionX - 1
          || nouvPositionX == positionX) {
        coordOk = true;
        positionX = nouvPositionX;
      } else {
        System.out.println("Impossible : Le déplacement est limité à 1 case");
      }
    }
    coordOk = false;
    while (coordOk == false) {
      if (positionY - 1 < 1) {
        System.out.print("Y [1 - " + (positionY + 1) + " ] = ");
      } else if (positionY + 1 > tailleEchiquier) {
        System.out.print("Y [" + (positionY - 1) + " - " + (tailleEchiquier) + " ] = ");
      } else {
        System.out.print("Y [" + (positionY - 1) + " - " + (positionY + 1) + " ] = ");
      }
      int nouvPositionY = IO.lireEntier();
      if (nouvPositionY < 1) {
        System.out.println("Impossible : coordonnee Y < 1 !");
      } else if (nouvPositionY > tailleEchiquier) {
        System.out.println("Impossible : coordonnee Y > " + tailleEchiquier + " !");
      } else if (nouvPositionY == positionY + 1
          || nouvPositionY == positionY - 1
          || nouvPositionY == positionY) {
        coordOk = true;
        positionY = nouvPositionY;
      } else {
        System.out.println("Impossible : Le déplacement est limité à 1 case");
      }
    }
    try {
      ResultSet rset =
          stmt.executeQuery(
              "select count (*) from objet where positionX = "
                  + this.positionX
                  + " and positionY="
                  + this.positionY);
      rset.first();
      int nbObjet = rset.getInt(1);
      if (nbObjet > 0) {
        System.out.println();
        System.out.println("Vous marchez sur quelque chose...");
      }
      proc = conn.prepareCall("{? = call deplacer_troll(?,?,?)}");
      proc.registerOutParameter(1, Types.VARCHAR);
      proc.setInt(2, idTroll);
      proc.setInt(3, positionX);
      proc.setInt(4, positionY);
      proc.executeUpdate();
      String mess = proc.getString(1);
      proc.close();

      proc = conn.prepareCall("{? = call pa_restants(?)}");
      proc.registerOutParameter(1, Types.INTEGER);
      proc.setInt(2, idTroll);
      proc.executeUpdate();
      paRestants = proc.getInt(1);
      proc.close();
      if (mess != null) {
        System.out.println(mess);
      }
    } catch (SQLException E) {
      System.err.println("SQLException: " + E.getMessage());
      System.err.println("SQLState:     " + E.getSQLState());
    }
  }