<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alexandr</title>
    <description>The latest articles on DEV Community by Alexandr (@niacrisss).</description>
    <link>https://dev.to/niacrisss</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2413853%2F8bebd0cf-bf95-4558-8c1e-7170ae8f96ed.png</url>
      <title>DEV Community: Alexandr</title>
      <link>https://dev.to/niacrisss</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/niacrisss"/>
    <language>en</language>
    <item>
      <title>Minesweeper in Power App: Two Buttons One Gallery</title>
      <dc:creator>Alexandr</dc:creator>
      <pubDate>Tue, 24 Feb 2026 05:58:16 +0000</pubDate>
      <link>https://dev.to/niacrisss/minesweeper-in-power-app-two-buttons-one-gallery-4i6c</link>
      <guid>https://dev.to/niacrisss/minesweeper-in-power-app-two-buttons-one-gallery-4i6c</guid>
      <description>&lt;p&gt;It was another cold winter Sunday, too cold for fishing, too cozy to be productive. I needed a challenge. Something silly but satisfying.&lt;/p&gt;

&lt;p&gt;Twenty years ago I dabbled in Flash game development. A few of those games are still floating around internet archives somewhere, quietly embarrassing me. So I thought — why not build a game in Power Apps? Sure, in 2024 you can vibe-code something like this in minutes with AI. But where's the fun in that?&lt;/p&gt;

&lt;p&gt;Here's my step-by-step journey building a fully working classic Minesweeper in Power Apps. Fast, rough, and absolutely not something your boss should see running on your SharePoint portal.&lt;/p&gt;

