Quote from: LM on 29.11.2008, 21:40:23
mate to na dreamhoste.
nemate zac.
dik
kOsTi: ja som to teraz stiahol, takze ...
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Zobrazi» príspevky MenuQuote from: LM on 29.11.2008, 21:40:23
mate to na dreamhoste.
nemate zac.
private int countAdjacentMines(int row, int column) {
int count = 0;
for(int i = -1; i <= 1; i++){
int actRow = row + i;
for(int j = -1; j <= 1; j++){
int actColumn = column + j;
if(actRow >= 0 && actRow < getRowCount() &&
actColumn >= 0 && actColumn < getColumnCount()) {
if(tiles[actRow][actColumn] instanceof Mine) {
count++;
}
}
}
}
return count;
}
private void generate() {
//throw new UnsupportedOperationException("Method generate not yet implemented");
// do pola doplnim miny
Random r = new Random();
for(int i=0;i<mineCount;) {
int nr = r.nextInt(rowCount);
int nc = r.nextInt(columnCount);
if(tiles[nr][nc] == null) {
tiles[nr][nc] = new Mine();
i++;
}
}
// do ostatnych policok doplnim napovedu
for(int i=0;i<rowCount;i++) {
for(int j=0;j<columnCount;j++) {
if(tiles[i][j] == null) {
tiles[i][j] = new Clue(countAdjacentMines(i,j));
}
}
}
}
if (tile.getState() == Tile.State.CLOSED)
public void update() {
//throw new UnsupportedOperationException("Method update not yet implemented");
char[] alfa = {' ','A','B','C','D','E','F','G','H','I'};
for(int i=-1;i<field.getRowCount();i++) {
for(int j=0;j<field.getColumnCount();j++) {
if(j==0) {
// vypise prazdny znak az I
System.out.printf("%s",alfa[i+1]);
}
if(i==-1) {
// vypise 0 az 9
System.out.printf("%3d", j);
}
else {
// vypise hracie pole
Tile tile = field.getTile(i, j);
if(tile.getState() == Tile.State.OPEN) {
if(tile instanceof Mine) {
System.out.printf("%3s", "X");
}
else if(tile instanceof Clue) {
// potreba pretypovania Tile na Clue,
// aby som mohol pouzit metodu getValue()
System.out.printf("%3d", ((Clue) tile).getValue());
}
}
else if(tile.getState() == Tile.State.MARKED) {
System.out.printf("%3s", "M");
}
else {
System.out.printf("%3s", "-");
}
}
}
System.out.print("\n");
}
}