Hmm. It's been a while since I've worked on a text-based RPG but IIRC you can set up the room objects using a graph structure where the rooms are nodes and they are connected by bi-directional edges. As an example, Room1 has exits (S, W, N) and Room2 has exits (N, E, S, W), and Room1 (W) is attached to Room2 (E).
I know this may sound confusing but googling some of these terms may help get you started. Good luck on your game and remember to have fun.