Dynamicly create a playboard for Minesweeper game

后端 未结 3 1449
攒了一身酷
攒了一身酷 2020-12-06 14:23

with the objective to learn C#, XAML and especially MVVM I started to program the Minesweeper game. First version I made was without the MVVM part, where I created and added

3条回答
  •  佛祖请我去吃肉
    2020-12-06 15:28

    Recently I solved the Minesweeper game logic, for a sort of software development contest. I think that the main issue of his game is finding the adjacent mines and the adjacent empty cells around an item. In both cases we have to consider that at most each cell (item) could be surrounded by eight items (cells). If we consider a 4x4 grid (matrix) a cell C defined by a X,Y coordinates it will be surrounded by the following cells:

    C1 (X-1,Y-1)
    C2 (X,Y-1)
    C3 (X+1,Y-1)
    C4 (X-1,Y)
    C5 (X+1,Y)
    C6 (X-1,Y+1)
    C7 (X,Y+1)
    C8 (X+1,Y+1)
    

    In other words we can find the adjacent cells of an item by translating a point on the x and y axis. I developed a class set by splitting the presentation of the game (front-end) by the game logic (back-end).
    By using this strategy actually you can use it with different .Net environment: we don't are "locked" around UI elements or components.
    You can download my project here:
    https://github.com/alchimya/csharp-minesweeper-sdk

提交回复
热议问题