Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Collections;
  3. import java.util.Comparator;
  4.  
  5. public class Point {
  6.  
  7. public ArrayList<Point> neighbors;
  8. public static Integer []types ={0,1,2,3};
  9. public int type;
  10. public int staticField;
  11. public boolean isPedestrian;
  12.  
  13. public Point() {
  14. type=0;
  15. staticField = 100000;
  16. neighbors= new ArrayList<Point>();
  17. }
  18.  
  19. public void clear() {
  20. staticField = 100000;
  21.  
  22. }
  23.  
  24. public boolean calcStaticField() {
  25. Boolean toReturn = false;
  26. for (Point neighbor: neighbors) {
  27. if (neighbor.staticField < this.staticField -1){
  28. this.staticField = neighbor.staticField +1;
  29. toReturn = true;
  30. }
  31. }
  32. return toReturn;
  33. }
  34.  
  35. public void move(){
  36. if (isPedestrian){
  37. Point neighbor = Collections.min(neighbors, Comparator.comparing(n -> {
  38. if (!n.isPedestrian && n.staticField < this.staticField ){
  39. return n.staticField;
  40. }
  41. else {
  42. return 100;
  43. }
  44. }));
  45.  
  46. if (!(neighbor == null)){
  47. neighbor.isPedestrian=true;
  48. this.isPedestrian=false;
  49. }
  50. }
  51. }
  52.  
  53. public void addNeighbor(Point nei) {
  54. neighbors.add(nei);
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement