Interactive Lights Off game
C++, 564 bytes

#include &lt;iostream&gt;
#include &lt;algorithm&gt;
#include &lt;ctime&gt;
#include &lt;cstdlib&gt;
#include &lt;vector&gt;
using namespace std;int main(){int n,p,s=0,y,i=0,b;cin&gt;&gt;n&gt;&gt;b;if(n&lt;5)n=5;vector&lt;int&gt;m(n*n,1);srand(time(0));if(b)for(int&amp;c:m)c=rand()&lt;RAND_MAX/6;for(;i&lt;n*n;i++)cout&lt;&lt;m[i]&lt;&lt;(-~i%n?"":"\n");while(find(m.begin(),m.end(),1)!=m.end()){cin&gt;&gt;p&gt;&gt;y;p+=y*n;if(p&lt;0||p&gt;=n*n)continue;m[p]=!m[p];if(p%n)m[p-1]=!m[p-1];if(p%n+1&lt;n)m[p+1]=!m[p+1];if(p&gt;=n)m[p-n]=!m[p-n];if(p+n&lt;n*n)m[p+n]=!m[p+n];for(i=0;i&lt;n*n;i++)cout&lt;&lt;m[i]&lt;&lt;(-~i%n?"":"\n");s++;}cout&lt;&lt;"Solved in "&lt;&lt;s&lt;&lt;" steps."&lt;&lt;endl;}


In setup phase, the user should input the grid size first. Then if the grid should starts with all of the lights on, the user should input 0; otherwise 1.

In play phase, the user should input the 0-based coordinates of the cell to toggle until all lights off.

Original code:

#include &lt;iostream&gt;
#include &lt;algorithm&gt;
#include &lt;ctime&gt;
#include &lt;cstdlib&gt;
#include &lt;vector&gt;
using namespace std;
int main() {
    int n, p, s = 0, y, i = 0, b;
    cin &gt;&gt; n &gt;&gt; b;
    if(n &lt; 5) n = 5;
    vector&lt;int&gt; m(n * n, 1);
    srand(time(0));
    if (b) for (int&amp; c : m) c = rand() &lt; RAND_MAX / 6;
    for (; i &lt; n * n; i++) cout &lt;&lt; m[i] &lt;&lt; (-~i % n ? "" : "\n");
    while (find(m.begin(), m.end(), 1) != m.end()) {
        cin &gt;&gt; p &gt;&gt; y;
        p += y * n;
        if (p &lt; 0 || p &gt;= n * n) continue;
        m[p] = !m[p];
        if (p % n) m[p - 1] = !m[p - 1];
        if (p % n + 1 &lt; n) m[p + 1] = !m[p + 1];
        if (p &gt;= n) m[p - n] = !m[p - n];
        if (p + n &lt; n * n) m[p + n] = !m[p + n];
        for (i = 0; i &lt; n * n; i++) cout &lt;&lt; m[i] &lt;&lt; (-~i % n ? "" : "\n");
        s++;
    }
    cout &lt;&lt; "Solved in " &lt;&lt; s &lt;&lt; " steps." &lt;&lt; endl;
}