Package flyingdiamond.model

Examples of flyingdiamond.model.ArticleMatrix


      //Ours UI update are ordered!For example:When matrix loading,we have to
      //waiting for one grew and the up updated,then grow a new line and update
      //again.
      SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
          ArticleMatrix matrix = (ArticleMatrix) o;
          ModelUpdateCaseEnum updateCase =(ModelUpdateCaseEnum) arg;
          if (updateCase == ModelUpdateCaseEnum.ACTIVATED) {
            shine(matrix);
          } else if (updateCase == ModelUpdateCaseEnum.UNACTIVATED) {
            stopShine();
View Full Code Here


    Article blueDia = ArticleFactory.getInstance().createArticle(ArticleEnum.BLUE_DIAMOND);
    Article greenDia = ArticleFactory.getInstance().createArticle(ArticleEnum.GREEN_DIAMOND);
    //Set pattern to different positions,check whether the react method work well.
    for (int i = 0; i < ArticleMatrix.HEIGHT; i++) {
      for (int j = 0; j < ArticleMatrix.WIDTH; j++) {
        ArticleMatrix matrix = generateTestMatrix(i,j);
        int nullCells = reaction.react(i, j, matrix);
        int redDiamonds = 0;
        for (int row = 0; row < ArticleMatrix.HEIGHT; row++) {
          for (int col = 0; col < ArticleMatrix.WIDTH; col++) {
            Article art = matrix.getArticle(row, col);
            if (art.equals(greenDia) && !art.isActivated()) {
              redDiamonds++;
            }
          }
        }       
View Full Code Here

   * with each cell of matrix as the center cell(trim those out of boundary articles),
   * and fill rest cells with the other type articles.After activateArticle method
   * invoked,asserts all circle are activated and all the other cells are not.
   */
  private ArticleMatrix generateTestMatrix(int row,int col){
    ArticleMatrix matrix = new ArticleMatrix();
    int height = matrix.getHeight();
    int width = matrix.getWidth();
    //Fills target diamonds.
    fillACross(row, col, matrix) ;
    fillACross(row-3, col, matrix) ;
    fillACross(row+3, col, matrix) ;
    fillACross(row, col-3, matrix) ;
    fillACross(row, col+3, matrix) ;
   
    //Fills non-target diamonds.
    for(int i=0;i<height;i++){
      for(int j=0;j<width;j++){
        if(matrix.getArticle(i, j)==null){
          matrix.setArticle(i, j, ArticleFactory.getInstance().createArticle(ArticleEnum.GREEN_DIAMOND));
        }
      }
    }
    return matrix;
  }
View Full Code Here

   * Test method for {@link flyingdiamond.model.chainreaction.BlastChainReaction#react(int, int, flyingdiamond.model.ArticleMatrix)}.
   */
  @Test
  public void testReact() {
    //Generates a matrix which is full of diamonds and a bomb in the center.
    ArticleMatrix matrix = generateTestMatrix(ArticleMatrix.HEIGHT/2,ArticleMatrix.WIDTH/2);
    //Actives bomb
    int blastCount = blastChainReaction.react(ArticleMatrix.HEIGHT/2,ArticleMatrix.WIDTH/2, matrix);
    //Counts activated articles.
    int activatedCount = 0;
    for(int i=0;i<ArticleMatrix.HEIGHT;i++){
      for(int j=0;j<ArticleMatrix.WIDTH;j++){
        if(matrix.getArticle(i, j).isActivated()){
          activatedCount++;
        }
      }
    }
    assertEquals(activatedCount,25);
View Full Code Here

    assertEquals(activatedCount,25);
    assertEquals(blastCount,25);
  }
 
  private ArticleMatrix generateTestMatrix(int row,int col){
    ArticleMatrix matrix = new ArticleMatrix();
    //Fill matrix full with articles.
    //Fills non-target diamonds.
    for(int i=0;i<ArticleMatrix.HEIGHT;i++){
      for(int j=0;j<ArticleMatrix.WIDTH;j++){
        matrix.setArticle(i, j, ArticleFactory.getInstance().createDiamondRandomly());
      }
    }
    //Sets a bomb at given position.
    matrix.setArticle(row, col, ArticleFactory.getInstance().createArticle(ArticleEnum.BOMB));
    return matrix;
  }
View Full Code Here

TOP

Related Classes of flyingdiamond.model.ArticleMatrix

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.