Skip to content

Commit

Permalink
Field: Ensure that the first cell has no mine
Browse files Browse the repository at this point in the history
Closes #3.
  • Loading branch information
Kaffeine committed Jan 28, 2020
1 parent b430dba commit 1e44736
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void Cell::open()
m_open = true;

if (!m_field->isGenerated()) {
m_field->generate();
m_field->generate(x(), y());
}

if (minesAround() == 0) {
Expand Down
6 changes: 5 additions & 1 deletion Field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void Field::prepare()
}
}

void Field::generate()
void Field::generate(int x, int y)
{
m_generated = true;

Expand All @@ -47,6 +47,10 @@ void Field::generate()
while (minesToPlace > 0) {
Cell *cell = m_cells.at(qrand() % m_cells.count());

if (cell->x() == x && cell->y() == y) {
continue;
}

if (cell->haveMine()) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion Field.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Field
void setNumberOfMines(int number);

void prepare();
void generate();
void generate(int x, int y);

int width() const { return m_width; }
int height() const { return m_height; }
Expand Down

0 comments on commit 1e44736

Please sign in to comment.