This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/MCU/MCU_REAL_FINAL/mine.c

50 lines
1.2 KiB
C
Raw Normal View History

#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Ϊ<30><CEAA> -1Ϊ<31><CEAA><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD>׵ĸ<D7B5><C4B8><EFBFBD>
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;
}