Skip to content

Commit

Permalink
act
Browse files Browse the repository at this point in the history
  • Loading branch information
Macro21 committed Mar 5, 2018
1 parent 416620f commit b2f78f5
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 31 deletions.
Binary file modified Practica 1/bin/aStar/Board$3.class
Binary file not shown.
Binary file removed Practica 1/bin/aStar/Board$4.class
Binary file not shown.
Binary file modified Practica 1/bin/aStar/Board.class
Binary file not shown.
Binary file modified Practica 1/bin/aStar/Star$2.class
Binary file not shown.
Binary file modified Practica 1/bin/aStar/Star.class
Binary file not shown.
Binary file modified Practica 1/bin/dataStructures/Cell.class
Binary file not shown.
41 changes: 18 additions & 23 deletions Practica 1/src/aStar/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,21 @@ private void createMatrix(){
for(int j = 1; j<=N_COLS;j++) {
Cell cell = new Cell(i,j);
JButton b = cell.getCell();
if(b.getText().equals("")) {
cell.setDefaultColor();
}
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
cell.isBarrier();
}
});
this.pMatrix.add(cell.getCell());
this.pMatrix.add(b);
this.matrix[i][j] = cell;
}
}
this.pFrame.setPreferredSize(new Dimension(700+(N_ROWS*15), 600+(N_COLS*15)));
this.pMatrix.setPreferredSize(new Dimension(700+(N_ROWS*20), 600+(N_COLS*15)));
this.pFrame.setPreferredSize(this.pMatrix.getPreferredSize());
this.pFrame.revalidate();
}

Expand Down Expand Up @@ -321,6 +325,18 @@ else if (x == goalX && y == goalY) {
}
}
}

public void repaintDefaultMatrix(Cell matrix[][]) {
createMatrix();
for(int i = 1; i<= N_ROWS; i++) {
for(int j = 1; j <= N_COLS; j++) {
Cell c = matrix[i][j];
if(!c.getCell().getText().equals("")) {
this.matrix[i][j].isBarrier();
}
}
}
}

public Cell[][] getMatrix() {
return matrix;
Expand Down Expand Up @@ -377,27 +393,6 @@ public void setXg(int goalX) {
public void setYg(int goalY) {
this.goalY = goalY;
}

public void repaintDefaultMatrix() {
this.pMatrix.removeAll();
this.pMatrix.setLayout(new GridLayout(this.N_ROWS, this.N_COLS));
matrix = new Cell[N_ROWS+1][N_COLS+1];
for(int i = 1; i<=N_ROWS; i++) {
for(int j = 1; j<=N_COLS;j++) {
Cell cell = new Cell(i,j);
JButton b = cell.getCell();
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
cell.isBarrier();
}
});
this.pMatrix.add(cell.getCell());
this.matrix[i][j] = cell;
}
}
this.pFrame.revalidate();
}

public JFrame getpFrame() {
return pFrame;
Expand Down
11 changes: 7 additions & 4 deletions Practica 1/src/aStar/Star.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,15 @@ private void iniStar() throws Exception {
N = board.getN_ROWS();
M = board.getN_COLS();

if(startX > N || startY > M || goalX > N || goalY > M) {
throw new Exception("Error, fuera de rango");
}
if(startX > N || startY > M || goalX > N || goalY > M)
throw new Exception("Error, fuera de rango!");

matrix = board.getMatrix();
board.repaintDefaultMatrix();
if(!matrix[startX][startY].getCell().getText().equals(""))
throw new Exception("Error, inicio en obstaculo!");
if(!matrix[goalX][goalY].getCell().getText().equals(""))
throw new Exception("Error, fin en obstaculo!");
board.repaintDefaultMatrix(matrix);
this.close.clear();
this.open.clear();

Expand Down
8 changes: 4 additions & 4 deletions Practica 1/src/dataStructures/Cell.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ public void isBarrier() {
this.cell.setText("X");
}

public void isNormal() {
this.cell.setBackground(new Color(255,255,204));
}

public void setCell(JButton cell) {
this.cell = cell;
}
Expand Down Expand Up @@ -99,4 +95,8 @@ else if (this.h == c2.getH()) {
}
return 1;
}

public void setDefaultColor() {
this.cell.setBackground(new Color(255,255,204));
}
}

0 comments on commit b2f78f5

Please sign in to comment.