Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Area {
- private Field[][] fields;
- public Area(int width, int height) {
- fields = new Field[h][];
- for (int y = 0; y < height; ++y) {
- fields[y] = new Field[w];
- for (int x = 0; x < width; ++x) {
- fields[y][x] = new Field();
- }
- }
- for (int y = 0; y < height; ++y) {
- for (int x = 0; x < width; ++x) {
- fields[y][x].setNeighbors(neighbors(x, y));
- }
- }
- }
- private ArrayList<Field> neighbors(int x, int y) {
- ArrayList<Field> n = new ArrayList<Field>();
- int xFrom = Math.max(x - 1, 0);
- int yFrom = Math.max(y - 1, 0);
- int xTo = Math.min(x + 1, width - 1);
- int yTo = Math.min(y + 1, height - 1);
- for (int yy = yFrom; yy <= yTo; ++yy) {
- for (int xx = xFrom; xx <= xTo; ++xx) {
- if (xx != x || yy != y) {
- n.add(fields[yy][xx]);
- }
- }
- }
- }
- }
- public class Field extends Thread {
- private ArrayList<Field> neighbors;
- private int cost;
- public Field(int x, int y) {
- this.x = x;
- this.y = y;
- cost = 0;
- }
- public setNeighbors(ArrayList<Field> neighbors) {
- this.neighbors = neighbors;
- }
- public run() {
- // zablokuj wszystkie sasiednie pola 3x3 (neighbors)
- // jakies obliczenia ktore zmieniaja this i sasiednie pola
- // odblokuj wszystkie sasiednie pola 3x3 (neighbors)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement