void Command::set_e_info(Cell cell) { QPointer<Figure> fig = desk_->getFigure(cell); if (!fig.isNull()) e_cell_info_ = CellInfo(cell, fig->getFigName(), fig->getColor()); else e_cell_info_ = CellInfo(cell, " ", NONE); }
// _____________________________________________________________________________ void MineSweeperState::revealCell(size_t row, size_t col) { int mineCount = 0; // the game is lost if an unrevealed mine is revealed if (getCellInfo(row, col) == UNREVEALED_MINE) { _status = LOST; _mineField[row][col] = REVEALED_MINE; } // get number of mines in surrounding cells // do if the field is unrevealed and not a mine or marked as one if (getCellInfo(row, col) == UNREVEALED) { for (int i = -1; i < 2; i++) { for (int j = -1; j < 2; j++) { if (getCellInfo(row + i, col + j) <= MARKED_CORRECT) mineCount++; } } _mineField[row][col] = CellInfo(mineCount); _numRevealed++; // reveal cells recursively if there are no mines in surrounding cells if (mineCount == 0) { for (int i = -1; i < 2; i++) { for (int j = -1; j < 2; j++) { revealCell(row + i, col + j); } } } // check whether the game is won already if (_numMarked + _numRevealed == _numCols * _numRows) _status = WON; } }
void W32Table::setElement(W32WidgetPtr element, int row, int fromColumn, int toColumn) { if (!element.isNull()) { if (row >= (int)myRows.size()) { myRows.insert(myRows.end(), row - myRows.size() + 1, RowList()); } RowList &rowList = myRows[row]; RowList::iterator it = rowList.begin(); bool canInsertAfter = true; for (; it != rowList.end(); ++it) { if (it->XFrom > toColumn) { break; } canInsertAfter = it->XTo < fromColumn; } if (canInsertAfter) { rowList.insert(it, CellInfo(fromColumn, toColumn, element)); } } }
void Command::set_b_info(Cell cell) { QPointer<Figure> fig = desk_->getFigure(cell); b_cell_info_ = CellInfo(cell, fig->getFigName(), fig->getColor()); }