/**
   * Puts the specified Object into the cell at the specified coordinates. The contents of the cell
   * are ordered such that the first object inserted will be the first out and the last in the last
   * out.
   *
   * @param x the x coordinate
   * @param y the y coordinate
   * @param object the object to put
   */
  public void putObjectAt(int x, int y, Object object) {
    Cell c = (Cell) matrix.get(x, y);

    if (c == null) {
      c = new OrderedCell();
      matrix.put(x, y, c);
    }
    c.add(object);
  }
Exemplo n.º 2
0
 public void add(String value, int pos) throws Exception {
   Cell tempCell = cells.get(pos);
   tempCell.add(value);
   cells.set(pos, tempCell);
   // and eliminate that value from possibilities of relevant cells
   for (int i = 0; i < 81; i++) {
     if (areRelevant(i, pos)) {
       tempCell = cells.get(i);
       int beforeLength = tempCell.getPossibilities().length();
       tempCell.eliminate(value);
       if (beforeLength > 1 && tempCell.getPossibilities().length() == 1) {
         add(tempCell.getPossibilities(), i);
       }
       cells.set(i, tempCell);
     }
   }
 }
Exemplo n.º 3
0
  /**
   * Move the herbivore one cell (eating a plant if possible)
   *
   * @param w the world where this herbivore is present
   * @param cArray the group of cells where this herbivore belongs
   * @param a contains the herbivore
   * @param herb herbivore that will be moved.
   */
  public void move(World w, Cell cArray[][], Cell a, Herbivore herb) {

    temp = herb;
    temp.life--; // descrease hp as soon as it moves, reset if had eat
    temp.hasMoved = true;

    // holds the adjacents cells.
    ArrayList<Cell> adCells = a.getAdjacentCells(w, cArray, a);

    // holds the cell where the herbivore will be moved
    Cell holder = adjPlants(adCells);
    adCells.clear();

    holder.removeAll();

    // when an herbivore was not able to find a plant
    if (temp.life == 0) {
      a.remove(temp);
      return;
    }

    // add herbivore to the cell
    holder.add(herb);
  }
Exemplo n.º 4
0
  protected void makeMove() {
    MoveOptions options = Actor.world.getMoveOptions(cell);
    boolean moved = false;

    while (!moved) {

      Move move = move(options);

      if (move == null) return;
      Cell lock1, lock2;

      Move.Direction direction = move.getMove();
      Cell center = options.getOption(Move.Direction.CENTER),
          newCell = options.getOption(direction);

      switch (direction) {
        case DOWN:
          lock1 = center;
          lock2 = newCell;

          break;
        case CENTER:
          lock1 = center;
          lock2 = center;
          newCell = center;
        default:
          lock1 = newCell;
          lock2 = center;
      }

      synchronized (lock1) {
        synchronized (lock2) {
          if (alive) {
            // if the new location already has an object of the same class as us find another set of
            // moves.
            if (newCell != center && newCell.hasClass(this.getClass())) {
              continue;
            }
            moved = true;

            // kill to actor on the cell you are moving to
            // this can be "this", as in a flower has reached the end of its life
            Class<?> toKill = move.getClassToConsume();
            if (toKill != null) newCell.kill(toKill);

            if (newCell != center) {
              center.remove(this.getClass());
              newCell.add(this);
            }
            cell = newCell;
            if (this instanceof HasLife) {
              Class<?> kill = ((HasLife) this).getClassToKill(cell);
              if (kill != null) {
                cell.kill(kill);
              }
            }

            Actor toCreate = move.getActorToCreate();

            if (toCreate != null) {
              center.add(toCreate);
              world.startActor(toCreate);
            }

            world.redrawCell(newCell);
            world.redrawCell(center);

          } else {
            moved = true;
          }
        }
      }
    }
  }
Exemplo n.º 5
0
  /**
   * Put the herbivore on the given cell.
   *
   * @param c the cell which this herbivore will be put.
   */
  public void setCell(Cell c) {

    c.add(this);
  }
