Problemas ao localizar string na linha de um txt [RESOLVIDO]

1 resposta
InSeOfKn

Ola!

Esta eu aqui ajudando uma amigo criando uma base para ele começar a desenvolver um jogo de RPG.
Já esta tudo funcionando mais quando eu tentei fazer a leitura do mapa de tiles de um txt encontrei um problema eu ler eu percorro linha por linha o arquivo só que quando ele encontrasse uma linha que tivesse escrito "new" ele era para entrar no if mais isso não ocorre e acaba dendo erro por não incrementar a variável nivel

abaixo vai o txt e o metodo responsável por colocar os dados numa matriz tridimensional

txt
$3 10 10
new
001 001 001 001 001 001 001 001 001 001
001 001 001 001 001 001 001 001 001 001
001 001 001 001 001 001 001 001 001 001
001 001 001 001 001 001 001 001 001 001
001 001 001 001 001 001 001 001 001 001
001 001 001 001 001 001 001 001 001 001
001 001 001 001 001 001 001 001 001 001
001 001 001 001 001 001 001 001 001 001
001 001 001 001 001 001 001 001 001 001
001 001 001 001 001 001 001 001 001 001
new
char
000 000 000 000 000 000 000 000 000 000
000 100 101 000 000 000 000 000 000 000
000 108 009 000 000 000 000 000 000 000
000 116 117 000 000 000 000 000 000 000
000 124 125 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000
método
try {  
			BufferedReader reader = new BufferedReader(new FileReader(arquivo));  
			int nivel = -1;  
			int col = 0;

			String linha = reader.readLine();  

			while (linha != null) {  
				if(linha.charAt(0)=='$'){
					linha = linha.substring(1);
					StringTokenizer st = new StringTokenizer(linha);
					tiles = new Tile[Integer.parseInt(st.nextToken())][Integer.parseInt(st.nextToken())][Integer.parseInt(st.nextToken())];
				}else{
					if(linha.indexOf("new")>=0){
						nivel++;
						col = 0;
						System.out.println("linha criada");
					}else if(linha.indexOf("char")>=0){
						nivel++;
						tiles[nivel] = null;
						System.out.println("char adicionado");
					}else{

						StringTokenizer st = new StringTokenizer(linha);
						int valor;
						for(int row=0; row<tiles[nivel][col].length; row++){
							valor = Integer.parseInt(st.nextToken());
							if(valor!=0)
								tiles[nivel][col][row] = Tiles.TILESET_1[valor];
							else
								tiles[nivel][col][row] = Tiles.PADRAO;
						}
						col++;
					}
					linha = reader.readLine();
				}
			}   
		} catch (Exception e) {  
			e.printStackTrace();  
		}

aguardo resposta e agradeço a todos
até!

1 Resposta

InSeOfKn

achei o erro eu coloquei o linha = reader.readLine(); no else errado

até!

Criado 17 de novembro de 2010
Ultima resposta 17 de nov. de 2010
Respostas 1
Participantes 1