Bubble Bubble

Chapter 1 Show Bubbles

1 . 1Create five fixed-position bubbles

  1.1.1 Position class

        public class Position {

    private int row;

    private int column;

   

    public Position(){

      

    }

   

    public Position(int row,int column){

       this.row=row;

       this.column=column;

    }

   

    public int getRow() {

       return row;

    }

    public void setRow(int row) {

       this.row = row;

    }

    public int getColumn() {

       return column;

    }

    public void setColumn(int column) {

       this.column = column;

    }

   

   

}

Explanation: Write the Position class to obtain and modify the coordinates of Star.

1.1.2 Star class

public class Star {

    private Position position=null;

    private StarType type=null;

    public enum StarType{

       BLUE(0),GREEN(1),YELLOW(2),RED(3),PURPLE(4);

       private int value;

       private StarType(int value){

           this.value=value;

       }

       public int value(){

           return this.value;

       }

    /*  public static StarType valueOf(int value){

           if(value<4){

              return StarType.values()[value];

           }

           else

              return null;

       }

       */

      

      

       public static StarType valueOf(int value){

           switch(value){

           case 0:

              return BLUE;

           case 1:

              return GREEN;

           case 2:

              return YELLOW;

           case 3:

              return RED;

           case 4:

              return PURPLE;

           default:

              return null;

             

           }

       }

      

    }

   

    public Position getPosition() {

       return position;

    }

    public void setPosition(Position position) {

       this.position = position;

    }

   

    public StarType getType() {

       return type;

    }

    public void setType(StarType type) {

       this.type = type;

    }

   

   

/*  public Star(){

       position=new Position();

       type=StarType.BLUE;

    }      */

    public Star(Position position, StarType type){

       this.position=position;

       this.type=type;

    }

   

}

Explanation: Write the Star class, which includes methods for setting coordinates and colors. When writing methods related to Type, an enumeration class is used. The enumeration class is a form of standardized parameters. The enumeration class is used to facilitate later call data.

1.1.3 Create five fixed-position bubbles

Position p1=new Position(1,1);

       Star star1=new Star(p1,StarType.BLUE);

    //  star1.setPosition(new Position(0,0));

    //  star1.setType(StarType.BLUE);

       stars.add(star1);

      

       Position p2=new Position(2,2);

       Star star2=new Star(p2,StarType.YELLOW);

       stars.add(star2);

      

       Position p3=new Position(3,3);

       Star star3=new Star(p3,StarType.GREEN);

       stars.add(star3);

      

       Position p4=new Position(4,4);

       Star star4=new Star(p4,StarType.RED);

       stars.add(star4);

      

       Position p5=new Position(5,5);

       Star star5=new Star(p5,StarType.PURPLE);

       stars.add(star5);

Explanation: Call the construction methods of Position and Star to construct five bubbles with fixed positions and colors, and display them on the screen.

1.2 Create random screen-full bubbles

  1.2.1 Create screen-full bubbles

        for(int i=0;i<10;i++){

           for(int j=0;j<10;j++){

              Position p=new Position(i,j);

              //Star star=new Star(p,StarType.PURPLE);

              Star star=new Star(p,StarType.valueOf(random.nextInt(5)));

              stars.add(star);                                        

             

           }

       }

      

  1.2.2 Create random bubbles that fill the screen

       Star star=new Star(p,StarType.valueOf(random.nextInt(5)));

Chapter 2 Obtain bubbles to be eliminated

2.1Clone _

    /******************* PRJ - BU2 - JAVA - 004 Task1 ********************/

   

   

    public static Star clone(Star star){

       Star s1=new Star(new Position(star.getPosition().getRow(),star.getPosition().getColumn()),star.getType());

      

       return s1;

    }

//             test

   

