Advertisement
Guest User

Untitled

a guest
Dec 7th, 2015
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. public class Area {
  2.     private Field[][] fields;
  3.  
  4.     public Area(int width, int height) {
  5.         fields = new Field[h][];
  6.         for (int y = 0; y < height; ++y) {
  7.             fields[y] = new Field[w];
  8.             for (int x = 0; x < width; ++x) {
  9.                 fields[y][x] = new Field();
  10.             }
  11.         }
  12.  
  13.         for (int y = 0; y < height; ++y) {
  14.             for (int x = 0; x < width; ++x) {
  15.                 fields[y][x].setNeighbors(neighbors(x, y));
  16.             }
  17.         }
  18.     }
  19.  
  20.     private ArrayList<Field> neighbors(int x, int y) {
  21.         ArrayList<Field> n = new ArrayList<Field>();
  22.         int xFrom = Math.max(x - 1, 0);
  23.         int yFrom = Math.max(y - 1, 0);
  24.         int xTo = Math.min(x + 1, width - 1);
  25.         int yTo = Math.min(y + 1, height - 1);
  26.         for (int yy = yFrom; yy <= yTo; ++yy) {
  27.             for (int xx = xFrom; xx <= xTo; ++xx) {
  28.                 if (xx != x || yy != y) {
  29.                     n.add(fields[yy][xx]);
  30.                 }
  31.             }
  32.         }
  33.     }
  34. }
  35.  
  36. public class Field extends Thread {
  37.     private ArrayList<Field> neighbors;
  38.     private int cost;
  39.  
  40.     public Field(int x, int y) {
  41.         this.x = x;
  42.         this.y = y;
  43.         cost = 0;
  44.     }
  45.  
  46.     public setNeighbors(ArrayList<Field> neighbors) {
  47.         this.neighbors = neighbors;
  48.     }
  49.  
  50.     public run() {
  51.         // zablokuj wszystkie sasiednie pola 3x3 (neighbors)
  52.         // jakies obliczenia ktore zmieniaja this i sasiednie pola
  53.         // odblokuj wszystkie sasiednie pola 3x3 (neighbors)
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement