Пример #1
0
bool MainWindow::updateConnections()
{
  bool newconnection[BoardSize * BoardSize];
  for(int i = 0; i < BoardSize * BoardSize; i++)
    newconnection[i] = false;

  CellList list;
  if(!root->isRotated())
  {
    newconnection[root->index()] = true;
    list.append(root);
  }
  while(!list.isEmpty())
  {
    Cell* cell = list.first();
    Cell* ucell = uCell(cell);
    Cell* rcell = rCell(cell);
    Cell* dcell = dCell(cell);
    Cell* lcell = lCell(cell);

    if((cell->dirs() & Cell::U) && ucell && (ucell->dirs() & Cell::D) && !newconnection[ucell->index()] && !ucell->isRotated())
    {
      newconnection[ucell->index()] = true;
      list.append(ucell);
    }
    if((cell->dirs() & Cell::R) && rcell && (rcell->dirs() & Cell::L) && !newconnection[rcell->index()] && !rcell->isRotated())
    {
      newconnection[rcell->index()] = true;
      list.append(rcell);
    }
    if((cell->dirs() & Cell::D) && dcell && (dcell->dirs() & Cell::U) && !newconnection[dcell->index()] && !dcell->isRotated())
    {
      newconnection[dcell->index()] = true;
      list.append(dcell);
    }
    if((cell->dirs() & Cell::L) && lcell && (lcell->dirs() & Cell::R) && !newconnection[lcell->index()] && !lcell->isRotated())
    {
      newconnection[lcell->index()] = true;
      list.append(lcell);
    }
    list.removeFirst();
  }

  bool isnewconnection = false;
  for(int i = 0; i < BoardSize * BoardSize; i++)
  {
    if(!board[i]->isConnected() && newconnection[i])
      isnewconnection = true;
    board[i]->setConnected(newconnection[i]);
  }

  return isnewconnection;
}