public static void main(String[] args){

    Star s=new Star(new Position(5,5), StarType.RED);

    Star star=clone(s);

    System. out .println( " The original bubble gum object is: " + "(" + s .getPosition().getRow()+ "," + s .getPosition().getColumn()+ "-" + s .getType( )+ ")" );

    System. out .println( " The cloned bubblegum object is: " + "(" + star .getPosition().getRow()+ "," + star .getPosition().getColumn()+ "-" + star .getType( )+ ")" );

    System. out .println( " Are the two objects consistent: " + s .equals( star ));

    System. out .println( " Whether the coordinate objects of the two objects are consistent: " + s .getPosition().equals( star .getPosition()));

   

   

   

      

    }

   

    /**************************************************************/

2.2 Find surrounding bubbles

   private void lookupByPath(Star base, StarList sList, StarList clearStars) {

       /******************* PRJ - BU2 - JAVA - 004 Task2 ********************/

      

       int x = base .getPosition().getRow();

       int y=base.getPosition().getColumn();

       StarType type=base.getType();

      

       Star star=null;

      

       if(x-1>=0){

           star=sList.lookup(x-1, y);

           if(star!=null){

              if(!(clearStars.existed(star))){

                  if(star.getType().equals(type)){

                     clearStars.add(StarsUtil.clone(star));

                     lookupByPath(star,sList,clearStars);

                  }

              }

           }

       }

      

      

        /**************************************************************/

       /******************* PRJ - BU2 - JAVA - 004 Task3 ********************/

       if(y-1>=0){

           star=sList.lookup(x, y-1);

           if(star!=null){

              if(!(clearStars.existed(star))){

                  if(star.getType().equals(type)){

                     clearStars.add(StarsUtil.clone(star));

                     lookupByPath(star,sList,clearStars);

                  }

              }

           }

       }

      

          

        /**************************************************************/

       /******************* PRJ - BU2 - JAVA - 004 Task4 ********************/

       if(x+1<=10){

           star=sList.lookup(x+1, y);

           if(star!=null){

              if(!(clearStars.existed(star))){

                  if(star.getType().equals(type)){

                     clearStars.add(StarsUtil.clone(star));

                     lookupByPath(star,sList,clearStars);

                  }

              }

           }

       }

      

        /**************************************************************/

       /******************** PRJ - BU2 - JAVA - 004 Task5 ********************/

       if(y+1<=10){

           star=sList.lookup(x, y+1);

           if(star!=null){

              if(!(clearStars.existed(star))){

                  if(star.getType().equals(type)){

                     clearStars.add(StarsUtil.clone(star));

                     lookupByPath(star,sList,clearStars);

                  }

              }

           }

       }

    /**************************************************************/

       // If the above four judgments are not entered, it means that there is no bubble gum around, so jump out of the recursive method.

    }

2.3 Package the bubble gum to be moved

  2.3.1

 public class MovedStar extends Star {

    private Position movedposition;

   

    public Position getMovedPosition() {

       return movedposition;

    }

    public void setMovedPosition(Position movedposition) {

       this.movedposition = movedposition;

    }

    public MovedStar(){

      

    }

   

    public MovedStar(Position p1, StarType s, Position mp){

       super(p1,s);

       this.movedposition=mp;

    }

   

   

   

    @Override

    public String toString() {

      

       return super.toString()+"\nnew position: ("+movedposition.getRow()+","+movedposition.getColumn()+")";

    }

    public static void main(String[] args){

/*     Position p1=new Position(0,0);

       Position p2=new Position(1,1);

       StarType type=StarType.RED;

       MoveStar m1=new MoveStar(p1,type,p2);

       System.out.println(" Bubble gum's original position: "+"("+p1.getRow()+","+p1.getColumn()+")\n"+" Bubble gum's target position: "+" ("+p2.getRow()+","+p2.getColumn()+")\n"+" The color of bubble gum is: "+type); */

      

       Position p=new Position(0,0);

       Position mp=new Position(1,1);

       MovedStar s1=new MovedStar(p, StarType.RED,mp);

       System.out.println(s1.toString());

      

    }         

   

}

2.3.2

   public Position() {}

    public Position(int row, int column) {

       setRow(row);

       setColumn(column);

    }

   

    public int getRow() {

       return row;

    }

    public void setRow(int row) {

       this.row = row;

    }

    public int getColumn() {

       return column;

    }

    public void setColumn(int column) {

       this.column = column;

    }

    @Override

    public String toString() {

       String string="position:("+this.row+","+this.column+")";

       return string;

    }

   

2.3.3

  public String toString() {

      

       return position.toString()+", type:"+this.type;

    }

2.4   Implement mobile bubble gum packaging

   public StarList getYMovedStars(StarList clearStars,

           StarList currentStarList) {

       /******************** PRJ - BU2 - EL - 005 Task2 ********************/

       StarList stars=new StarList();

       int y = 0;

       for (int i=6; i>=0; i--){

           MovedStar ms=new MovedStar(currentStarList.lookup(i,0).getPosition(),currentStarList.lookup(i,y).getType(),new Position(i+2,0));

           stars.add(ms);

       }

      

      

      

       return stars;

        /**************************************************************/

    }

Chapter 3 Interface Decoupling

3.1 Write interface classes, write interface methods, and main function output detection

    public class StarServiceTester implements StarService {

    public static void main(String[] args){

       StarServiceTester sst1=new StarServiceTester();

       StarList list=sst1.createStars();

       for (Star e : list ){                            // One of the traversal forms of for loop     

       System.out.println(e.toString());

       }

      

      

    }

   

   

    @Override

    public StarList createStars() {

       StarList stars=new StarList();

       Star s1=new Star(new Position(0,0),StarType.BLUE);

       Star s2=new Star(new Position(0,1),StarType.GREEN);

       Star s3=new Star(new Position(1,0),StarType.PURPLE);

       Star s4=new Star(new Position(1,1),StarType.YELLOW);

       Star s5=new Star(new Position(0,2),StarType.RED);

      

       stars.add(s1);

       stars.add(s2);

       stars.add(s3);

       stars.add(s4);

       stars.add(s5);

      

      

       return stars;

    }

    @Override

    public StarList tobeClearedStars(Star base, StarList sList) {

       // TODO Auto-generated method stub

       return null;

    }

    @Override

    public StarList getYMovedStars(StarList clearStars, StarList currentStarList) {

       // TODO Auto-generated method stub

       return null;

    }

    @Override

    public StarList getXMovedStars(StarList currentStarList) {

       // TODO Auto-generated method stub

       return null;

    }

    @Override

    public boolean tobeEliminated(StarList currentStarList) {

       // TODO Auto-generated method stub

       return false ;

    }

    @Override

    public StarList getAwardStarList(StarList currentStarList) {

       // TODO Auto-generated method stub

       return null;

    }

}

3.2 Create objects based on interfaces and use JavaFX to implement related functions

   private void initGameStars(AnchorPane root) {

       // Return to the area where bubble gum is displayed in the form

       /** Environment package : provided **/

       mStarForm = (AnchorPane) root.lookup("#game_pane");

       /******************* PRJ - BU2 - JAVA - 006 ********************/

      

    // StarService service=new StarServiceTester(); // Virtual business class

    // StarService service=new StarServiceImpl(); // Real business class

       StarService service=getStarService();

      

       mCurretStars=service.createStars();

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

           Star star=mCurretStars.get(i);

           Label starFrame=new Label();

           starFrame .setPrefHeight(48);

           starFrame .setPrefWidth(48);

           int x = star .getPosition().getColumn();

           int y=star.getPosition().getRow();

           starFrame.setId("s"+x+y);

           starFrame.setUserData(x+";"+y);

           starFrame.setLayoutX(y*48);

           starFrame.setLayoutY(x*48);

           switch(star.getType().value()){

           case 0:

              starFrame.getStyleClass().add("blue_star");

              break;

           case 1:

              starFrame.getStyleClass().add("green_star");

              break;

           case 2:

              starFrame.getStyleClass().add("yellow_star");

              break;

           case 3:

              starFrame.getStyleClass().add("red_star");

              break;

           case 4:

              starFrame.getStyleClass().add("purple_star");

              break;

             

           }

          

           mStarForm.getChildren().add(starFrame);

             

       }

    /******************************************************/

    }

