mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:57:44 +00:00
GameOfLife: Add a tick counter to the status bar
The counter is incremented after each new generation and reset whenever any cell on the board is toggled. Resizing the board does not reset the tick count.
This commit is contained in:
parent
7e9ea964a8
commit
19dfdeeaec
4 changed files with 45 additions and 18 deletions
|
@ -38,6 +38,12 @@ BoardWidget::BoardWidget(size_t rows, size_t columns)
|
|||
void BoardWidget::run_generation()
|
||||
{
|
||||
m_board->run_generation();
|
||||
if (!m_board->is_stalled())
|
||||
m_ticks++;
|
||||
|
||||
if (on_tick)
|
||||
on_tick(m_ticks);
|
||||
|
||||
update();
|
||||
if (m_board->is_stalled()) {
|
||||
if (on_stall)
|
||||
|
@ -91,6 +97,8 @@ void BoardWidget::toggle_cell(size_t row, size_t column)
|
|||
if (m_running || !m_toggling_cells || (m_last_cell_toggled.row == row && m_last_cell_toggled.column == column))
|
||||
return;
|
||||
|
||||
m_ticks = 0;
|
||||
|
||||
m_last_cell_toggled = { row, column };
|
||||
m_board->toggle_cell(row, column);
|
||||
|
||||
|
@ -100,6 +108,18 @@ void BoardWidget::toggle_cell(size_t row, size_t column)
|
|||
update();
|
||||
}
|
||||
|
||||
void BoardWidget::clear_cells()
|
||||
{
|
||||
m_ticks = 0;
|
||||
m_board->clear();
|
||||
}
|
||||
|
||||
void BoardWidget::randomize_cells()
|
||||
{
|
||||
m_ticks = 0;
|
||||
m_board->randomize();
|
||||
}
|
||||
|
||||
int BoardWidget::get_cell_size() const
|
||||
{
|
||||
int width = rect().width() / m_board->columns();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue