/** *
* CFileReader.java * * Revisions: 1.0 Nov. 24, 2002 * Created the CFileReader class * ** * @author Jose Manuel Caban * @version Version 1.0, Nov. 24, 2002 */ import java.io.*; import java.util.*; public class CFileReader implements Constants{ BufferedReader brReader; /** *@return an array with the first 4 slots holding pacman and the ghost *start locations, slot 5 holding the Background grid, slot 6 holding the *Node Grid */ public Object[] readMap(String mapFile){ Object[] array = new Object[6]; StringTokenizer st; ///////////////////// //Read Start Points// ///////////////////// try{ brReader = new BufferedReader(new FileReader(mapFile)); }catch(FileNotFoundException fnfe){ System.err.println("File Not Found Error - CFileReader"); System.exit(0); } for(int i=0; i<5; i++){ st = new StringTokenizer("b"); try{ st = new StringTokenizer(brReader.readLine()); }catch(IOException ioe){ System.err.println(ioe); System.exit(0); } array[i] = new CCoord(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()),1); } /*End Read Start Points*/ ///////////////////////// String strTemp = ""; CTile[][] cBgGrid; try{ strTemp = brReader.readLine(); }catch(IOException ioe){ System.err.println(ioe); System.exit(0); } //////////////////////////////////////////////////// /*Check whether its standard file or enhanced grid*/ switch(strTemp.charAt(0)){ case 'w': case 'n': case 's': case 'f': cBgGrid = new CTile[15][15]; break; case '1':case '2':case '3':case '4': case '5': case '6': case '7': case '8':case '9':case '0': st = new StringTokenizer(strTemp); cBgGrid = new CTile[Integer.parseInt(st.nextToken())] [Integer.parseInt(st.nextToken())]; try{ strTemp = brReader.readLine(); }catch(IOException ioe){ System.err.println(ioe); System.exit(0); } break; default: cBgGrid = new CTile[0][0]; break; } /*End Check file type*/ /////////////////////// /////////////// /*Read in map*/ st = new StringTokenizer(""); for(int i=0; i