Exemplo n.º 6
0
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    WebApplicationContext ctx =
        WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());

    CourseManager manager = (CourseManager) ctx.getBean("courseManager");
    HttpSession session = request.getSession(false);

    List selectFilterCouList = (List) session.getAttribute("selectFilterCouList");

    Date date = new Date();
    DateFormat dateFormat = new SimpleDateFormat("yyyy年 MM月 dd日 HH:mm");

    String stuTmp[] = new String[selectFilterCouList.size()];
    List students = new ArrayList();

    for (int i = 0; i < selectFilterCouList.size(); i++) {
      stuTmp[i] = ((Map) selectFilterCouList.get(i)).get("dtimeOid").toString();
    }
    students = manager.getSeldStuFilterBy(stuTmp, true);

    Document document = new Document(PageSize.A4, 72, 72, 35, 35);
    ByteArrayOutputStream ba = new ByteArrayOutputStream();

    String year = manager.getNowBy("School_year");
    String term = manager.getNowBy("School_term");

    // 如果是下學期, 學年要+1
    if (Integer.parseInt(term) == 2) {
      Integer tmpYear = (Integer.parseInt(year) + 1);
      year = tmpYear.toString();
      term = "1";
    } else {
      term = "2";
    }

    try {

      PdfWriter writer = PdfWriter.getInstance(document, ba);
      // TODO 路徑

      // Image
      // image=Image.getInstance("http://cap.chit.edu.tw/CIS/pages/images/2002chitWatermark.gif");
      // Watermark wamark=new Watermark(image, ((PageSize.A4).width()-image.plainHeight())/2,
      // ((PageSize.A4).height()-image.plainHeight())/2);
      // document.add(wamark);

      Phrase now = doEncode("課程管理系統 " + dateFormat.format(date));
      HeaderFooter header = new HeaderFooter(now, false);
      document.setHeader(header);
      document.setFooter(header);

      // Image logo=Image.getInstance("http://192.192.231.32:8080/CIS/pages/images/art.gif");
      document.open();

      for (int i = 0; i < students.size(); i++) {

        String buf[] = {((Map) students.get(i)).get("student_no").toString()};
        List tmp = manager.getSeldStuFilterBy(buf, false);

        if (i % 2 != 0) {
          document.add(new Paragraph(doEncode("\n")));
          document.add(new Paragraph(doEncode("\n")));
          document.add(new Paragraph(doEncode("\n")));
        }

        document.add(new Paragraph(""));

        Table table = new Table(6);
        table.setWidth(100);

        table.setBorderWidth(0);
        table.setPadding(5);
        // table.setSpacing(5);
        // table.setDefaultHorizontalAlignment(table.ALIGN_CENTER);
        // table.setDefaultHorizontalAlignment(table.ALIGN_MIDDLE);

        // table.setDefaultCellBorderColor(new Color(255, 255, 255));

        Cell cell = new Cell();
        cell.add(doEncode(year));
        cell.add(doEncode("學年 第"));
        cell.add(doEncode(term));
        cell.add(doEncode("學期 網路預選失敗通知單"));
        // cell.addElement(logo);
        cell.setColspan(6);
        cell.setHorizontalAlignment(cell.ALIGN_CENTER);
        cell.setBorderColor(new Color(255, 255, 255));
        table.addCell(cell);

        // ((Map)students.get(i)).get("ClassName2");

        cell = new Cell();
        // cell.add(doEncode("學生班級: "));
        cell.add(doEncode(((Map) students.get(i)).get("ClassName").toString()));
        cell.add(doEncode("\t學號: "));
        cell.add(doEncode(((Map) students.get(i)).get("student_no").toString()));
        cell.add(doEncode("\t姓名: "));
        cell.add(doEncode(((Map) students.get(i)).get("student_name").toString()));

        cell.setColspan(6);
        cell.setHorizontalAlignment(cell.ALIGN_LEFT);
        cell.setBorderColor(new Color(255, 255, 255));
        table.addCell(cell);

        cell = new Cell();
        cell.add(doEncode("您在第一階段網路選課所選的下列課程並未成功,請按照規定時間進行網路第二階段選課,以免影響您的權益。"));

        cell.setColspan(6);
        cell.setHorizontalAlignment(cell.ALIGN_LEFT);
        cell.setBorderColor(new Color(255, 255, 255));
        table.addCell(cell);

        document.add(table);

        float[] widths = {0.2f, 0.3f, 0.1f, 0.1f, 0.1f, 0.2f};
        PdfPTable tables = new PdfPTable(widths);
        tables.setWidthPercentage(100);

        PdfPCell cells = new PdfPCell(doEncode("開課班級"));
        tables.addCell(cells);

        cells = new PdfPCell(doEncode("科目名稱"));
        tables.addCell(cells);
        cells = new PdfPCell(doEncode("選別"));
        tables.addCell(cells);
        cells = new PdfPCell(doEncode("學分"));
        tables.addCell(cells);
        cells = new PdfPCell(doEncode("時數"));
        tables.addCell(cells);
        cells = new PdfPCell(doEncode("上課時間"));
        tables.addCell(cells);

        for (int j = 0; j < tmp.size(); j++) {
          cells = new PdfPCell();
          cells = new PdfPCell(doEncode(((Map) tmp.get(j)).get("ClassName2").toString()));
          tables.addCell(cells);
          cells = new PdfPCell(doEncode(((Map) tmp.get(j)).get("chi_name").toString()));
          tables.addCell(cells);
          cells = new PdfPCell(doEncode(getOpt(((Map) tmp.get(j)).get("opt").toString())));
          tables.addCell(cells);
          cells = new PdfPCell(doEncode(((Map) tmp.get(j)).get("credit").toString()));
          tables.addCell(cells);
          cells = new PdfPCell(doEncode(((Map) tmp.get(j)).get("thour").toString()));
          tables.addCell(cells);

          List dcTmp =
              manager.getDtimeClassListForOpenCourse(((Map) tmp.get(j)).get("dtimeOid").toString());

          StringBuffer strBuf = new StringBuffer();
          DtimeClass dtimeClass;
          for (int x = 0; x < dcTmp.size(); x++) {
            dtimeClass = (DtimeClass) dcTmp.get(x);
            strBuf.append("週" + dtimeClass.getWeek() + ":");
            strBuf.append(dtimeClass.getBegin() + "~" + dtimeClass.getEnd() + " ");
          }

          cells = new PdfPCell(doEncode(strBuf.toString()));
          tables.addCell(cells);
        }

        for (int k = 13; k > tmp.size(); k--) {
          cells = new PdfPCell(doEncode("\t"));
          tables.addCell(cells);
          cells = new PdfPCell(doEncode("\t"));
          tables.addCell(cells);
          cells = new PdfPCell(doEncode("\t"));
          tables.addCell(cells);
          cells = new PdfPCell(doEncode("\t"));
          tables.addCell(cells);
          cells = new PdfPCell(doEncode("\t"));
          tables.addCell(cells);
          cells = new PdfPCell(doEncode("\t"));
          tables.addCell(cells);
        }

        document.add(tables);

        if (i % 2 == 1) {
          document.newPage();
        }
      }

    } catch (DocumentException de) {
      de.printStackTrace();
      System.err.println("A Document error:" + de.getMessage());
    }

    document.close();
    response.setContentType("application/pdf");
    response.setContentLength(ba.size());
    ServletOutputStream out = response.getOutputStream();
    ba.writeTo(out);
    ba.close();
    out.flush();
    out.close();
  }