Exemple #1
0
/**
 * Toggle flag on for a tile. Used to mark that the player believes the tile
 * contains a bomb.
 */
bool Game::flagon(CoordinateSet pos) {
	Tile *tile = this->getTile(pos);
	bool alreadyflag = FLAG_ON(tile->getFlag());
	tile->setFlag(true);
	if (!tile->amIDeadNow()) {
		std::cout << "Whoops, setting flag on a safe tile" << std::endl;
	}
	if (!alreadyflag) ++this->flagcount;
	drawtile(pos);
	return !alreadyflag;
}
Exemple #2
0
/**
 * Called by amIDeadNow: Press a tile. If !norecursivespread and the tile is
 * not a bomb and doesn't have any bomb neighbours, press all tiles in its
 * neighbourhood.
 */
void Game::press(CoordinateSet pos, bool norecursivespread) {
	Tile *tile = this->getTile(pos);
	tile->press();
	++this->pressedcount;
	drawtile(pos);
	if (!tile->amIDeadNow() && (tile->getSurroundings() == 0)) {
		CoordinateSetList neighbours = this->neighbourhoodpositions(pos);
		CoordinateSetListIt i;
		for (i = neighbours.begin(); i != neighbours.end(); ++i) {
			if (norecursivespread && this->getTile(*i)->getSurroundings() == 0) continue;
			this->amIDeadNow(*i);
		}
	}
}
Exemple #3
0
/**
 * Press a tile. Returns true if the pressed tile was a bomb. Oops!
 */
bool Game::amIDeadNow(CoordinateSet pos) {
	Tile *tile = this->getTile(pos);
	if (tile == NULL) return false;
	if (tile->getDepressed()) return false;
	this->press(pos);
	if (this->pressedcount == this->tiles.size()-this->minecount) {
		this->state = GAMESTATE_WIN;
	}
	if (tile->amIDeadNow()) {
		this->state = GAMESTATE_LOSE;
		return true;
	}
	return false;
}
Exemple #4
0
void Game::findblanks(Dimension dim, CoordinateSet basis, CoordinateSetSet *result) {
	if (dim >= this->dimensioncount) {
		Tile *tile = this->getTile(basis);
		if (tile->getSurroundings() == 0 && !tile->amIDeadNow()) {
			result->insert(basis);
		}
		return;
	}
	for (unsigned int x = 0; x < this->dimensions[dim]; ++x) {
		CoordinateSet temp = basis;
		temp[dim] = x;
		findblanks(dim+1, temp, result);
	}
}
Exemple #5
0
void Game::pressborders() {
	CoordinateSetList::const_iterator i;
	for (i = coordbegin(); i != coordend(); ++i) {
		CoordinateSet c = *i;
		CoordinateSetIt x;
		SizeVectorIt s;
		bool isborder = false;
		for (x = c.begin(), s = dimensions.begin(); x != c.end() && s != dimensions.end(); ++x, ++s) {
			if (*x == 0 || *x+1 == *s) {
				isborder = true;
				break;
			}
		}
		if (isborder) {
			Tile *tile = getTile(c);
			if (!tile->amIDeadNow())
				amIDeadNow(c);
		}
	}
}
/* A field is a "bomb neighbor" if it has a positive number on its face. */
bool MineFieldFilterBombNeighbours::filter_cb(CoordinateSet coords, Game *field) {
	Tile *tile = field->getTile(coords);
	if (tile == NULL) return false;
	/* The tile must be pressed, not be a mine, and have a positive "surroundings" */
	return (tile->getDepressed() && !tile->amIDeadNow() && tile->getSurroundings() > 0);
}