/*_________________________________________________

___________________________________________________
preprocessor*/

#include "tile.hpp"

/*_________________________________________________
tileBase Method*/

//constructor
tileBase::tileBase (base*back)
{
    _col = _row = _rotation = 0;
    _back = back;
}

//rotation 90 cw
void tileBase::rotate()
{
    _rotation = (_rotation+1)%4;
}

//move at coordinate with validation
void tileBase::move(int col, int row)
{
    if (col >=0 && col < 4 && row >= 0 && row < 4)
    {
        _col = col;
        _row = row;
    }
}

//reset iterator
void tileBase::reset()
{
    _iterator=0;
    _col = 0;
    _row = 0;
    _rotation = 0;
}

//test iterator
bool tileBase::end()
{
    return _iterator >= 36;
}

//increase iterator
void tileBase::next()
{
    _iterator++;
    _rotation = (_rotation+1)%4;
    int tmp = _iterator/4;
    _col = tmp%3;
    _row = tmp/3;
}

/*_________________________________________________
tileBase protected Method*/

//test if coordinate is under the tile
bool tileBase::under(int col, int row)
{
    return col >= _col && col < _col+2 && row >= _row && row < _row+2;
}

//return name from grid behind the tile
char tileBase::backName(int col, int row)
{
    return _back->getName(col, row);
}

//return property from grid behind the tile
char tileBase::backAt (int col, int row)
{
    if (_back)
        return _back->getAt(col,row);
    return ' ';
}

