Exemple #1
0
bool Grid::isCellAvailable(int x,int y)
{
    return !isCellOccupied(x,y);
}
Exemple #2
0
bool Grid::timerTick(float dTime)
{
  static bool emptySent = true;
  bool result = false, full;
  
  { // Animate the vanishing bits
    list<GridBit> vanished;
    
    for (list<GridBit>::iterator cur=vanishingBits.begin(); cur != vanishingBits.end(); cur++)
    {
      if (cur->timerTick(dTime))
        result = true;
      else
        vanished.push_back(*cur);
    }
    
    if (!vanished.empty())
      for (list<GridBit>::const_iterator cur=vanished.begin(); cur != vanished.end(); cur++)
        vanishingBits.remove(*cur);
  }
  
  if (result)
    return true;
  
  // Trigger animations
  for (int x=0; x < width; x++)
  {
    for (list<GridBit>::iterator cur = gridBits[x].begin();
                                 cur != gridBits[x].end();
                                 cur++)
    {
      if (cur->timerTick(dTime))
        result = true;
    }
  }
  
  if (result)
    return true;
  
  // Check for full rows
  for (int y=0,ay=0; y < height; y++,ay++)
  {
    full = true;
    
    for (int x=0; x < width; x++)
      if (!isCellOccupied(x, y))
      {
        full = false;
        break;
      }
    
    if (!full) continue;
    result = true;
    
    // Row is full, remove row and move the above blocks down
    for (list<GridListener*>::iterator cur=listeners.begin(); cur != listeners.end(); cur++)
      (*cur)->rowRemoved(ay);
    
    GridBit* bit;
    for (int x=0; x < width; x++)
    {
      bit = getGridBit(x, y);
      if (bit != NULL)
      {
        vanishingBits.push_back(*bit);
        vanishingBits.back().triggerVanishing();
        gridBits[x].remove(*bit);
      }
      
      // move the blocks above down
      for (int y2=y+1; y2 < height; y2++)
      {
        bit = getGridBit(x, y2);
        if (bit != NULL)
          bit->drop(1);
      }
    }
    
    // Make sure we don't miss the new current row
    y--;
  }// end for y
  
  if (!emptySent && !result)
  {
    bool empty = true;
    for (int i=0; i < width; i++)
      if (!gridBits[i].empty())
      {
        empty = false;
        break;
      }
    if (empty)
    {
      emptySent = true;
      for (list<GridListener*>::iterator cur = listeners.begin(); cur != listeners.end(); cur++)
        (*cur)->gridEmpty();
    }
  }
  else if (result)
    emptySent = false;
  
  return result;
}
Exemple #3
0
bool Grid::isCellAvailable(TileOfCell *cell)
{
    return !isCellOccupied(cell);
}