50 lines
No EOL
1.2 KiB
C
50 lines
No EOL
1.2 KiB
C
#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;
|
|
} |