2022-06-08 02:53:52 +00:00
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include "mine.h"
|
|
|
|
|
#include "button.h"
|
|
|
|
|
#include <reg52.h>
|
2022-06-08 12:07:55 +00:00
|
|
|
|
#include "draw.h"
|
|
|
|
|
#include <string.h>
|
2022-06-08 02:53:52 +00:00
|
|
|
|
|
|
|
|
|
enum MGS mineGameStatus = _idle;
|
|
|
|
|
extern unsigned int mBestScore[];
|
|
|
|
|
char mbase[MAX_MX][MAX_MY] = {0}; //x*y //0Ϊ<30><CEAA> -1Ϊ<31><CEAA><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD>ĸ<D7B5><C4B8><EFBFBD>
|
|
|
|
|
extern unsigned int score;
|
|
|
|
|
extern enum OPR opr;
|
|
|
|
|
|
2022-06-08 12:07:55 +00:00
|
|
|
|
void mineInit()
|
|
|
|
|
{
|
|
|
|
|
char i, j;
|
|
|
|
|
mineGameStatus = start;
|
|
|
|
|
score = 0;
|
2022-06-10 17:29:42 +00:00
|
|
|
|
genMine();
|
|
|
|
|
for(i = 0; i < 8; i++)
|
2022-06-08 12:07:55 +00:00
|
|
|
|
for(j = 0; j < 8; j++)
|
2022-06-10 17:29:42 +00:00
|
|
|
|
if(mbase[i][j]==-1)
|
2022-06-08 12:07:55 +00:00
|
|
|
|
placeIMG_BLOCK(i, j);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void mineDestroy()
|
|
|
|
|
{
|
|
|
|
|
score = 0;
|
|
|
|
|
memset(mbase,0, sizeof(mbase));
|
|
|
|
|
mineGameStatus = over;
|
|
|
|
|
}
|
2022-06-08 02:53:52 +00:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2022-06-08 12:07:55 +00:00
|
|
|
|
return re;
|
2022-06-08 02:53:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|