feat(MCU课设): 增加历史排行榜功能,但还有bug

This commit is contained in:
iridiumR 2022-06-07 14:25:11 +08:00
parent cc9a66ef00
commit 4a01b42afe
7 changed files with 124 additions and 20 deletions

View file

@ -3,6 +3,7 @@
#include "button.h"
#include <reg52.h>
#include "delay.h"
#include "eeprom.h"
char base[MAX_X][MAX_Y] = {0}; //x*y //0为空 1为下落完成 2为正在下落
extern unsigned int score;
@ -208,7 +209,7 @@ void moveRightPiece()
}
}
//判断是否游戏结束/分数增加
//判断消除整行
void judgeBlock()
{
char i, j, k, h, count;
@ -239,6 +240,7 @@ void judgeBlock()
}
}
//判断是否游戏结束
void blockGameOver()
{
char j,i;
@ -256,6 +258,8 @@ void blockGameOver()
//结束则填满
if(blockGameStatus == over)
{
addBest(score);
saveBest();
for(j = 0; j < MAX_Y; j++)
for(i = 0; i < MAX_X; i++)
{

View file

@ -588,7 +588,7 @@ void drawBEST(unsigned char x, unsigned char y)
CSA = 0;
CSB = 1;
}
for(j = 0; j < 40; j++)
for(j = 0; j < 32; j++)
{
RS = 0;
RW = 0;

View file

@ -14,6 +14,11 @@ void drawGOOD(unsigned char x, unsigned char y);
void drawGAME(unsigned char x, unsigned char y);
void drawOVER(unsigned char x, unsigned char y);
void drawBLOCKSCORE();
////=================== ¼Ç¼ ==================
void drawRECORD(unsigned char x, unsigned char y);
void drawBEST(unsigned char x, unsigned char y);
////=================== ¼¸ºÎ ==================
void drawVerticalDottedLine(char x);
#endif

View file

@ -13,7 +13,9 @@
#include "reg51.h"
#include "intrins.h"
#include "eeprom.h"
#include "delay.h"
extern unsigned int bestScore[10];
/*----------------------------
Disable ISP/IAP/EEPROM function
@ -86,3 +88,29 @@ void IapEraseSector(WORD addr)
IapIdle();
}
void addBest(unsigned int s)
{
bestScore[2]=s;
}
void saveBest()
{
char i;
IapEraseSector(IAP_ADDRESS);
delayms(20);
for(i=0;i++;i<10)
{
IapProgramByte(IAP_ADDRESS+2*i, bestScore[i]/256);
IapProgramByte(IAP_ADDRESS+2*i+1, bestScore[i]%256);
}
}
void readBest()
{
char i;
for(i=0;i++;i<10)
{
bestScore[i]=(unsigned int)IapReadByte(IAP_ADDRESS+2*i)*256 +(unsigned int)IapReadByte(IAP_ADDRESS+2*i+1);
}
}

View file

@ -33,4 +33,8 @@ BYTE IapReadByte(WORD addr);
void IapProgramByte(WORD addr, BYTE dat);
void IapEraseSector(WORD addr);
void saveBest();
void readBest();
void addBest(unsigned int s);
#endif

View file

@ -1,4 +1,5 @@
#include "main.h"
#include "eeprom.h"
#define RELOAD (65535-9216) //定时器填充值(1ms)
unsigned char TH, TL;
@ -64,8 +65,8 @@ int main()
displayInit(); //屏幕初始化
clear();
menuInit(); //꽉데섟페儉놓迦뺏
menuInit(); //꽉데놓迦뺏
readBest();
while(1)
{

View file

@ -22,8 +22,9 @@ Menu* NOW; //
Menu* LAST = NULL; //上一个状态的菜单
enum OPR opr = idle;
static unsigned char local[10] = {0};
static unsigned char local[2] = {0};
unsigned int score;
unsigned int bestScore[10];
extern enum GS blockGameStatus;
@ -93,29 +94,29 @@ void m_block(struct _menu* this)
{
opr = idle;
blockDestroy();
NOW=&M_MAINMENU;
clear();
NOW = &M_MAINMENU;
clear();
return;
}
if(opr == left)
{
opr = idle;
moveLeftPiece();
drawBlock();
return;
drawBlock();
return;
}
if(opr == right)
{
opr = idle;
moveRightPiece();
drawBlock();
return;
drawBlock();
return;
}
switch(blockGameStatus)
{
case good:
drawGOOD(70, 4);
blockGameStatus=start;
blockGameStatus = start;
break;
case over:
drawGAME(70, 4);
@ -125,12 +126,12 @@ void m_block(struct _menu* this)
drawVOID8(70, 4, 40);
drawVOID8(70, 6, 32);
}
drawSUPNUM(70, 2, score/10000); //绘制分数
drawSUPNUM(79, 2, (score%10000)/1000);
drawSUPNUM(88, 2, (score%1000)/100);
drawSUPNUM(97, 2, (score%100)/10);
drawSUPNUM(106, 2, score%10);
blockGameOver(); //检查是否游戏结束
drawSUPNUM(70, 2, score / 10000); //绘制分数
drawSUPNUM(79, 2, (score % 10000) / 1000);
drawSUPNUM(88, 2, (score % 1000) / 100);
drawSUPNUM(97, 2, (score % 100) / 10);
drawSUPNUM(106, 2, score % 10);
blockGameOver(); //检查是否游戏结束
genPiece(); //若有需要,生成新块
dropPiece(); //若有需要,块下落
judgeBlock(); //若有需要,清除一行
@ -147,7 +148,7 @@ void m_about(struct _menu* this)
if(LAST != &M_ABOUT)
{
LAST = &M_ABOUT;
delayms(2000);
delayms(2000);
drawNAME(); //绘制名字
delayms(2000);
drawNUMBER(); //绘制学号
@ -161,12 +162,73 @@ void m_about(struct _menu* this)
}
}
//记录页
void m_best(struct _menu* this)
{
if(LAST != &M_BEST)
{
LAST = &M_BEST;
drawBEST(2, 0);
drawSUPNUM(2, 2, bestScore[0] / 10000); //绘制分数
drawSUPNUM(11, 2, (bestScore[0] % 10000) / 1000);
drawSUPNUM(20, 2, (bestScore[0] % 1000) / 100);
drawSUPNUM(29, 2, (bestScore[0] % 100) / 10);
drawSUPNUM(38, 2, bestScore[0] % 10);
drawSUPNUM(2, 4, bestScore[1] / 10000); //绘制分数
drawSUPNUM(11, 4, (bestScore[1] % 10000) / 1000);
drawSUPNUM(20, 4, (bestScore[1] % 1000) / 100);
drawSUPNUM(29, 4, (bestScore[1] % 100) / 10);
drawSUPNUM(38, 4, bestScore[1] % 10);
drawSUPNUM(2, 6, bestScore[2] / 10000); //绘制分数
drawSUPNUM(11, 6, (bestScore[2] % 10000) / 1000);
drawSUPNUM(20, 6, (bestScore[2] % 1000) / 100);
drawSUPNUM(29, 6, (bestScore[2] % 100) / 10);
drawSUPNUM(38, 6, bestScore[2] % 10);
drawSUPNUM(72, 0, bestScore[3] / 10000); //绘制分数
drawSUPNUM(81, 0, (bestScore[3] % 10000) / 1000);
drawSUPNUM(90, 0, (bestScore[3] % 1000) / 100);
drawSUPNUM(99, 0, (bestScore[3] % 100) / 10);
drawSUPNUM(108, 0, bestScore[3] % 10);
drawSUPNUM(72, 2, bestScore[4] / 10000); //绘制分数
drawSUPNUM(81, 2, (bestScore[4] % 10000) / 1000);
drawSUPNUM(90, 2, (bestScore[4] % 1000) / 100);
drawSUPNUM(99, 2, (bestScore[4] % 100) / 10);
drawSUPNUM(108, 2, bestScore[4] % 10);
drawSUPNUM(72, 4, bestScore[5] / 10000); //绘制分数
drawSUPNUM(81, 4, (bestScore[5] % 10000) / 1000);
drawSUPNUM(90, 4, (bestScore[5] % 1000) / 100);
drawSUPNUM(99, 4, (bestScore[5] % 100) / 10);
drawSUPNUM(108, 4, bestScore[5] % 10);
drawSUPNUM(72, 6, bestScore[6] / 10000); //绘制分数
drawSUPNUM(81, 6, (bestScore[6] % 10000) / 1000);
drawSUPNUM(90, 6, (bestScore[6] % 1000) / 100);
drawSUPNUM(99, 6, (bestScore[6] % 100) / 10);
drawSUPNUM(108, 6, bestScore[6] % 10);
}
if(opr == confirm)
{
opr = idle;
NOW = &M_MAINMENU; //转向下一菜单
clear();
}
}
void menuInit()
{
M_MAINMENU.f = m_mainmenu;
M_BLOCK.f = m_block;
M_ABOUT.f = m_about;
M_ABOUT.f = m_about;
M_BEST.f = m_best;
#ifdef DEBUG_MODE
NOW = &M_DEBUG;