Ver Mensaje Individual
  #1 (permalink)  
Antiguo 11/03/2009, 20:53
fdaf58
Invitado
 
Mensajes: n/a
Puntos:
Exception in thread "main" java.lang.Null http://mx.geocities.com/fdaf58/1.JPG

import java.io.*;
//import java.util.Stack;


class MazeCell {
public int x, y;
public MazeCell(){
}
public MazeCell(int i, int j){
x= i; y=j;
}
public boolean equals(MazeCell cell){
return x == cell.x && y == cell.y;
}
}
class Maze{
private int rows = 0, cols = 0;
private char[][] store;
private MazeCell currentCell, exitCell =
new MazeCell(), entryCell = new MazeCell();
private final char exitMarker = 's', entryMarker = 'e', visited = '.';
private final char passage = '0', wall = '1';
private java.util.Stack mazeStack = new java.util.Stack();
public Maze() {
int row = 0, col = 0;
java.util.Stack mazeRows = new java.util.Stack();
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader buffer = new BufferedReader(isr);
System.out.println("Introduzca un laberinto rectangular utilizando los caracteres "
+"siguientes:\ne - entrada\ns - salida\n1 - muro\n0 - pasillo\n"
+"introduzca una linea a la vez; termine con Ctrl-z: ");
try {
String str = buffer.readLine();
while (str != null){
row++;
cols = str.length();
str = "1" + str + "1"; //pone 1 en las celdas del borde;
mazeRows.push(str);
if (str.indexOf(exitMarker) != -1){
exitCell.x = row;
exitCell.y = str.indexOf(exitMarker);
}
if (str.indexOf(entryMarker) != -1) {
entryCell.x = row;
entryCell.y = str.indexOf(entryMarker);
}
str= buffer.readLine();
}
}catch(IOException eof){
rows = row;
store = new char[rows+2][]; //crea un arreglo ID de arreglos char;
store[0] = new char[cols+2]; //una fila de borde;
for (; !mazeRows.isEmpty();row--)
store[row] = ((String) mazeRows.pop()).toCharArray();
store[rows+1] = new char[cols+2]; //otro fila de borde;
for (col = 0; col <= cols+1;col++){
store[0][col]=wall; // llena las filas de borde con 1;
store[rows+1][col]=wall;
}
}
}
private void display(PrintStream out){
for (int row = 0;row <= rows+1;row++)
System.out.println(store[row]);
System.out.println();
}
private void pushUnvisited(int row, int col){
if (store[row][col] == passage || store[row][col]==exitMarker)
mazeStack.push(new MazeCell(row,col));
}
public void exitMaze(PrintStream out){
currentCell = entryCell;
out.println();
while (!currentCell.equals(exitCell)){
int row = currentCell.x;
int col = currentCell.y;
display(System.out); //imprime una imagen instantanea;
if (!currentCell.equals((entryCell)))
store[row][col] = visited;
pushUnvisited(row-1, col);
pushUnvisited(row+1, col);
pushUnvisited(row, col-1);
pushUnvisited(row, col+1);
if (mazeStack.isEmpty()){
display(out);
out.print("Intento fallido");
return;
}
else currentCell = (MazeCell) mazeStack.pop();
}
display(out);
out.print("Intento exitoso");
}
public static void main (String args[]){
(new Maze()).exitMaze(System.out);
}
}

Disculpen no se porque motivo me salen esas excepciones, agradeceria si me pueden ayudar.
el link de la imagen esta en el titulo