3.3 Interface isolation

  3.3.1 Single machine event

     class StartEventHandler implements EventHandler<MouseEvent>{

       StarService starservice ;

       StartEventHandler(StarService starservice){

           this.starservice=starservice;

       }

       @Override

       public void handle(MouseEvent event) {

           Label starFrame=(Label)event.getTarget();

           Star base=StarFormUtils.convert(starFrame);

           StarList clearStars=starservice.tobeClearedStars(base, mCurretStars);

           if(clearStars.size()==0){

              return;

           }

          

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

              Star star=clearStars.get(i);

              Label frame=StarFormUtils.findFrame(star, mStarForm);

              StarAnimation.clearStarLable(mStarForm,frame);

              mCurretStars.setNull(star.getPosition().getRow(), star.getPosition().getColumn());

          

          

       }

      

    }

}

3.3.2 Pass the click event object through the constructor

   StartEventHandler handler=new StartEventHandler(starService);

           starFrame.setOnMouseClicked(handler);

                    

          

Chapter 4 Throwing Exceptions

4.1

4.1.1

     Private void initGameStars(AnchorPane root) throws ServiceInitException {

   

           try{

              starService =getStarService();

           }catch(ServiceInitException e){

              StarFormUtils.errorMessage(e.getMessage());

              System.exit(0);

             

           }

  

  4.1.2 Customize exception classes and inherit exception classes

      public class NoClearedStarsException extends Exception {

    public NoClearedStarsException() {

       super();

      

    }

    public NoClearedStarsException(String message) {

       super(message);

      

    }

}

public StarList tobeClearedStars(Star base,StarList sList) throws NoClearedStarsException;

public StarList tobeClearedStars(Star base, StarList mCurrent) throws NoClearedStarsException{

    if (clearStars.size() == 1) {

           clearStars.clear();

       /******************* PRJ - BU2 - JAVA - 008 Task3 ********************/

            throw new NoClearedStarsException();

           /******************************************************/

       }

4.1.3 Put exceptions into stand-alone events

   public class StartEventHandler implements EventHandler<MouseEvent> {

       private StarService starService = null ;

       public StartEventHandler(StarService starService) {

           this.starService = starService;

       }

       @Override

       public void handle(MouseEvent event) {

           // Get the clicked bubblegum view

           Label starFrame = (Label) event.getTarget();

           // Convert the view to a bubblegum entity

           Star base = StarFormUtils.convert(starFrame);

           // Get the bubble gum list that needs to be cleared from the server

           StarList clearStars;

        

              try {

                  clearStars = starService.tobeClearedStars(base,

                         mCurretStars);

             

              // According to the bubble gum list that needs to be cleared obtained from the server, clear the corresponding view

                  clearStars(clearStars);

          

                   } catch (NoClearedStarsException e) {

                  // TODO Auto-generated catch block

                  e.printStackTrace();

              }

       }

    }

Chapter 5 Moving Vertical Bubble Gum

5.1

  5.1.1 Exchange

    private static void swap(Star s1, Star s2){

       Star s=new Star();

       s.setPosition(new Position(s1.getPosition().getRow(),s1.getPosition().getColumn()));

       s.setType(s1.getType());

       s1.setPosition(new Position(s2.getPosition().getRow(),s2.getPosition().getColumn()));

       s1.setType(s2.getType());

       s2.setPosition(new Position(s.getPosition().getRow(),s.getPosition().getColumn()));

       s2.setType(s.getType());

    }

  

  5.1.2 Bubble sort

       public static StarList sort(StarList stars){

       for(int i=0;i<stars.size()-1;i++){

           for(int j=i;j<stars.size()-1;j++){

           if(stars.get(j).getPosition().getRow()>stars.get(j+1).getPosition().getRow()){

                  swap(stars.get(j),stars.get(j+1));

              }

           }

       }

       return stars;

      

    }

   

5.1.3 Test code

   public static void main(String[] args){

    /*  Star s1=new Star(new Position(0,0),StarType.BLUE);

       Star s2=new Star(new Position(1,1),StarType.GREEN);

       swap(s1,s2);

       System.out.println("交换前:"+"s1:(0,0-blue) s2:(1,1-green)\n"+"交换后:s1:"+s1.getPosition().getRow()+","+s1.getPosition().getColumn()+s1.getType()+"  s2:"+s2.getPosition().getRow()+","+s2.getPosition().getColumn()+s2.getType());  */

      

    StarList stars=new StarList();

    Star s1=new Star(new Position(2,0),StarType.BLUE);

    Star s2=new Star(new Position(5,0),StarType.GREEN);

    Star s3=new Star(new Position(9,0),StarType.PURPLE);

    Star s4=new Star(new Position(3,0),StarType.RED);

    Star s5=new Star(new Position(8,0),StarType.YELLOW);

   

    stars.add(s1);

    stars.add(s2);

    stars.add(s3);

    stars.add(s4);

    stars.add(s5);

   

    sort(stars);

   

    for(Star e:stars){

       System.out.println(e.toString());

    }  

   

}

5.1.4 Move vertical bubble gum

   public StarList getYMovedStars(StarList clearStars,

           StarList currentStarList) {

       /************ PRJ - BU2 - JAVA - 010 Task3 3/3 start ***************/

       StarList wait=new StarList();

       int y = 0;

       int move=0;

        StarsUtil.sort(clearStars);

        clearStars.get(clearStars.size()-1);

        for(int i=clearStars.get(clearStars.size()-1).getPosition().getRow();i>=0;i--){

        Star star=currentStarList.lookup(i, y);

        if(star==null){

            break;

        }

        if(clearStars.existed(star)){

            move++;

            System.out.println(move);

            continue;

        }

        MovedStar movestar=new MovedStar(new Position(star.getPosition().getRow(),star.getPosition().getColumn()),star.getType(),new Position(star.getPosition().getRow()+move,star.getPosition().getColumn()));

        wait.add(movestar);

        }

       return wait;

       /************ PRJ - BU2 - JAVA - 010 Task3 3/3 end ******************/

    }

5.2

  5.2.1 Find bubbles based on coordinates

       public Star lookup(int row,int col){

       Star star=null;

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

           star=super.get(i);

           if(star==null){

              continue;

           }

       if(star.getPosition().getRow()==row&&star.getPosition().getColumn()==col){

              return star;

           }

          

       }

       return null;

      

    }    

   

5.2.2 Find bubbles based on Position 

public Star lookup(Position position ){                        // Overload the lookup method and use position to search

       int row=position.getRow();

       int col=position.getColumn();

       Star star=null;

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

           star=super.get(i);

           if(star==null){

              continue;

           }

       if(star.getPosition().getRow()==row&&star.getPosition().getColumn()==col){

              return star;

           }

          

       }

       return null;

      

    }

   

   

