Guest User

Untitled

a guest
Apr 23rd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.08 KB | None | 0 0
  1. public class Ground {
  2.     Item myBoard[][];
  3.     ArrayList<Robot> myList=null;
  4.     LinkedList<GeometricElement> mySapesList=null;
  5.     protected Dot size;
  6.     public Ground(int row,int col)
  7.     {
  8.     myBoard=new Item[size.getRow()][size.getCol()];
  9.     for (int i=0;i< size.getRow();i++)
  10.         for (int j=0;j< size.getRow();j++)
  11.         {
  12.            
  13.             myBoard[i][j]=new Item();
  14.            
  15.         }
  16.    
  17.     size=new Dot(row, col);
  18.     myList=new ArrayList<Robot>();
  19.     mySapesList=new LinkedList<GeometricElement>();
  20.     }
  21.     public Dot getSize() {
  22.         return size;
  23.     }
  24.    
  25.     public void eatAllTheShapes()
  26.     {
  27.         //pass on all the shapse and ate them
  28.         for (int i=0;i<mySapesList.size();i++)
  29.         {
  30.             eatShape(mySapesList.get(i));
  31.            
  32.         }
  33.     }
  34.     public void eatShape(GeometricElement elem)
  35.     {
  36.         //first calcluate the nierst shape(we asume anormal size of the ground)
  37.         float distance=1000000000;
  38.         //find the minmum distance
  39.         for(int i=0;i<myList.size();i++)
  40.         {
  41.             if( distance<(myList.get(i).calculateRealDistanceFromDot(elem.getD()))&&
  42.                     myList.get(i).getSize()-elem.getArea()>=0)
  43.             {  
  44.                 distance=myList.get(i).calculateRealDistanceFromDot(elem.getD());
  45.             }
  46.         }
  47.         //naw after we now the closest distance  we find the closest robot
  48.         for(int i=0;i<myList.size();i++)
  49.         {
  50.             if( distance==(myList.get(i).calculateRealDistanceFromDot(elem.getD())))
  51.             {  
  52.                 //update the distance the robot went
  53.                 myList.get(i).setSumDist(myList.get(i).calculateDistanceFromDot((elem.getD())));
  54.                 //update the realdistance the robot went
  55.                 myList.get(i).setSumRealDist(myList.get(i).calculateRealDistanceFromDot(elem.getD()));
  56.                 //set the postion of the robot to the place of the shape
  57.                 myList.get(i).setPosion(elem.getD());
  58.                 elem.setEaten(true);
  59.             }
  60.         }
  61.         //Collections.max(myList, comp)
  62.     }
  63.    
  64.     public void printFinalRestlt()
  65.     {
  66.         //print the resukt of the robots
  67.         for(int i=0;i<myList.size();i++)
  68.         {
  69.         System.out.println("ROBOT NUM"+i);
  70.         System.out.println(myList.get(i));
  71.         }
  72.         for(int i=0;i<mySapesList.size();i++)
  73.         {
  74.         if(!mySapesList.get(i).isEaten())
  75.         System.out.println("shape"+i+"didnt eaten");
  76.         }
  77.     }
  78.    
  79.    
  80. }
Add Comment
Please, Sign In to add comment