Exemple #1
0
bool			Map::lineIsFree(const int x, const int y, const int nb_free, const int to_add, const bool modif_x)
{
  Obj *			next;

  if (nb_free >= 4)
    return (true);
  if (modif_x == true)
    {
      if ((next = this->getObj(x + to_add, y)) && (next->get_type() == EMPTY
						    || next->get_type() == PERSO))
	{
	  return (this->lineIsFree(x + to_add, y, nb_free + 1, to_add, modif_x));
	}
      return (false);
    }
  else
    {
      if ((next = this->getObj(x , y + to_add)) && (next->get_type() == EMPTY
						    || next->get_type() == PERSO))
	{
	  return (this->lineIsFree(x, y + to_add, nb_free + 1, to_add, modif_x));
	}
      return (false);
    }
  return (false);
}
Exemple #2
0
bool			Map::CanBePlaced(int i, int j)
{

  Obj			*on = getObj(j, i);

  if (on->get_type() == EMPTY || on->get_type() == PERSO)
    {
      if (this->DiagIsFree(on->get_x(), on->get_y()) == true
	  || this->lineIsFree(on->get_x(), on->get_y(), 1, 1, true) == true
	  || this->lineIsFree(on->get_x(), on->get_y(), 1,  -1, true) == true
	  || this->lineIsFree(on->get_x(), on->get_y(), 1, 1, false) == true
	  || this->lineIsFree(on->get_x(), on->get_y(), 1, -1, false) == true
	  )
	return (true);
    }
  return (false);
}
Exemple #3
0
bool			Map::DiagIsFree(const int x, const int y)
{
  Obj *		next;

  if (((next = this->getObj(x + 1, y))
       && this->check_empty(next->get_type()) == true
       && (next = this->getObj(x, y + 1))
       && this->check_empty(next->get_type()) == true)
      || ((next = this->getObj(x - 1, y)) &&
	  this->check_empty(next->get_type()) == true
	  && (next = this->getObj(x, y - 1)) &&
	  this->check_empty(next->get_type()) == true)
      || ((next = this->getObj(x + 1, y)) &&
	  this->check_empty(next->get_type()) == true
	  && (next = this->getObj(x, y - 1)) &&
	  this->check_empty(next->get_type()) == true)
      || ((next = this->getObj(x - 1, y)) &&
	  this->check_empty(next->get_type()) == true
	  && (next = this->getObj(x, y + 1)) &&
	  this->check_empty(next->get_type()) == true)
      )
    return (true);
  return (false);
}