// test class

    public static void main(String[] args){

       StarList stars=new StarList();

       Star s1=new Star(new Position(0,0),StarType.BLUE);

       Star s2=new Star(new Position(1,0),StarType.BLUE);

       Star s3=new Star(new Position(2,0),StarType.BLUE);

       Star s4=new Star(new Position(3,0),StarType.BLUE);

       Star s5=new Star(new Position(4,0),StarType.BLUE);

       Star s6=new Star(new Position(5,0),StarType.BLUE);

       Star s7=new Star(new Position(6,0),StarType.BLUE);

       Star s8=new Star(new Position(7,0),StarType.BLUE);

       Star s9=new Star(new Position(8,0),StarType.BLUE);

       Star s10=new Star(new Position(9,0),StarType.BLUE);

      

       stars.add(s1);

       stars.add(s2);

       stars.add(s3);

        stars.add(s4);

       stars.add(s5);

       stars.add(s6);

       stars.add(s7);

       stars.add(s8);

       stars.add(s9);

       stars.add(s10);

      

      

    //  System.out.println("(3,0)位置泡泡糖:"+stars.lookup(3, 0).getPosition().getRow()+","+stars.lookup(3, 0).getPosition().getColumn()+"  "+stars.lookup(3, 0).getType());

       System.out.println(stars.lookup(new Position(3,0)));

       System.out.println(stars.lookup(new Position(1,1)));

    }

