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

70 lines
1.5 KiB
C
Raw Normal View History

#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>
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;
for(i = 0; i < 8; i++)
for(j = 0; j < 8; j++)
placeIMG_BLOCK(i, j);
genMine();
}
void mineDestroy()
{
score = 0;
memset(mbase,0, sizeof(mbase));
mineGameStatus = over;
}
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;
}
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;
}