// @topic W010202 FLTK Graphics -- maze navigation
// @brief Business class: room with doors

#ifndef _ROOM_H_INCLUDED_
#define _ROOM_H_INCLUDED_

#include <cassert>

class Room {
    int light_switch;
    Room* door_N;
    Room* door_E;
    Room* door_S;
    Room* door_W;
    const std::string name;
public:
    enum {
        COMPASS_NORTH,
        COMPASS_NORTHEAST,
        COMPASS_EAST,
        COMPASS_SOUTHEAST,
        COMPASS_SOUTH,
        COMPASS_SOUTHWEST,
        COMPASS_WEST,
        COMPASS_NORTHWEST,
        COMPASS_NORTH_2,
        COMPASS_UNKNOWN
    };

    Room( char const* name )
        : light_switch( 0 ), door_N( 0 ), door_E( 0 ), door_S( 0 ), door_W( 0 ), name( name )
    {
    }

    Room* get_room( int direction )
    {
        switch( direction ) {
            case COMPASS_NORTH_2:
            case COMPASS_NORTH: return door_N;
            case COMPASS_EAST:  return door_E;
            case COMPASS_SOUTH: return door_S;
            case COMPASS_WEST:  return door_W;
            default:
                //assert( !"Bad direction param" );
                return NULL;
        }
    }

    int get_direction( Room* door )
    {
        if ( door_N == door ) return COMPASS_NORTH;
        if ( door_E == door ) return COMPASS_EAST;
        if ( door_S == door ) return COMPASS_SOUTH;
        if ( door_W == door ) return COMPASS_WEST;
        return COMPASS_UNKNOWN;
    }

    void add_door( int direction, Room* another_room )
    {
        switch( direction ) {
            case COMPASS_NORTH:
                door_N = another_room;
                another_room->door_S = this;
                break;
            case COMPASS_EAST:
                door_E = another_room;
                another_room->door_W = this;
                break;
            case COMPASS_SOUTH:
                door_S = another_room;
                another_room->door_N = this;
                break;
            case COMPASS_WEST:
                door_W = another_room;
                another_room->door_E = this;
                break;
            default:
                assert( !"Bad door request" );
        }
    }

    char const* get_name()
    {
        return name.c_str();
    }

};//class Room

#endif //_ROOM_H_INCLUDED_