Bläddra i källkod

Added Grid.java, Patch.java

master
Kevin Li 12 år sedan
förälder
incheckning
832b6cf301
2 ändrade filer med 44 tillägg och 0 borttagningar
  1. +29
    -0
      Grid.java
  2. +15
    -0
      Patch.java

+ 29
- 0
Grid.java Visa fil

@@ -0,0 +1,29 @@
public class Grid {

private Patch[][] _grid;

public Grid() {
_grid = new Patch[1][1];
_grid[0][0] = new Patch(this, 0, 0);
}

public Grid(int x, int y) {
_grid = new Patch[x][y];
for(int i = 0; i < x; i++) {
for(int j = 0; j < y; j++) {
_grid[i][j] = new Patch(this, i, j);
}
}
}

public String toString() }
String ans = "";
for(int i = 0; i < _grid.length; i++) {
for(int j = 0; j < _grid[i].length; j++) {
ans += _grid[i][j];
}
ans += "\n";
}
return ans;
}
}

+ 15
- 0
Patch.java Visa fil

@@ -0,0 +1,15 @@
public class Patch {
private int _pxcor, _pycor;
private String _plabel;
private Grid _myGrid;

public Patch(Grid grid, int xcor, int ycor) {
_myGrid = grid;
_pxcor = xcor;
_pycor = ycor;
}

public String toString() {
return _plabel;
}
}

Laddar…
Avbryt
Spara