Browse Source

Fixed awful typos in Patch, constructors in grid

Also switched back to a class for RuleSet.
    Because intefaces and static methods don't mix.
master
Josh Hofing 11 years ago
parent
commit
705abad2bb
4 changed files with 13 additions and 10 deletions
  1. +2
    -2
      src/Grid.java
  2. +3
    -1
      src/Patch.java
  3. +3
    -4
      src/rules/Conway.java
  4. +5
    -3
      src/rules/RuleSet.java

+ 2
- 2
src/Grid.java View File

@@ -6,14 +6,14 @@ public class Grid {

public Grid() {
_grid = new Patch[1][1];
_grid[0][0] = new Patch(this, 0, 0);
_grid[0][0] = new Patch(this, 0, 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);
_grid[i][j] = new Patch(this, i, j, 0, "");
}
}
}


+ 3
- 1
src/Patch.java View File

@@ -46,7 +46,7 @@ public class Patch {
}

public String toString() {
return _plabel;
return _label;
}

public Patch[] get4Neighbors() {
@@ -55,6 +55,7 @@ public class Patch {
neighbors[1] = _grid.getPatch(_xcor - 1, _ycor);
neighbors[2] = _grid.getPatch(_xcor, _ycor + 1);
neighbors[3] = _grid.getPatch(_xcor, _ycor - 1);
return neighbors;
}

public Patch[] get8Neighbors() {
@@ -67,6 +68,7 @@ public class Patch {
neighbors[5] = _grid.getPatch(_xcor + 1, _ycor - 1);
neighbors[6] = _grid.getPatch(_xcor - 1, _ycor + 1);
neighbors[7] = _grid.getPatch(_xcor - 1, _ycor - 1);
return neighbors;
}

public Patch clone() {


+ 3
- 4
src/rules/Conway.java View File

@@ -3,14 +3,13 @@ package edu.stuy.goldfish.rules;
import edu.stuy.goldfish.Grid;
import edu.stuy.goldfish.Patch;

public class Conway implements RuleSet {
states = 2;
public class Conway extends RuleSet {
public static int states = 2;

@Override
public static Grid run (Grid g) {
Grid newGrid = new Grid(g.getWidth(), g.getHeight());
for (int i = 0; i < g.getWidth(); i++) {
for (int j = 0; j < j.getHeight(); j++) {
for (int j = 0; j < g.getHeight(); j++) {
Patch[] neighbors = g.getPatch(i, j).get8Neighbors();
int numAlive = 0;
for (Patch p : neighbors)


+ 5
- 3
src/rules/RuleSet.java View File

@@ -2,8 +2,8 @@ package edu.stuy.goldfish.rules;

import edu.stuy.goldfish.Grid;

public interface RuleSet {
public static int states;
public class RuleSet {
public static int states = 0;

/**
* Run this ruleset on a grid, returning the result.
@@ -12,6 +12,8 @@ public interface RuleSet {
*
* @return The new grid
*/
public static Grid run (Grid g);
public static Grid run (Grid g) {
return g;
}

}

Loading…
Cancel
Save