feat(MCU课设): 增加部分扫雷代码

This commit is contained in:
iridiumR 2022-06-08 10:53:52 +08:00
parent 25c07e4a0d
commit a52a764eb2
6 changed files with 98 additions and 10 deletions

View file

@ -293,6 +293,18 @@
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>1</GroupNumber>
<FileNumber>8</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>.\mine.c</PathWithFileName>
<FilenameWithoutPath>mine.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>
<Group>
@ -303,7 +315,7 @@
<RteFlg>0</RteFlg>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>8</FileNumber>
<FileNumber>9</FileNumber>
<FileType>5</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -315,7 +327,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>9</FileNumber>
<FileNumber>10</FileNumber>
<FileType>5</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -327,7 +339,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>10</FileNumber>
<FileNumber>11</FileNumber>
<FileType>5</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -339,7 +351,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>11</FileNumber>
<FileNumber>12</FileNumber>
<FileType>5</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -351,7 +363,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>12</FileNumber>
<FileNumber>13</FileNumber>
<FileType>5</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -363,7 +375,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>13</FileNumber>
<FileNumber>14</FileNumber>
<FileType>5</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -375,7 +387,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>14</FileNumber>
<FileNumber>15</FileNumber>
<FileType>5</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -387,7 +399,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>15</FileNumber>
<FileNumber>16</FileNumber>
<FileType>5</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -399,7 +411,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>16</FileNumber>
<FileNumber>17</FileNumber>
<FileType>5</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -409,6 +421,18 @@
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>18</FileNumber>
<FileType>5</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>.\mine.h</PathWithFileName>
<FilenameWithoutPath>mine.h</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>
</ProjectOpt>

View file

@ -411,6 +411,11 @@
<FileType>1</FileType>
<FilePath>.\eeprom.c</FilePath>
</File>
<File>
<FileName>mine.c</FileName>
<FileType>1</FileType>
<FilePath>.\mine.c</FilePath>
</File>
</Files>
</Group>
<Group>
@ -461,6 +466,11 @@
<FileType>5</FileType>
<FilePath>.\eeprom.h</FilePath>
</File>
<File>
<FileName>mine.h</FileName>
<FileType>5</FileType>
<FilePath>.\mine.h</FilePath>
</File>
</Files>
</Group>
</Groups>

View file

@ -3,5 +3,6 @@
enum OPR {left,right,confirm,idle};
enum GS {__idle,start,good,over};
enum MGS {_idle,mstart,mgood,mover};
#endif

View file

@ -28,8 +28,9 @@ enum OPR opr = idle;
static unsigned int local[4] = {0};
unsigned int score;
unsigned int bestScore[10];
unsigned int mBestScore[10];
extern enum GS blockGameStatus;
extern enum GS mineGameStatus;
//寮꽉데
void m_mainmenu(struct _menu* this)

50
MCU/MCU_REAL_FINAL/mine.c Normal file
View file

@ -0,0 +1,50 @@
#include <stdlib.h>
#include "mine.h"
#include "button.h"
#include <reg52.h>
enum MGS mineGameStatus = _idle;
extern unsigned int mBestScore[];
char mbase[MAX_MX][MAX_MY] = {0}; //x*y //0为空 -1为有雷 整数为雷的个数
extern unsigned int score;
extern enum OPR opr;
unsigned mIsIegal(int i, int j)
{
if(i >= 0 && i < MAX_MX && j >= 0 && j < MAX_MY)
return 1;
return 0;
}
unsigned int findSum(int i, int j)
{
int re = 0;
if(mbase[i][j] == -1)
return -1;
else
{
mIsIegal(i, j + 1) ? re += mbase[i][j + 1] : 0;
mIsIegal(i, j - 1) ? re += mbase[i][j - 1] : 0;
mIsIegal(i + 1, j) ? re += mbase[i + 1][j] : 0;
mIsIegal(i - 1, j) ? re += mbase[i - 1][j] : 0;
mIsIegal(i - 1, j + 1) ? re += mbase[i - 1][j + 1] : 0;
mIsIegal(i + 1, j + 1) ? re += mbase[i + 1][j + 1] : 0;
mIsIegal(i - 1, j - 1) ? re += mbase[i - 1][j - 1] : 0;
mIsIegal(i + 1, j - 1) ? re += mbase[i + 1][j - 1] : 0;
}
return re;
}
void genMine()
{
int i, j;
score = 0;
srand((unsigned)TL0);
for(i = 0; i < MAX_MY; i++)
mbase[rand() % 10][i] = -1;
for(i = 0; i < MAX_MX; i++)
for(j = 0; j < MAX_MX; j++)
mbase[j][i] = findSum(j, i);
mineGameStatus = start;
}

View file

@ -0,0 +1,2 @@
#define MAX_MX 8
#define MAX_MY 8