5.2.3 Determine whether bubbles exist

public boolean existed(Star s){

       if(s==null){

           return false ;

       }

       if(!(s==null)){

       return ((lookup(s.getPosition().getRow(),s.getPosition().getColumn()))==null)?false:true;

       }

       else return false ;

      

    }

5.3

5.3.1

   public static void sort(StarList starList) {    

       /*****PRJ - BU2 - JAVA - 012 Task1 1/3 Start *******/

       for (int i = 0; i < starList.size() - 1; i++) {

           for (int j = 0; j < starList.size() - i - 1; j++) {

              // Get the Nth bubble gum

              Star preStar = starList.get(j);

              // Get the next bubble gum of the Nth bubble gum ( N+1 )

              Star nextStar = starList.get(j + 1);

              if (preStar.getPosition().getColumn() > nextStar.getPosition()

                     .getColumn()) {

                  swap(preStar, nextStar);

                  continue;

              }

             

             

              if(preStar.getPosition().getColumn()== nextStar.getPosition()

                     .getColumn()){

                  if(preStar.getPosition().getRow()> nextStar.getPosition()

                     .getRow()){

                     swap(preStar, nextStar);

                  }

              }

           }

       }

       /*****PRJ - BU2 - JAVA - 012 Task1 1/3 End ********/

    }

5.3.2

   public static Map<Integer, StarList> group(StarList clearedStars){

       Map<Integer, StarList> map=new HashMap<Integer,StarList>();

       sort(clearedStars);

       Star s=null;

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

           s=clearedStars.get(i);

           if(map.containsKey(s.getPosition().getColumn())){

              map.get(s.getPosition().getColumn()).add(s);

           }

           else{

              map.put(s.getPosition().getColumn(),new StarList());

              map.get(s.getPosition().getColumn()).add(s);

           }

       }

      

       return map;

  }

// test class

public static void main(String[] args){

       StarList stars=new StarList();

       Star s1=new Star(new Position(2,3),StarType.BLUE);

       Star s2=new Star(new Position(1,5),StarType.GREEN);

       Star s3=new Star(new Position(0,9),StarType.PURPLE);

       Star s4=new Star(new Position(0,3),StarType.RED);

       Star s5=new Star(new Position(0,8),StarType.YELLOW);

      

       stars.add(s1);

       stars.add(s2);

       stars.add(s3);

       stars.add(s4);

       stars.add(s5);

      

       group(stars);

      

       //for(Star e:stars){

           //System.out.println(e.toString());

       //}

       System.out.println(group(stars));

      

  }

5.3.3

   public StarList getYMovedStars(StarList clearStars,

           StarList currentStarList) {

       /************ PRJ - BU2 - JAVA - 010 Task3 3/3 start ***************/

       StarList wait=new StarList();

//     int y=0;

    //  int move=0;

      //  StarsUtil.sort(clearStars);

       Map<Integer,StarList> clear=StarsUtil.group(clearStars);

       Iterator<Integer> key=clear.keySet().iterator();

       while(key.hasNext()){

           int y=key.next();

           int move=0;

            for(int i=clear.get(y).get(clear.get(y).size()-1).getPosition().getRow();i>=0;i--){

               Star star=currentStarList.lookup(i, y);

               if(star==null){

                   break;

                }

               if(clearStars.existed(star)){

                   move++;

                   System.out.println(move);

                   continue;

               }

               MovedStar movestar=new MovedStar(new Position(star.getPosition().getRow(),star.getPosition().getColumn()),star.getType(),new Position(star.getPosition().getRow()+move,star.getPosition().getColumn()));

               wait.add(movestar);

               }

       }

       return wait;

       /************ PRJ - BU2 - JAVA - 010 Task3 3/3 end ******************/

    }

Chapter 6 Moving Bubble Gum Horizontally

