|
@ -2,22 +2,18 @@ package de.tims.fleetstorm.matchfield; |
|
|
|
|
|
|
|
|
public class Matchfield { |
|
|
public class Matchfield { |
|
|
|
|
|
|
|
|
private int[][] matchfield; |
|
|
|
|
|
|
|
|
private Coordinate[][] matchfield; |
|
|
private int size; |
|
|
private int size; |
|
|
|
|
|
|
|
|
public static final int EMPTY = 0; |
|
|
|
|
|
public static final int SHIP = 1; |
|
|
|
|
|
public static final int SHOT = 2; |
|
|
|
|
|
|
|
|
|
|
|
public Matchfield(int size) { |
|
|
public Matchfield(int size) { |
|
|
this.size = size; |
|
|
this.size = size; |
|
|
this.matchfield = new int[this.size][this.size]; |
|
|
|
|
|
|
|
|
this.matchfield = new Coordinate[this.size][this.size]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public int[][] createMatchfield() { |
|
|
|
|
|
|
|
|
public Coordinate[][] createMatchfield() { |
|
|
for (int i = 0; i < size; i++) { |
|
|
for (int i = 0; i < size; i++) { |
|
|
for (int j = 0; j < size; j++) { |
|
|
for (int j = 0; j < size; j++) { |
|
|
this.matchfield[i][j] = Matchfield.EMPTY; |
|
|
|
|
|
|
|
|
this.matchfield[i][j] = new Coordinate(i, j); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -29,11 +25,11 @@ public class Matchfield { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public int getState(int x, int y) { |
|
|
public int getState(int x, int y) { |
|
|
return this.matchfield[x][y]; |
|
|
|
|
|
|
|
|
return this.matchfield[x][y].getState(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void setState(int x, int y, int state) { |
|
|
public void setState(int x, int y, int state) { |
|
|
this.matchfield[x][y] = state; |
|
|
|
|
|
|
|
|
this.matchfield[x][y].setState(state); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |