All pastes #966795 Raw Edit

Cave v0.2

public java v1 · immutable
·published 2008-04-02 00:11 UTC
rendered paste body
package Wumpus; /** * A cave the holds the room array */import java.io.*;import System.Collections.Generic.*;public class Cave{    //Arraylist containing all the room objects of a specific cave    private List<Room> roomList;    private int caveNum;    //Default Constructor with an null arraylist of rooms    public Cave()    {        roomList = null;    }    public Cave(int aCaveNum)    {        caveNum = aCaveNum;        roomList = new List<Room>();    }    public void initializeCave()    {                File cave = new File("cave" + caveNum + ".dat");        if (cave.exists())        {}        else        {            cave = new File("defaultCave.dat");        }        try        {            BufferedReader in = new BufferedReader(new FileReader(cave));            for (int i = 0; i < 30; i++)            {                String[] list = in.readLine().Split(new char[] { ';' });                int[] rmList = new int[6];                boolean canHaveRm = true;                int roomNum = -9;                for (int j = 0; j < list.length; j++)                {                    if (list[j].Contains(","))                    {                        String[] connectingRm = list[j].Split(new char[] { ',' });                        for (int k = 0; k < connectingRm.length; k++)                        {                            rmList[k] = Integer.parseInt(connectingRm[k]);                        }                    }                    else if (list[j].equalsIgnoreCase("true"))                    {                        canHaveRm = true;                    }                    else if (list[j].equalsIgnoreCase("false"))                    {                        canHaveRm = false;                    }                    else                    {                        roomNum = Integer.parseInt(list[j]);                    }                }                roomList.Add(new Room(roomNum, rmList, canHaveRm));            }            in.close();        }        catch(FileNotFoundException e)        {            e.printStackTrace();        }        catch (IOException e)        {            e.printStackTrace();        }    }    /**     * @param roomNum the number of the room to be returned. Based for now on its array position, but can be set to be displayed room number     */    public Room getRoom(int roomNum)    {        return roomList.get_Item(roomNum);    }    /**     * @param roomNum the room number to be used to get connections;     * @return an array of the connecting rooms;     */    public int[] getConnections(int roomNum)    {        Room room = roomList.get_Item(roomNum);        return room.getConnections();    }    public int getCaveName()    {        return caveNum;    }}