6.1

  6.1.1

     private ArrayList<Integer> getNullColumns(StarList currentStarList){

       ArrayList<Integer> empty=new ArrayList<Integer>();

       for(int i=0;i<MAX_COLUMN_SIZE;i++){

           Star star=currentStarList.lookup(MAX_ROW_SIZE-1,i);

           if(star==null){

              empty.add(i);

           }

       }

       return empty;

    }

   

6.1.2

   public StarList getXMovedStars(StarList currentStarList) {

    //  getNullColumns(currentStarList);

    // System.out.println(getNullColumns(currentStarList)); // Test code

       /************PRJ - BU2 - JAVA - 013 Task2  2/2 Start **************/

       ArrayList<Integer> nullcol=getNullColumns(currentStarList);

       if ( nullcol == null ){

           return null;

       }

       StarList movedstar=new StarList();

       int move=0;

   

       for(int i=nullcol.get(0);i<MAX_COLUMN_SIZE;i++){

           if(nullcol.contains(i)){

              move++;

           }

           else{

              for(int j=MAX_ROW_SIZE-1;j>=0;j--){

                  if(currentStarList.lookup(j, i)==null){

                     break;

                  }

                  else{

                     MovedStar movedStar=StarsUtil.toMovedStar(currentStarList.lookup(j,i));

                     movedStar.setMovedPosition(new Position(j,i-move));

                     movedstar.add(movedStar);

                 

                  }

              }

           }

          

       }

       return movedstar;

       /************PRJ - BU2 - JAVA - 013 Task2  2/2 End ***************/

    }

Chapter 7 Updates Level Scores

7.1

 7.1.1 I

    public class Configuration {

    Score score;

    public static final String CONF_PATH="score.conf";

    public Score getScore() {

       return score;

    }

   

    public Configuration(){

       score=new Score();

       InputStream is=getClass().getClassLoader().getResourceAsStream(CONF_PATH);

       BufferedReader bu=new BufferedReader(new InputStreamReader(is));

       try{

           score.setLevelScore(Integer.parseInt(bu.readLine()));

           score.setStep(Integer.parseInt(bu.readLine()));

           score.setIncrement(Integer.parseInt(bu.readLine()));

           score.setLength(Integer.parseInt(bu.readLine()));

          

       }catch(FileNotFoundException e){

           score=null;

          

       }

       catch(IOException e){

           score=null;

       }

      

    }

}

7.1.2  Calculation of level scores

   public int nextScoreByLevel(int nextLevel) {

       int nextscore=0;

       int x =0;

       x=((int)((nextLevel-1)/con.score.getLength()))*con.score.getIncrement();

       nextscore=con.score.getLevelScore()+con.score.getStep()+x;

       con.score.setLevelScore(nextscore);

       return nextscore;

    }

 

Chapter 8 Implementing Bubblegum Points Rules

8.1

  8.1.1 

        public int getScoreByStars(StarList stars) {

       int score=LOWER_SCORE*(stars.size()*stars.size());

       return score;

    }

  8.1.2 Bonus Points

      public int getAwardScore(int leftStarNum) {

       /*********PRJ - BU2 - JAVA - 015 Task2 2/3 Start ***********/

       int awardscore=0;

       if(leftStarNum<10){

           return awardscore=LOWER_AWARD_SCORE*((AWARD_LIMIT-leftStarNum)*(AWARD_LIMIT-leftStarNum));

       }else

    return 0;

       /************PRJ - BU2 - JAVA - 015 Task2 2/3 End **************/

    }

  8.1.3  Display customs clearance information

     public boolean isChangeLevel(int score) {

       int levelScore=mConfiguration.getScore().getLevelScore();

      

       if(score>levelScore){

           return true;

       } else return false ;

    }

public boolean isNoticePassLevel(int currentLevel, int score) {

       if(score<mConfiguration.getScore().getLevelScore()){

           return false ;

       }

       if(!(currentLevel==pass)){

           return false ;

       }

       pass++;

       return true;

    }

    /***********PRJ - BU2 - JAVA - 015 Task3 3/3 End **************/

}

Guess you like

Origin blog.csdn.net/weixin_54464792/article/details/120321085