&lt;p&gt;The Rules in a Nutshell&lt;br&gt;
You have a grid hiding a set number of mines.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsmkka1kxj4p9rkilejx3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsmkka1kxj4p9rkilejx3.png" alt="Classic" width="624" height="774"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click a cell to reveal it. &lt;/li&gt;
&lt;li&gt;Hit a mine? Game over.&lt;/li&gt;
&lt;li&gt;Safe? It shows a number representing how many neighbouring cells contain mines.&lt;/li&gt;
&lt;li&gt;The Goal: Reveal all safe cells without going kaboom 💥.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Setup&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl4sqg2ndmj7rf2dzybh3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl4sqg2ndmj7rf2dzybh3.png" alt="start" width="800" height="261"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Fire up the Power Apps portal and create a blank canvas app. For this demo we're hardcoding a 3×3 grid — keeping it simple and sane.&lt;br&gt;
Here's all we need UI-wise:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A vertical Gallery with &lt;code&gt;Wrap Count = 3&lt;/code&gt; and &lt;code&gt;Template Size = 100&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Delete all default template controls and drop in a single square Button — this will be our cell&lt;/li&gt;
&lt;li&gt;One more Button on the main screen for starting and resetting the game — this is also where all our logic lives&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4fd7moqkjbwi80aax1hz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4fd7moqkjbwi80aax1hz.png" alt="step1" width="800" height="359"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's it. Minimal controls, maximum fun. Let's get to work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Game Logic — Three Steps&lt;/strong&gt;&lt;br&gt;
Let's break the logic into three parts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Build the grid&lt;/li&gt;
&lt;li&gt;Plant the mines&lt;/li&gt;
&lt;li&gt;Calculate neighbour mine counts&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Step 1 — Build the Grid&lt;/strong&gt;&lt;br&gt;
We need a collection of objects, one per cell, each storing everything we need to know about that cell.&lt;br&gt;
Pop this into your Start Button's &lt;code&gt;OnSelect&lt;/code&gt; property:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F98zx4029pn9nryr5sgdu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F98zx4029pn9nryr5sgdu.png" alt="step2" width="291" height="44"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 1. Create the game grid
ClearCollect(
    colGameField,
    ForAll(
        Sequence(9),  // 9 cells for a 3x3 grid
        {
            ID: Value,
            IsMine: false,           // is this cell a mine?
            IsRevealed: false,       // has the player clicked it?
            AdjacentMineCount: 0,    // how many mines are nearby?
            PosX: Mod(Value - 1, 3) + 1,        // X position: 1, 2, 3
            PosY: Int((Value - 1) / 3) + 1      // Y position: 1, 2, 3
        }
    )
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don't forget to set your Gallery's &lt;code&gt;Items&lt;/code&gt; property to &lt;code&gt;colGameField&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe2x20beocib8m428e6x9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe2x20beocib8m428e6x9.png" alt="Items" width="800" height="540"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Go ahead, hit the Start button. Marvel at your 9 beautiful empty cells. Take a moment. You deserve it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2 — Plant the Mines&lt;/strong&gt;&lt;br&gt;
I decided to set the number of mines to grid size + 1, so 4 mines for a 3×3 grid. The strategy: shuffle all cell IDs, grab the first 4, and tell them "sorry, you're a wizard... oi, a mine now."&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 2. Mine n+1 cells randomly
ClearCollect(
    RandomMineIDs,
    FirstN(Shuffle(Sequence(9)), 4)
);

UpdateIf(
    colGameField,
    ID in RandomMineIDs.Value,
    {IsMine: true}
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You won't see much yet since all cells are hidden. But if you're curious (read: impatient), temporarily add a Label to the gallery template with &lt;code&gt;Text = ThisItem.IsMine&lt;/code&gt;. Hit Start a few times and watch the mines shuffle around randomly. Fun, right? Now remove the label — no cheating.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8ypvaiysi4sfl51rp4y0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8ypvaiysi4sfl51rp4y0.png" alt="Try" width="800" height="256"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3 — Calculate Neighbour Mine Counts&lt;/strong&gt;&lt;br&gt;
This is the meaty part. There are two ways to approach this:&lt;/p&gt;

&lt;p&gt;Check every safe cell and count mines around it&lt;br&gt;
Check every mine and increment its neighbour's counters&lt;/p&gt;

&lt;p&gt;I went with option two — it's likely more efficient on larger grids. Here's the idea:&lt;br&gt;
a) Find all mines (we have X/Y coordinates, so this is easy)&lt;br&gt;
b) Find all 8 neighbours around each mine&lt;br&gt;
c) If a neighbour is in bounds and not a mine, increment its &lt;code&gt;AdjacentMineCount&lt;/code&gt; by 1&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 3. Calculate adjacent mine counts
ForAll(
    Filter(colGameField, IsMine = true),  // loop through all mines
    ForAll(
        Filter(
            ForAll(
                Sequence(9, 0),  // 0-8 to generate 3x3 offset grid
                {
                    NX: PosX + (Mod(Value, 3) - 1),
                    NY: PosY + (RoundDown(Value / 3, 0) - 1)
                }
            ),
            // exclude: the mine itself, out-of-bounds cells, and other mines
            !(NX = PosX &amp;amp;&amp;amp; NY = PosY) &amp;amp;&amp;amp;
            NX &amp;gt; 0 &amp;amp;&amp;amp; NX &amp;lt; 4 &amp;amp;&amp;amp;
            NY &amp;gt; 0 &amp;amp;&amp;amp; NY &amp;lt; 4 &amp;amp;&amp;amp;
            LookUp(colGameField, PosX = NX &amp;amp;&amp;amp; PosY = NY).IsMine = false
        ),
        Patch(
            colGameField,
            LookUp(colGameField, PosX = NX &amp;amp;&amp;amp; PosY = NY),
            {AdjacentMineCount: LookUp(colGameField, PosX = NX &amp;amp;&amp;amp; PosY = NY).AdjacentMineCount + 1}
        )
    )
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The clever trick here: Starting &lt;code&gt;Sequence&lt;/code&gt; from 0 and using &lt;code&gt;Mod(Value, 3) - 1&lt;/code&gt; gives us offsets of -1, 0, +1 for both X and Y — covering all 8 neighbours plus the cell itself, which we then filter out. Neat!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Want to test? Add a label with &lt;code&gt;Text = ThisItem.AdjacentMineCount&lt;/code&gt;. Notice how mined cells show 0 — because we excluded them from incrementing. Once you're done admiring your work, clean up the label.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiq69nj4qcvqkn2ihyms0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiq69nj4qcvqkn2ihyms0.png" alt="Try2" width="800" height="264"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Making Cells Clickable&lt;/strong&gt;&lt;br&gt;
Almost there! Select the Button &lt;em&gt;inside&lt;/em&gt; your gallery template and set these two properties:&lt;br&gt;
&lt;code&gt;OnSelect&lt;/code&gt; — reveal the cell on click (but only if it hasn't been revealed yet):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;If(!ThisItem.IsRevealed, Patch(colGameField, ThisItem, {IsRevealed: true}))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Text&lt;/code&gt; — show what's under the cell:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;If(ThisItem.IsRevealed &amp;amp;&amp;amp; ThisItem.IsMine, "💥",
    If(ThisItem.IsRevealed, Text(ThisItem.AdjacentMineCount), "❓"))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Mined cell? 💥. Safe cell? Shows the neighbour count. Unrevealed? ❓. Clean and simple.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Play It!&lt;/strong&gt;&lt;br&gt;
Hit Start and start clicking. Watch the numbers appear, find the mines, try not to explode. Click Start again for a fresh game.&lt;br&gt;
Yes, there's no penalty for hitting a mine yet. No flagging. No timer. No mine counter. The board is tiny. But you know what? It works. And that's a win.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fumjumoxrq3fo26loppl0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fumjumoxrq3fo26loppl0.png" alt="Win" width="800" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What's Next?&lt;/strong&gt;&lt;br&gt;
After sitting with it a little longer, I did add all the missing pieces — bigger board, flagging, timer, mine counter, and a proper game-over screen. The full version is actually good enough to drop on a SharePoint portal.&lt;br&gt;
Just... maybe don't show your boss. 🙂&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmxmw7bswdk1qxc9q2mma.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmxmw7bswdk1qxc9q2mma.png" alt="Advanced" width="502" height="750"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Built on a cold Sunday instead of going fishing. Zero regrets.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What do you think — should Power Apps game development be a thing? Drop a comment below!&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>powerapps</category>
      <category>powerplatform</category>
    </item>
  </channel>
</rss>
